- 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
This commit is contained in:
Dan Stillman 2009-09-22 09:00:09 +00:00
parent 4407275401
commit 7e6784a739
4 changed files with 29 additions and 4 deletions

View file

@ -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;
}

View file

@ -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();

View file

@ -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";

View file

@ -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