compress zip, add media sanity check

This commit is contained in:
Damien Elmes 2011-12-06 23:36:01 +09:00
parent fabec6e920
commit 9b76a4669c
2 changed files with 23 additions and 1 deletions

View file

@ -259,7 +259,7 @@ If the same name exists, compare checksums."""
def zipAdded(self): def zipAdded(self):
"Add files to a zip until over SYNC_ZIP_SIZE. Return zip data." "Add files to a zip until over SYNC_ZIP_SIZE. Return zip data."
f = StringIO() f = StringIO()
z = zipfile.ZipFile(f, "w") z = zipfile.ZipFile(f, "w", compression=zipfile.ZIP_DEFLATED)
sz = 0 sz = 0
cnt = 0 cnt = 0
files = {} files = {}
@ -382,3 +382,8 @@ create table log (fname text primary key, type int);
if not v[2]: if not v[2]:
removed.append(k) removed.append(k)
return added, removed return added, removed
def sanityCheck(self):
assert not self.db.scalar("select count() from log")
cnt = self.db.scalar("select count() from media")
return cnt

View file

@ -577,6 +577,15 @@ class MediaSyncer(object):
# after server has replied, safe to remove from log # after server has replied, safe to remove from log
self.col.media.forgetAdded(fnames) self.col.media.forgetAdded(fnames)
self.col.media.setUsn(usn) self.col.media.setUsn(usn)
# step 5: sanity check during beta testing
# NOTE: when removing this, need to move server tidyup
# back from sanity check to addFiles
s = self.server.mediaSanity()
c = self.mediaSanity()
if c != s:
raise Exception("""\
Sanity check failed. Please copy and paste the text below:\n%s\n%s""" %
(c, s))
return "success" return "success"
def removed(self): def removed(self):
@ -595,6 +604,9 @@ class MediaSyncer(object):
"True if zip is the last in set. Server returns new usn instead." "True if zip is the last in set. Server returns new usn instead."
return self.col.media.syncAdd(zip) return self.col.media.syncAdd(zip)
def mediaSanity(self):
return self.col.media.sanityCheck()
# Remote media syncing # Remote media syncing
########################################################################## ##########################################################################
@ -615,10 +627,15 @@ class RemoteMediaServer(MediaSyncer, HttpSyncer):
self.con, "files", StringIO(simplejson.dumps(kw)), self._vars()) self.con, "files", StringIO(simplejson.dumps(kw)), self._vars())
def addFiles(self, zip): def addFiles(self, zip):
# no compression, as we compress the zip file instead
return simplejson.loads( return simplejson.loads(
self.postData(self.con, "addFiles", StringIO(zip), self.postData(self.con, "addFiles", StringIO(zip),
self._vars(), comp=0)) self._vars(), comp=0))
def mediaSanity(self):
return simplejson.loads(
self.postData(self.con, "mediaSanity", None, self._vars()))
# only for unit tests # only for unit tests
def mediatest(self, n): def mediatest(self, n):
return simplejson.loads( return simplejson.loads(