From 7e6784a7390dcb9b6bdda27136877d89fe92c4ea Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 22 Sep 2009 09:00:09 +0000 Subject: [PATCH] - Fix error syncing empty files - Clarify quota message to say that metadata will continue to sync - Fix some other problem that I don't remember --- chrome/content/zotero/xpcom/data/item.js | 8 +++++++- chrome/content/zotero/xpcom/storage/zfs.js | 2 +- chrome/content/zotero/xpcom/sync.js | 17 +++++++++++++++-- chrome/content/zotero/xpcom/utilities.js | 6 ++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index f659b6ae15..48ae92db36 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -2563,7 +2563,7 @@ Zotero.Item.prototype.getFilename = function () { * * -1 Destination file exists -- use _force_ to overwrite * -2 Error renaming - * false Attachment file not found or other error + * false Attachment file not found */ Zotero.Item.prototype.renameAttachmentFile = function(newName, overwrite) { var file = this.getFile(); @@ -2591,10 +2591,16 @@ Zotero.Item.prototype.renameAttachmentFile = function(newName, overwrite) { file.moveTo(null, newName); // Update mod time and clear hash so the file syncs + // TODO: use an integer counter instead of mod time for change detection dest.lastModifiedTime = new Date(); this.relinkAttachmentFile(dest); + Zotero.DB.beginTransaction(); + Zotero.Sync.Storage.setSyncedHash(this.id, null, false); + Zotero.Sync.Storage.setSyncState(this.id, Zotero.Sync.Storage.SYNC_STATE_TO_UPLOAD); + + Zotero.DB.commitTransaction(); return true; } diff --git a/chrome/content/zotero/xpcom/storage/zfs.js b/chrome/content/zotero/xpcom/storage/zfs.js index bef227de01..4f4ddaf4c3 100644 --- a/chrome/content/zotero/xpcom/storage/zfs.js +++ b/chrome/content/zotero/xpcom/storage/zfs.js @@ -164,7 +164,7 @@ Zotero.Sync.Storage.Session.ZFS.prototype.downloadFile = function (request) { return; } // If not compressed, check hash, in case only timestamp changed - else if (!info.compressed && Zotero.Utilities.prototype.md5(file) == syncHash) { + else if (!info.compressed && item.attachmentHash == syncHash) { Zotero.debug("File hash matches remote file -- skipping download"); Zotero.DB.beginTransaction(); diff --git a/chrome/content/zotero/xpcom/sync.js b/chrome/content/zotero/xpcom/sync.js index 7d9af4bdc5..ceb6e11b47 100644 --- a/chrome/content/zotero/xpcom/sync.js +++ b/chrome/content/zotero/xpcom/sync.js @@ -39,16 +39,24 @@ Zotero.Sync = new function() { this.init = function () { + Zotero.DB.beginTransaction(); + var sql = "SELECT version FROM version WHERE schema='syncdeletelog'"; if (!Zotero.DB.valueQuery(sql)) { sql = "SELECT COUNT(*) FROM syncDeleteLog"; if (Zotero.DB.valueQuery(sql)) { throw ('syncDeleteLog not empty and no timestamp in Zotero.Sync.delete()'); } + + var syncInitTime = Zotero.DB.transactionDate; + syncInitTime = Zotero.Date.toUnixTimestamp(syncInitTime); + sql = "INSERT INTO version VALUES ('syncdeletelog', ?)"; - Zotero.DB.query(sql, Zotero.Date.getUnixTimestamp()); + Zotero.DB.query(sql, syncInitTime); } + Zotero.DB.commitTransaction(); + this.EventListener.init(); } @@ -136,6 +144,10 @@ Zotero.Sync = new function() { } // Last sync time is before start of log + Zotero.debug('=============='); + Zotero.debug(lastSyncDate); + Zotero.debug(lastSyncDate + ''); + Zotero.debug(syncLogStart); if (lastSyncDate && new Date(syncLogStart * 1000) > lastSyncDate) { return -1; } @@ -716,7 +728,8 @@ Zotero.Sync.Runner = new function () { if (e) { if (e.error == Zotero.Error.ERROR_ZFS_OVER_QUOTA) { // TODO: localize - message = "You have reached your Zotero File Storage quota. Some files were not synced.\n\n" + message = "You have reached your Zotero File Storage quota. Some files were not synced. " + + "Other Zotero data will continue to sync to the server.\n\n" + "See your zotero.org account settings for additional storage options."; buttonText = "Open Account Settings"; diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 13644d9953..d84b44c1fd 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -415,6 +415,12 @@ Zotero.Utilities.prototype.md5 = function(strOrFile, base64) { ch.update(data, data.length); } else if (strOrFile instanceof Components.interfaces.nsIFile) { + // Otherwise throws (NS_ERROR_NOT_AVAILABLE) [nsICryptoHash.updateFromStream] + if (!strOrFile.fileSize) { + // MD5 for empty string + return "d41d8cd98f00b204e9800998ecf8427e"; + } + var istream = Components.classes["@mozilla.org/network/file-input-stream;1"] .createInstance(Components.interfaces.nsIFileInputStream); // open for reading