diff options
author | jchu <jchu> | 2004-12-13 04:07:09 +0000 |
---|---|---|
committer | jchu <jchu> | 2004-12-13 04:07:09 +0000 |
commit | ad8f4991476870d9ddeacdf72f4dd633570c8ec7 (patch) | |
tree | c9126a487824f1011b9305889d423bfe4f23312e /tupkg | |
parent | 592565d863fda7eaafd9ec69d6086c2ec0eeac07 (diff) | |
download | aurweb-ad8f4991476870d9ddeacdf72f4dd633570c8ec7.tar.xz |
added resume support on the server side
Diffstat (limited to 'tupkg')
-rwxr-xr-x | tupkg/server/tupkgs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/tupkg/server/tupkgs b/tupkg/server/tupkgs index 5eac499..0db7aab 100755 --- a/tupkg/server/tupkgs +++ b/tupkg/server/tupkgs @@ -40,9 +40,11 @@ class ClientFile: def __init__(self, filename, actual_size, actual_md5): self.pathname = INCOMINGDIR + filename self.filename = filename - self.fd = open(self.pathname, "w+b") + self.fd = open(self.pathname, "a+b") self.actual_size = actual_size self.actual_md5 = actual_md5 + self.getSize() + self.orig_size = self.size def getSize(self): cur = self.fd.tell() @@ -61,12 +63,16 @@ class ClientFile: self.md5 = md5sum.hexdigest() def finishDownload(self): - self.fd.close(); + self.fd.close() newpathname = CACHEDIR + self.filename os.rename(self.pathname, newpathname) self.pathname = newpathname self.fd = open(self.pathname, "a+b") + def delete(self): + self.fd.close() + os.remove(self.pathname) + class ClientSocket(threading.Thread): def __init__(self, sock, db, **other): threading.Thread.__init__(self, *other) @@ -136,14 +142,15 @@ class ClientSocket(threading.Thread): new_files = files.copy() for i in files: if i[:4] == 'size': - new_files[i] = '0' + clientfile = self.files[int(i[4:])] + new_files[i] = str(clientfile.orig_size) if i[:6] == 'md5sum': del new_files[i] self.sendMsg(new_files) def readFiles(self): for i in self.files: - count = 0 + count = i.orig_size while count != i.actual_size: if count + 1024 > i.actual_size: i.fd.write(self.reliableRead(i.actual_size - count)) @@ -152,14 +159,15 @@ class ClientSocket(threading.Thread): i.fd.write(self.reliableRead(1024)) count += 1024 i.fd.flush() - i.finishDownload() reply = {'numpkgs': len(self.files)} for i, v in enumerate(self.files): v.makeMd5() if v.actual_md5 == v.md5: reply['md5sum'+str(i)] = "PASS" + v.finishDownload() else: reply['md5sum'+str(i)] = "FAIL" + v.delete() self.sendMsg(reply) print self.readMsg() |