From 5fc2dd4d44bb226aa06517b67d66396e14b1f474 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 21 Jul 2015 03:01:21 -0400 Subject: [PATCH] Fix a probably rare case of a file's not being uploaded If a file existed locally but somehow ended up marked as to-download without existing on the server, it was never uploaded. I'm not sure when this can happen, but I saw it while messing around. Maybe switching between ZFS and WebDAV? This will still only check and upload if there's another computer syncing files to the same library, but we'll check all files in 5.0. --- chrome/content/zotero/xpcom/storage/webdav.js | 12 +++++++++++- chrome/content/zotero/xpcom/storage/zfs.js | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js index 8aebd403eb..dc9843db5a 100644 --- a/chrome/content/zotero/xpcom/storage/webdav.js +++ b/chrome/content/zotero/xpcom/storage/webdav.js @@ -853,15 +853,25 @@ Zotero.Sync.Storage.WebDAV = (function () { return false; } + var file = item.getFile(); + if (!mdate) { Zotero.debug("Remote file not found for item " + Zotero.Items.getLibraryKeyHash(item)); + // Reset sync state if a remotely missing file exists locally. + // I'm not sure how this can happen, but otherwise it results in + // a file marked as TO_DOWNLOAD never being uploaded. + if (file && file.exists()) { + Zotero.Sync.Storage.setSyncState(item.id, Zotero.Sync.Storage.SYNC_STATE_TO_UPLOAD); + return { + localChanges: true + }; + } return false; } var syncModTime = mdate.getTime(); // Skip download if local file exists and matches mod time - var file = item.getFile(); if (file && file.exists() && syncModTime == file.lastModifiedTime) { Zotero.debug("File mod time matches remote file -- skipping download"); diff --git a/chrome/content/zotero/xpcom/storage/zfs.js b/chrome/content/zotero/xpcom/storage/zfs.js index 2638e99b4c..97c7ea0882 100644 --- a/chrome/content/zotero/xpcom/storage/zfs.js +++ b/chrome/content/zotero/xpcom/storage/zfs.js @@ -762,15 +762,25 @@ Zotero.Sync.Storage.ZFS = (function () { return false; } + var file = item.getFile(); + if (!info) { Zotero.debug("Remote file not found for item " + item.libraryID + "/" + item.key); + // Reset sync state if a remotely missing file exists locally. + // I'm not sure how this can happen, but otherwise it results in + // a file marked as TO_DOWNLOAD never being uploaded. + if (file && file.exists()) { + Zotero.Sync.Storage.setSyncState(item.id, Zotero.Sync.Storage.SYNC_STATE_TO_UPLOAD); + return { + localChanges: true + }; + } return false; } var syncModTime = info.mtime; var syncHash = info.hash; - var file = item.getFile(); // Skip download if local file exists and matches mod time if (file && file.exists()) { if (syncModTime == file.lastModifiedTime) {