Prevent setting base directory within data directory

Addresses #538
This commit is contained in:
Dan Stillman 2020-04-26 01:20:15 -04:00
parent 30d40d6094
commit 40fe85b274
2 changed files with 18 additions and 2 deletions

View file

@ -569,13 +569,28 @@ Zotero_Preferences.Attachment_Base_Directory = {
return false;
}
return this.changePath(newPath);
try {
return await this.changePath(newPath);
}
catch (e) {
Zotero.logError(e);
Zotero.alert(null, Zotero.getString('general.error'), e.message);
}
},
changePath: Zotero.Promise.coroutine(function* (basePath) {
Zotero.debug(`New base directory is ${basePath}`);
if (Zotero.File.directoryContains(Zotero.DataDirectory.dir, basePath)) {
throw new Error(
Zotero.getString(
'zotero.preferences.advanced.baseDirectory.withinDataDir',
Zotero.appName
)
);
}
// Find all current attachments with relative attachment paths
var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=? AND path LIKE ?";
var params = [
@ -693,7 +708,7 @@ Zotero_Preferences.Attachment_Base_Directory = {
return false;
}
// Set new data directory
// Set new base directory
Zotero.debug("Setting base directory to " + basePath);
Zotero.Prefs.set('baseAttachmentPath', basePath);
Zotero.Prefs.set('saveRelativeAttachmentPath', true);

View file

@ -685,6 +685,7 @@ zotero.preferences.wordProcessors.incompatibleVersions2 = %1$S %2$S requires %3
zotero.preferences.styles.addStyle = Add Style
zotero.preferences.advanced.baseDirectory.withinDataDir = You cannot select a Linked Attachment Base Directory within the %S data directory.
zotero.preferences.advanced.resetTranslatorsAndStyles = Reset Translators and Styles
zotero.preferences.advanced.resetTranslatorsAndStyles.changesLost = Any new or modified translators or styles will be lost.
zotero.preferences.advanced.resetTranslators = Reset Translators