Move data dire getters to Z.DataDirectory
Add Z.DataDirectory.getSubdirectory which, optionally, creates the directory. Add async Z.DataDirectory.removeSubdirectory and use it for Z.removeTempDirectory (was sync call before!).
This commit is contained in:
parent
fc8037a83b
commit
7f2d83a602
2 changed files with 36 additions and 43 deletions
|
@ -1228,5 +1228,27 @@ Zotero.DataDirectory = {
|
||||||
ext = ext ? '.' + ext : '';
|
ext = ext ? '.' + ext : '';
|
||||||
|
|
||||||
return OS.Path.join(this.dir, name + ext);
|
return OS.Path.join(this.dir, name + ext);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} name - the name of the subdirectory
|
||||||
|
* @param {Boolean} createIfMissing - ensure that the directory exists
|
||||||
|
* @return {String} the path to the subdirectory
|
||||||
|
*/
|
||||||
|
getSubdirectory: function (name, createIfMissing = false) {
|
||||||
|
let dir = OS.Path.join(this.dir, name);
|
||||||
|
if (createIfMissing) {
|
||||||
|
Zotero.File.createDirectoryIfMissing(dir);
|
||||||
|
}
|
||||||
|
return dir;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} name - the name of the subdirectory
|
||||||
|
* @return {Promise<Boolean>} true if the subdirectory was deleted,
|
||||||
|
* or false if it did not exist
|
||||||
|
*/
|
||||||
|
removeSubdirectory: function (name) {
|
||||||
|
return Zotero.File.removeIfExists(OS.Path.join(this.dir, name));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -941,7 +941,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove temp directory
|
// remove temp directory
|
||||||
Zotero.removeTempDirectory();
|
yield Zotero.removeTempDirectory();
|
||||||
|
|
||||||
if (Zotero.DB) {
|
if (Zotero.DB) {
|
||||||
// close DB
|
// close DB
|
||||||
|
@ -964,63 +964,34 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
||||||
return Zotero.File.pathToFile(Zotero.Profile.dir);
|
return Zotero.File.pathToFile(Zotero.Profile.dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.getZoteroDirectory = function () {
|
this.getZoteroDirectory = function () {
|
||||||
Zotero.warn("Zotero.getZoteroDirectory() is deprecated -- use Zotero.DataDirectory.dir");
|
Zotero.warn("Zotero.getZoteroDirectory() is deprecated -- use Zotero.DataDirectory.dir");
|
||||||
return Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
return Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getStorageDirectory(){
|
|
||||||
var file = OS.Path.join(Zotero.DataDirectory.dir, 'storage');
|
|
||||||
file = Zotero.File.pathToFile(file);
|
|
||||||
Zotero.File.createDirectoryIfMissing(file);
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.getZoteroDatabase = function (name, ext) {
|
this.getZoteroDatabase = function (name, ext) {
|
||||||
Zotero.warn("Zotero.getZoteroDatabase() is deprecated -- use Zotero.DataDirectory.getDatabase()");
|
Zotero.warn("Zotero.getZoteroDatabase() is deprecated -- use Zotero.DataDirectory.getDatabase()");
|
||||||
return Zotero.File.pathToFile(Zotero.DataDirectory.getDatabase(name, ext));
|
return Zotero.File.pathToFile(Zotero.DataDirectory.getDatabase(name, ext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getStorageDirectory() {
|
||||||
/**
|
return Zotero.DataDirectory.getSubdirectory('storage', true);
|
||||||
* @return {nsIFile}
|
|
||||||
*/
|
|
||||||
this.getTempDirectory = function () {
|
|
||||||
var tmp = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
|
||||||
tmp.append('tmp');
|
|
||||||
Zotero.File.createDirectoryIfMissing(tmp);
|
|
||||||
return tmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.removeTempDirectory = function () {
|
|
||||||
var tmp = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
|
||||||
tmp.append('tmp');
|
|
||||||
if (tmp.exists()) {
|
|
||||||
try {
|
|
||||||
tmp.remove(true);
|
|
||||||
}
|
|
||||||
catch (e) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.getStylesDirectory = function () {
|
this.getStylesDirectory = function () {
|
||||||
var dir = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
return Zotero.DataDirectory.getSubdirectory('styles', true);
|
||||||
dir.append('styles');
|
|
||||||
Zotero.File.createDirectoryIfMissing(dir);
|
|
||||||
return dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.getTranslatorsDirectory = function () {
|
this.getTranslatorsDirectory = function () {
|
||||||
var dir = Zotero.File.pathToFile(Zotero.DataDirectory.dir);
|
return Zotero.DataDirectory.getSubdirectory('translators', true);
|
||||||
dir.append('translators');
|
}
|
||||||
Zotero.File.createDirectoryIfMissing(dir);
|
|
||||||
return dir;
|
this.getTempDirectory = function () {
|
||||||
|
return Zotero.DataDirectory.getSubdirectory('tmp', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.removeTempDirectory = function () {
|
||||||
|
return Zotero.DataDirectory.removeSubdirectory('tmp');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue