diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js index 0f8c03aa6a..ed56f1cc09 100644 --- a/chrome/content/zotero/xpcom/storage/webdav.js +++ b/chrome/content/zotero/xpcom/storage/webdav.js @@ -1437,17 +1437,19 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = { break; } - // If an item file URI, get the property URI + // If a .zip file URL, get the .prop file URI var deletePropURI = this._getPropertyURIFromItemURI(deleteURI); - // Only nsIURL has fileName - deletePropURI.QueryInterface(Ci.nsIURL); - - // If we already deleted the prop file, skip it - if (!deletePropURI || results.deleted.has(deletePropURI.fileName)) { + // Not a .zip file URL + if (!deletePropURI) { return; } - + // Only nsIURL has fileName + deletePropURI.QueryInterface(Ci.nsIURL); fileName = deletePropURI.fileName; + // Already deleted + if (results.deleted.has(fileName)) { + return; + } // Delete property file var req = yield Zotero.HTTP.request( diff --git a/test/tests/webdavTest.js b/test/tests/webdavTest.js index 0cf25d466d..28c240a5cf 100644 --- a/test/tests/webdavTest.js +++ b/test/tests/webdavTest.js @@ -1008,6 +1008,8 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { }, text: '' + '' + + // Orphaned files to delete + '' + `${davBasePath}zotero/` + '' @@ -1035,7 +1037,6 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { + 'HTTP/1.1 200 OK' + '' + '' - + '' + `${davBasePath}zotero/AAAAAAAA.zip` + '' @@ -1054,9 +1055,28 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { + 'HTTP/1.1 200 OK' + '' + '' - + '' + `${davBasePath}zotero/BBBBBBBB.zip` + + '' + + '' + + `${beforeTime}` + + '' + + 'HTTP/1.1 200 OK' + + '' + + '' + + '' + + `${davBasePath}zotero/BBBBBBBB.prop` + + '' + + '' + + `${beforeTime}` + + '' + + 'HTTP/1.1 200 OK' + + '' + + '' + + // Orphaned files that aren't old enough to delete + + '' + + `${davBasePath}zotero/CCCCCCCC.zip` + '' + '' + `${currentTime}` @@ -1065,7 +1085,7 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { + '' + '' + '' - + `${davBasePath}zotero/BBBBBBBB.prop` + + `${davBasePath}zotero/CCCCCCCC.prop` + '' + '' + `${currentTime}` @@ -1125,6 +1145,16 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { url: 'zotero/AAAAAAAA.zip', status: 204 }); + setResponse({ + method: "DELETE", + url: 'zotero/BBBBBBBB.prop', + status: 204 + }); + setResponse({ + method: "DELETE", + url: 'zotero/BBBBBBBB.zip', + status: 204 + }); setResponse({ method: "DELETE", url: 'zotero/lastsync.txt', @@ -1137,9 +1167,19 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { }); var results = yield controller.purgeOrphanedStorageFiles(); - assertRequestCount(5); + assertRequestCount(7); - assert.sameMembers(results.deleted, ['lastsync.txt', 'lastsync', 'AAAAAAAA.prop', 'AAAAAAAA.zip']); + assert.sameMembers( + results.deleted, + [ + 'lastsync.txt', + 'lastsync', + 'AAAAAAAA.prop', + 'AAAAAAAA.zip', + 'BBBBBBBB.prop', + 'BBBBBBBB.zip' + ] + ); assert.lengthOf(results.missing, 0); assert.lengthOf(results.error, 0); })