mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
added resume support on the server side
This commit is contained in:
parent
592565d863
commit
ad8f499147
1 changed files with 13 additions and 5 deletions
|
@ -40,9 +40,11 @@ class ClientFile:
|
||||||
def __init__(self, filename, actual_size, actual_md5):
|
def __init__(self, filename, actual_size, actual_md5):
|
||||||
self.pathname = INCOMINGDIR + filename
|
self.pathname = INCOMINGDIR + filename
|
||||||
self.filename = 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_size = actual_size
|
||||||
self.actual_md5 = actual_md5
|
self.actual_md5 = actual_md5
|
||||||
|
self.getSize()
|
||||||
|
self.orig_size = self.size
|
||||||
|
|
||||||
def getSize(self):
|
def getSize(self):
|
||||||
cur = self.fd.tell()
|
cur = self.fd.tell()
|
||||||
|
@ -61,12 +63,16 @@ class ClientFile:
|
||||||
self.md5 = md5sum.hexdigest()
|
self.md5 = md5sum.hexdigest()
|
||||||
|
|
||||||
def finishDownload(self):
|
def finishDownload(self):
|
||||||
self.fd.close();
|
self.fd.close()
|
||||||
newpathname = CACHEDIR + self.filename
|
newpathname = CACHEDIR + self.filename
|
||||||
os.rename(self.pathname, newpathname)
|
os.rename(self.pathname, newpathname)
|
||||||
self.pathname = newpathname
|
self.pathname = newpathname
|
||||||
self.fd = open(self.pathname, "a+b")
|
self.fd = open(self.pathname, "a+b")
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
self.fd.close()
|
||||||
|
os.remove(self.pathname)
|
||||||
|
|
||||||
class ClientSocket(threading.Thread):
|
class ClientSocket(threading.Thread):
|
||||||
def __init__(self, sock, db, **other):
|
def __init__(self, sock, db, **other):
|
||||||
threading.Thread.__init__(self, *other)
|
threading.Thread.__init__(self, *other)
|
||||||
|
@ -136,14 +142,15 @@ class ClientSocket(threading.Thread):
|
||||||
new_files = files.copy()
|
new_files = files.copy()
|
||||||
for i in files:
|
for i in files:
|
||||||
if i[:4] == 'size':
|
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':
|
if i[:6] == 'md5sum':
|
||||||
del new_files[i]
|
del new_files[i]
|
||||||
self.sendMsg(new_files)
|
self.sendMsg(new_files)
|
||||||
|
|
||||||
def readFiles(self):
|
def readFiles(self):
|
||||||
for i in self.files:
|
for i in self.files:
|
||||||
count = 0
|
count = i.orig_size
|
||||||
while count != i.actual_size:
|
while count != i.actual_size:
|
||||||
if count + 1024 > i.actual_size:
|
if count + 1024 > i.actual_size:
|
||||||
i.fd.write(self.reliableRead(i.actual_size - count))
|
i.fd.write(self.reliableRead(i.actual_size - count))
|
||||||
|
@ -152,14 +159,15 @@ class ClientSocket(threading.Thread):
|
||||||
i.fd.write(self.reliableRead(1024))
|
i.fd.write(self.reliableRead(1024))
|
||||||
count += 1024
|
count += 1024
|
||||||
i.fd.flush()
|
i.fd.flush()
|
||||||
i.finishDownload()
|
|
||||||
reply = {'numpkgs': len(self.files)}
|
reply = {'numpkgs': len(self.files)}
|
||||||
for i, v in enumerate(self.files):
|
for i, v in enumerate(self.files):
|
||||||
v.makeMd5()
|
v.makeMd5()
|
||||||
if v.actual_md5 == v.md5:
|
if v.actual_md5 == v.md5:
|
||||||
reply['md5sum'+str(i)] = "PASS"
|
reply['md5sum'+str(i)] = "PASS"
|
||||||
|
v.finishDownload()
|
||||||
else:
|
else:
|
||||||
reply['md5sum'+str(i)] = "FAIL"
|
reply['md5sum'+str(i)] = "FAIL"
|
||||||
|
v.delete()
|
||||||
self.sendMsg(reply)
|
self.sendMsg(reply)
|
||||||
print self.readMsg()
|
print self.readMsg()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue