From 4c0abb68161fae508949da574db7026f9de36fc8 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 26 Nov 2016 22:41:26 -0500 Subject: [PATCH] Point other profiles to new data dir after migration (+ code reorg) Look for other profiles, from both apps (Firefox and Standalone), that point to the data directory being migrated and update prefs.js in those profiles to point to the new location. Also reorganize code into Zotero.Profile and Zotero.DataDirectory namespaces --- chrome/content/zotero/overlay.js | 2 +- .../preferences/preferences_advanced.js | 30 +- .../preferences/preferences_advanced.xul | 4 +- chrome/content/zotero/xpcom/dataDirectory.js | 847 +++++++++++++++++ chrome/content/zotero/xpcom/file.js | 1 - chrome/content/zotero/xpcom/profile.js | 236 +++++ chrome/content/zotero/xpcom/sync/syncLocal.js | 2 +- chrome/content/zotero/xpcom/zotero.js | 895 +----------------- components/zotero-service.js | 2 + test/content/support.js | 1 - .../{zoteroTest.js => dataDirectoryTest.js} | 41 +- test/tests/profileTest.js | 190 ++++ test/tests/syncLocalTest.js | 6 +- 13 files changed, 1338 insertions(+), 919 deletions(-) create mode 100644 chrome/content/zotero/xpcom/dataDirectory.js create mode 100644 chrome/content/zotero/xpcom/profile.js rename test/tests/{zoteroTest.js => dataDirectoryTest.js} (89%) create mode 100644 test/tests/profileTest.js diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 974295e43a..580bba8283 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -230,7 +230,7 @@ var ZoteroOverlay = new function() // Warn about unsafe data directory on first display let dataDir = Zotero.getZoteroDirectory(); - Zotero.checkForUnsafeDataDirectory(dataDir.path); + Zotero.DataDirectory.checkForUnsafeLocation(dataDir.path); // async // Make sure tags splitter isn't missing for people upgrading from <2.0b7 document.getElementById('zotero-tags-splitter').collapsed = false; diff --git a/chrome/content/zotero/preferences/preferences_advanced.js b/chrome/content/zotero/preferences/preferences_advanced.js index 2afa4d1393..f14084434c 100644 --- a/chrome/content/zotero/preferences/preferences_advanced.js +++ b/chrome/content/zotero/preferences/preferences_advanced.js @@ -38,8 +38,8 @@ Zotero_Preferences.Advanced = { migrateDataDirectory: Zotero.Promise.coroutine(function* () { - var currentDir = Zotero.getZoteroDirectory().path; - var defaultDir = Zotero.getDefaultDataDir(); + var currentDir = Zotero.DataDirectory.dir; + var defaultDir = Zotero.DataDirectory.defaultDir; if (currentDir == defaultDir) { Zotero.debug("Already using default directory"); return; @@ -65,7 +65,7 @@ Zotero_Preferences.Advanced = { ); if (index == 0) { - yield Zotero.markDataDirectoryForMigration(currentDir); + yield Zotero.DataDirectory.markForMigration(currentDir); Zotero.Utilities.Internal.quitZotero(true); } }), @@ -215,13 +215,13 @@ Zotero_Preferences.Advanced = { onDataDirLoad: function () { var useDataDir = Zotero.Prefs.get('useDataDir'); var dataDir = Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir'); - var defaultDataDir = Zotero.getDefaultDataDir(); - var currentDir = Zotero.getZoteroDirectory().path; + var currentDir = Zotero.DataDirectory.dir; + var defaultDataDir = Zotero.DataDirectory.defaultDir; // Change "Use profile directory" label to home directory location unless using profile dir if (useDataDir || currentDir == defaultDataDir) { document.getElementById('default-data-dir').setAttribute( - 'label', Zotero.getString('dataDir.default', Zotero.getDefaultDataDir()) + 'label', Zotero.getString('dataDir.default', Zotero.DataDirectory.defaultDir) ); } @@ -232,14 +232,14 @@ Zotero_Preferences.Advanced = { document.getElementById('data-dir-path').setAttribute('disabled', !useDataDir); document.getElementById('migrate-data-dir').setAttribute( - 'hidden', !Zotero.canMigrateDataDirectory() + 'hidden', !Zotero.DataDirectory.canMigrate() ); return useDataDir; }, - onDataDirUpdate: function (event) { + onDataDirUpdate: Zotero.Promise.coroutine(function* (event) { var radiogroup = document.getElementById('data-dir'); var useDataDir = Zotero.Prefs.get('useDataDir'); var newUseDataDir = radiogroup.selectedIndex == 1; @@ -250,11 +250,13 @@ Zotero_Preferences.Advanced = { // This call shows a filepicker if needed, forces a restart if required, and does nothing if // cancel was pressed or value hasn't changed - Zotero.chooseZoteroDirectory(true, !newUseDataDir, function () { - Zotero_Preferences.openURL('https://zotero.org/support/zotero_data'); - }); + yield Zotero.DataDirectory.choose( + true, + !newUseDataDir, + () => Zotero_Preferences.openURL('https://zotero.org/support/zotero_data') + ); radiogroup.selectedIndex = this._usingDefaultDataDir() ? 0 : 1; - }, + }), chooseDataDir: function(event) { @@ -269,7 +271,7 @@ Zotero_Preferences.Advanced = { var prefValue = Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir'); // Don't show path if the default - if (prefValue == Zotero.getDefaultDataDir()) { + if (prefValue == Zotero.DataDirectory.defaultDir) { return ''; } @@ -285,7 +287,7 @@ Zotero_Preferences.Advanced = { var dataDir = Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir'); // Default home directory location - if (dataDir == Zotero.getDefaultDataDir()) { + if (dataDir == Zotero.DataDirectory.defaultDir) { return true; } diff --git a/chrome/content/zotero/preferences/preferences_advanced.xul b/chrome/content/zotero/preferences/preferences_advanced.xul index 5a984a0b36..fabd06535d 100644 --- a/chrome/content/zotero/preferences/preferences_advanced.xul +++ b/chrome/content/zotero/preferences/preferences_advanced.xul @@ -185,7 +185,7 @@ + onsynctopreference="Zotero_Preferences.Advanced.onDataDirUpdate(event);"> @@ -199,7 +199,7 @@