Don't allow setting data dir to 'storage' or linked attachment base dir
If 'storage' (with a zotero.sqlite file above it) is chosen, offer to use parent instead. Addresses #538
This commit is contained in:
parent
40fe85b274
commit
7c3faeb58d
2 changed files with 51 additions and 0 deletions
|
@ -462,11 +462,35 @@ Zotero.DataDirectory = {
|
|||
let dialogText = '';
|
||||
let dialogTitle = '';
|
||||
|
||||
// If set to 'storage', offer to use the parent directory
|
||||
if (await this.isStorageDirectory(file.path)) {
|
||||
let buttonFlags = ps.STD_YES_NO_BUTTONS;
|
||||
let parentPath = OS.Path.dirname(file.path);
|
||||
let index = ps.confirmEx(
|
||||
null,
|
||||
Zotero.getString('general.error'),
|
||||
Zotero.getString('dataDir.cannotBeSetWithAlternative', [parentPath]),
|
||||
buttonFlags,
|
||||
null, null, null, null, {}
|
||||
);
|
||||
if (index == 1) {
|
||||
continue;
|
||||
}
|
||||
file = Zotero.File.pathToFile(parentPath)
|
||||
}
|
||||
|
||||
if (file.path == (Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir'))) {
|
||||
Zotero.debug("Data directory hasn't changed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.isLinkedAttachmentBaseDirectory(file.path)) {
|
||||
let dialogTitle = Zotero.getString('general.error');
|
||||
let dialogText = Zotero.getString('dataDir.cannotBeLinkedAttachmentBaseDirectory');
|
||||
ps.alert(null, dialogTitle, dialogText);
|
||||
continue;
|
||||
}
|
||||
|
||||
// In dropbox folder
|
||||
if (Zotero.File.isDropboxDirectory(file.path)) {
|
||||
dialogTitle = Zotero.getString('general.warning');
|
||||
|
@ -648,6 +672,31 @@ Zotero.DataDirectory = {
|
|||
}),
|
||||
|
||||
|
||||
isStorageDirectory: async function (dir) {
|
||||
if (OS.Path.basename(dir) != 'storage') {
|
||||
return false;
|
||||
}
|
||||
let sqlitePath = OS.Path.join(OS.Path.dirname(dir), 'zotero.sqlite');
|
||||
return OS.File.exists(sqlitePath);
|
||||
},
|
||||
|
||||
|
||||
isLinkedAttachmentBaseDirectory: function (dir) {
|
||||
var oldPath = Zotero.Prefs.get('baseAttachmentPath');
|
||||
if (!oldPath) return false;
|
||||
|
||||
try {
|
||||
oldPath = OS.Path.normalize(oldPath);
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.logError(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return oldPath === OS.Path.normalize(dir);
|
||||
},
|
||||
|
||||
|
||||
// TODO: Remove after 5.0 upgrades
|
||||
checkForLostLegacy: async function () {
|
||||
var currentDir = this.dir;
|
||||
|
|
|
@ -151,6 +151,8 @@ dataDir.selectDir = Select a Zotero data directory
|
|||
dataDir.selectNewDir = Select a new %S data directory
|
||||
dataDir.changeDataDirectory = Change Data Directory…
|
||||
dataDir.chooseNewDataDirectory = Choose New Data Directory…
|
||||
dataDir.cannotBeSetWithAlternative = The data directory cannot be set to a “storage” directory. Did you mean %S?
|
||||
dataDir.cannotBeLinkedAttachmentBaseDirectory = The data directory cannot be set to the same location as the Linked Attachment Base Directory.
|
||||
dataDir.unsafeLocation.selected.dropbox = Choosing a data directory within Dropbox may corrupt your database.
|
||||
dataDir.unsafeLocation.selected.useAnyway = Use this directory anyway?
|
||||
dataDir.unsafeLocation.existing.dropbox = Your Zotero data directory is within Dropbox, which may lead to data corruption.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue