Don't allow data dir migration via prefs if directory exists
And treat an existing non-empty directory as a failure during the migration, since it should now never happen Also suggest manually moving on Windows if more than 100 attachments
This commit is contained in:
parent
58f554a930
commit
0be67dbda5
3 changed files with 57 additions and 42 deletions
|
@ -48,6 +48,50 @@ Zotero_Preferences.Advanced = {
|
|||
Components.utils.import("resource://zotero/config.js")
|
||||
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Components.interfaces.nsIPromptService);
|
||||
|
||||
// ~/Zotero exists and is non-empty
|
||||
if ((yield OS.File.exists(defaultDir)) && !(yield Zotero.File.directoryIsEmpty(defaultDir))) {
|
||||
let buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
|
||||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
|
||||
let index = ps.confirmEx(
|
||||
window,
|
||||
Zotero.getString('general.error'),
|
||||
Zotero.getString('zotero.preferences.advanced.migrateDataDir.directoryExists1', defaultDir)
|
||||
+ "\n\n"
|
||||
+ Zotero.getString('zotero.preferences.advanced.migrateDataDir.directoryExists2'),
|
||||
buttonFlags,
|
||||
Zotero.getString('general.showDirectory'),
|
||||
null, null, null, {}
|
||||
);
|
||||
if (index == 0) {
|
||||
yield Zotero.File.reveal(
|
||||
// Windows opens the directory, which might be confusing here, so open parent instead
|
||||
Zotero.isWin ? OS.Path.dirname(defaultDir) : defaultDir
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var additionalText = '';
|
||||
if (Zotero.isWin) {
|
||||
try {
|
||||
let numItems = yield Zotero.DB.valueQueryAsync(
|
||||
"SELECT COUNT(*) FROM itemAttachments WHERE linkMode IN (?, ?)",
|
||||
[Zotero.Attachments.LINK_MODE_IMPORTED_FILE, Zotero.Attachments.LINK_MODE_IMPORTED_URL]
|
||||
);
|
||||
if (numItems > 100) {
|
||||
additionalText = '\n\n' + Zotero.getString(
|
||||
'zotero.preferences.advanced.migrateDataDir.manualMigration',
|
||||
[Zotero.appName, defaultDir, ZOTERO_CONFIG.CLIENT_NAME]
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.logError(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Prompt to restart
|
||||
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
|
||||
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
|
||||
var index = ps.confirmEx(window,
|
||||
|
@ -58,9 +102,9 @@ Zotero_Preferences.Advanced = {
|
|||
) + '\n\n'
|
||||
+ Zotero.getString(
|
||||
'zotero.preferences.advanced.migrateDataDir.appMustBeRestarted', Zotero.appName
|
||||
),
|
||||
) + additionalText,
|
||||
buttonFlags,
|
||||
Zotero.getString('general.restartApp', Zotero.appName),
|
||||
Zotero.getString('general.continue'),
|
||||
null, null, null, {}
|
||||
);
|
||||
|
||||
|
|
|
@ -730,47 +730,13 @@ Zotero.DataDirectory = {
|
|||
|
||||
// Create the new directory
|
||||
if (!partial) {
|
||||
try {
|
||||
yield OS.File.makeDir(
|
||||
newDir,
|
||||
{
|
||||
ignoreExisting: false,
|
||||
unixMode: 0o755
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (e) {
|
||||
// If default dir exists and is non-empty, move it out of the way
|
||||
// ("Zotero-1", "Zotero-2", …)
|
||||
if (e instanceof OS.File.Error && e.becauseExists) {
|
||||
if (!(yield Zotero.File.directoryIsEmpty(newDir))) {
|
||||
let i = 1;
|
||||
while (true) {
|
||||
let backupDir = newDir + "-" + i++;
|
||||
if (yield OS.File.exists(backupDir)) {
|
||||
if (i > 5) {
|
||||
throw new Error("Too many backup directories "
|
||||
+ "-- stopped at " + backupDir);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Zotero.debug(`Moving existing directory to ${backupDir}`);
|
||||
yield Zotero.File.moveDirectory(newDir, backupDir);
|
||||
break;
|
||||
}
|
||||
yield OS.File.makeDir(
|
||||
newDir,
|
||||
{
|
||||
ignoreExisting: false,
|
||||
unixMode: 0o755
|
||||
}
|
||||
);
|
||||
}
|
||||
yield OS.File.makeDir(
|
||||
newDir,
|
||||
{
|
||||
ignoreExisting: false,
|
||||
unixMode: 0o755
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Copy marker
|
||||
|
|
|
@ -59,6 +59,8 @@ general.dontShowAgain = Don’t Show Again
|
|||
general.fix = Fix…
|
||||
general.tryAgain = Try Again
|
||||
general.tryLater = Try Later
|
||||
general.showDirectory = Show Directory
|
||||
general.continue = Continue
|
||||
|
||||
general.operationInProgress = A Zotero operation is currently in progress.
|
||||
general.operationInProgress.waitUntilFinished = Please wait until it has finished.
|
||||
|
@ -639,8 +641,11 @@ zotero.preferences.advanced.resetTranslators.changesLost = Any new or modifie
|
|||
zotero.preferences.advanced.resetStyles = Reset Styles
|
||||
zotero.preferences.advanced.resetStyles.changesLost = Any new or modified styles will be lost.
|
||||
zotero.preferences.advanced.migrateDataDir.title = Migrate Data Directory
|
||||
zotero.preferences.advanced.migrateDataDir.directoryExists1 = A directory already exists at %S.
|
||||
zotero.preferences.advanced.migrateDataDir.directoryExists2 = Please move or rename it and try again.
|
||||
zotero.preferences.advanced.migrateDataDir.directoryWillBeMoved = Your %1$S data directory will be moved to %2$S.
|
||||
zotero.preferences.advanced.migrateDataDir.appMustBeRestarted = %S must be restarted to complete the migration.
|
||||
zotero.preferences.advanced.migrateDataDir.manualMigration = You can also quit %1$S and move your existing data directory to %2$S manually, which may be faster for larger data directories. %3$S will automatically detect the new location.
|
||||
|
||||
zotero.preferences.advanced.debug.title = Debug Output Submitted
|
||||
zotero.preferences.advanced.debug.sent = Debug output has been sent to the Zotero server.\n\nThe Debug ID is D%S.
|
||||
|
|
Loading…
Reference in a new issue