- Fix WebDAV deleted file purging
- Reenable WebDAV orphaned file purging (currently once every ten days) Also: - Create pref of appropriate type automatically in Zotero.Prefs.set() if one doesn't exist
This commit is contained in:
parent
f7765be35c
commit
45bc19c06a
|
@ -816,13 +816,30 @@ Zotero.Sync.Storage = new function () {
|
|||
this.purgeDeletedStorageFiles = function (module, callback) {
|
||||
_session = new Zotero.Sync.Storage.Session(module, { onError: _error });
|
||||
if (!_session.initFromPrefs()) {
|
||||
Zotero.debug("Module '" + module + "' not initialized in Zotero.Sync.Storage.purgeDeletedStorageFiles()");
|
||||
return;
|
||||
}
|
||||
_session.purgeDeletedStorageFiles(callback);
|
||||
}
|
||||
|
||||
|
||||
this.purgeOrphanedStorageFiles = function (module, callback) {
|
||||
_session = new Zotero.Sync.Storage.Session(module, { onError: _error });
|
||||
if (!_session.initFromPrefs()) {
|
||||
return;
|
||||
}
|
||||
_session.purgeOrphanedStorageFiles(callback);
|
||||
}
|
||||
|
||||
|
||||
this.isActive = function (module) {
|
||||
_session = new Zotero.Sync.Storage.Session(module, { onError: _error });
|
||||
if (!_session.initFromPrefs()) {
|
||||
return;
|
||||
}
|
||||
return _session.active;
|
||||
}
|
||||
|
||||
|
||||
this.resetAllSyncStates = function (syncState, includeUserFiles, includeGroupFiles) {
|
||||
if (!includeUserFiles && !includeGroupFiles) {
|
||||
includeUserFiles = true;
|
||||
|
|
|
@ -1298,7 +1298,19 @@ Zotero.Sync.Storage.Session.WebDAV.prototype.purgeDeletedStorageFiles = function
|
|||
Zotero.Sync.Storage.Session.WebDAV.prototype.purgeOrphanedStorageFiles = function (callback) {
|
||||
const daysBeforeSyncTime = 1;
|
||||
|
||||
if (!this.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
var lastpurge = Zotero.Prefs.get('lastWebDAVOrphanPurge');
|
||||
var days = 10;
|
||||
// Already purged within the last week
|
||||
if (lastpurge && new Date(lastpurge * 1000) > (new Date() - (1000 * 60 * 60 * 24 * days))) {
|
||||
return;
|
||||
}
|
||||
|
||||
Zotero.debug("Purging orphaned storage files");
|
||||
|
||||
var uri = this.rootURI;
|
||||
var path = uri.path;
|
||||
|
||||
|
@ -1390,19 +1402,17 @@ Zotero.Sync.Storage.Session.WebDAV.prototype.purgeOrphanedStorageFiles = functio
|
|||
// Delete files older than a day before last sync time
|
||||
var days = (lastSyncDate - lastModified) / 1000 / 60 / 60 / 24;
|
||||
|
||||
// DEBUG!!!!!!!!!!!!
|
||||
//
|
||||
// For now, delete all orphaned files immediately
|
||||
if (true) {
|
||||
deleteFiles.push(file);
|
||||
} else
|
||||
|
||||
if (days > daysBeforeSyncTime) {
|
||||
deleteFiles.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
this._deleteStorageFiles(deleteFiles, callback);
|
||||
self._deleteStorageFiles(deleteFiles, function (results) {
|
||||
Zotero.Prefs.set("lastWebDAVOrphanPurge", Math.round(new Date().getTime() / 1000))
|
||||
if (callback) {
|
||||
callback(results);
|
||||
}
|
||||
});
|
||||
},
|
||||
{ Depth: 1 });
|
||||
}
|
||||
|
|
|
@ -950,6 +950,9 @@ Zotero.Sync.Storage.Session.ZFS.prototype.setLastSyncTime = function (callback,
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all synced files from the server
|
||||
*/
|
||||
Zotero.Sync.Storage.Session.ZFS.prototype.purgeDeletedStorageFiles = function (callback) {
|
||||
// If we don't have a user id we've never synced and don't need to bother
|
||||
if (!Zotero.userID) {
|
||||
|
@ -966,12 +969,13 @@ Zotero.Sync.Storage.Session.ZFS.prototype.purgeDeletedStorageFiles = function (c
|
|||
|
||||
var uri = this.userURI;
|
||||
uri.spec += "removestoragefiles?";
|
||||
// Unused
|
||||
for each(var value in values) {
|
||||
switch (value) {
|
||||
case 'user':
|
||||
uri.spec += "user=1&";
|
||||
break;
|
||||
|
||||
|
||||
case 'group':
|
||||
uri.spec += "group=1&";
|
||||
break;
|
||||
|
|
|
@ -401,7 +401,7 @@ Zotero.Sync.EventListener = new function () {
|
|||
var sql = "REPLACE INTO syncDeleteLog VALUES (?, ?, ?, ?)";
|
||||
var syncStatement = Zotero.DB.getStatement(sql);
|
||||
|
||||
if (isItem && Zotero.Sync.Storage.active) {
|
||||
if (isItem && Zotero.Sync.Storage.isActive('webdav')) {
|
||||
var storageEnabled = true;
|
||||
var sql = "INSERT INTO storageDeleteLog VALUES (?, ?, ?)";
|
||||
var storageStatement = Zotero.DB.getStatement(sql);
|
||||
|
|
|
@ -1427,6 +1427,10 @@ var Zotero = new function(){
|
|||
Zotero.Sync.Storage.purgeDeletedStorageFiles('zfs');
|
||||
Zotero.Sync.Storage.purgeDeletedStorageFiles('webdav');
|
||||
}
|
||||
|
||||
if (!skipStoragePurge) {
|
||||
Zotero.Sync.Storage.purgeOrphanedStorageFiles('webdav');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1494,7 +1498,7 @@ Zotero.Prefs = new function(){
|
|||
/**
|
||||
* Set a preference
|
||||
**/
|
||||
function set(pref, value){
|
||||
function set(pref, value) {
|
||||
try {
|
||||
switch (this.prefBranch.getPrefType(pref)){
|
||||
case this.prefBranch.PREF_BOOL:
|
||||
|
@ -1503,6 +1507,22 @@ Zotero.Prefs = new function(){
|
|||
return this.prefBranch.setCharPref(pref, value);
|
||||
case this.prefBranch.PREF_INT:
|
||||
return this.prefBranch.setIntPref(pref, value);
|
||||
|
||||
// If not an existing pref, create appropriate type automatically
|
||||
case 0:
|
||||
if (typeof value == 'boolean') {
|
||||
Zotero.debug("Creating boolean pref '" + pref + "'");
|
||||
return this.prefBranch.setBoolPref(pref, value);
|
||||
}
|
||||
if (parseInt(value) == value) {
|
||||
Zotero.debug("Creating integer pref '" + pref + "'");
|
||||
return this.prefBranch.setIntPref(pref, value);
|
||||
}
|
||||
if (typeof value == 'string') {
|
||||
Zotero.debug("Creating string pref '" + pref + "'");
|
||||
return this.prefBranch.setCharPref(pref, value);
|
||||
}
|
||||
throw ("Invalid preference value '" + value + "' for pref '" + pref + "'");
|
||||
}
|
||||
}
|
||||
catch (e){
|
||||
|
|
Loading…
Reference in New Issue
Block a user