Fix bug 7878: Save command (#8140)
* first pass at fixing bug 7878, needs testing * clarify default behaviour in comment * fix property typo, tested and works as intended * remove debugger
This commit is contained in:
parent
9167b190d2
commit
5f74f4c2fa
|
@ -43,7 +43,9 @@ Saves individual tiddlers in their raw text or binary format to the specified fi
|
||||||
directory: path.resolve(self.commander.outputPath),
|
directory: path.resolve(self.commander.outputPath),
|
||||||
pathFilters: [filenameFilter],
|
pathFilters: [filenameFilter],
|
||||||
wiki: wiki,
|
wiki: wiki,
|
||||||
fileInfo: {}
|
fileInfo: {
|
||||||
|
overwrite: true
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if(self.commander.verbose) {
|
if(self.commander.verbose) {
|
||||||
console.log("Saving \"" + title + "\" to \"" + fileInfo.filepath + "\"");
|
console.log("Saving \"" + title + "\" to \"" + fileInfo.filepath + "\"");
|
||||||
|
|
|
@ -316,11 +316,13 @@ Options include:
|
||||||
pathFilters: optional array of filters to be used to generate the base path
|
pathFilters: optional array of filters to be used to generate the base path
|
||||||
wiki: optional wiki for evaluating the pathFilters
|
wiki: optional wiki for evaluating the pathFilters
|
||||||
fileInfo: an existing fileInfo object to check against
|
fileInfo: an existing fileInfo object to check against
|
||||||
|
fileInfo.overwrite: if true, turns off filename clash numbers (defaults to false)
|
||||||
*/
|
*/
|
||||||
exports.generateTiddlerFilepath = function(title,options) {
|
exports.generateTiddlerFilepath = function(title,options) {
|
||||||
var directory = options.directory || "",
|
var directory = options.directory || "",
|
||||||
extension = options.extension || "",
|
extension = options.extension || "",
|
||||||
originalpath = (options.fileInfo && options.fileInfo.originalpath) ? options.fileInfo.originalpath : "",
|
originalpath = (options.fileInfo && options.fileInfo.originalpath) ? options.fileInfo.originalpath : "",
|
||||||
|
overwrite = options.fileInfo && options.fileInfo.overwrite || false,
|
||||||
filepath;
|
filepath;
|
||||||
// Check if any of the pathFilters applies
|
// Check if any of the pathFilters applies
|
||||||
if(options.pathFilters && options.wiki) {
|
if(options.pathFilters && options.wiki) {
|
||||||
|
@ -381,19 +383,20 @@ exports.generateTiddlerFilepath = function(title,options) {
|
||||||
filepath += char.charCodeAt(0).toString();
|
filepath += char.charCodeAt(0).toString();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Add a uniquifier if the file already exists
|
// Add a uniquifier if the file already exists (default)
|
||||||
var fullPath, oldPath = (options.fileInfo) ? options.fileInfo.filepath : undefined,
|
var fullPath = path.resolve(directory, filepath + extension);
|
||||||
|
if (!overwrite) {
|
||||||
|
var oldPath = (options.fileInfo) ? options.fileInfo.filepath : undefined,
|
||||||
count = 0;
|
count = 0;
|
||||||
do {
|
do {
|
||||||
fullPath = path.resolve(directory,filepath + (count ? "_" + count : "") + extension);
|
fullPath = path.resolve(directory,filepath + (count ? "_" + count : "") + extension);
|
||||||
if(oldPath && oldPath == fullPath) {
|
if(oldPath && oldPath == fullPath) break;
|
||||||
break;
|
count++;
|
||||||
}
|
} while(fs.existsSync(fullPath));
|
||||||
count++;
|
}
|
||||||
} while(fs.existsSync(fullPath));
|
|
||||||
// If the last write failed with an error, or if path does not start with:
|
// If the last write failed with an error, or if path does not start with:
|
||||||
// the resolved options.directory, the resolved wikiPath directory, the wikiTiddlersPath directory,
|
// the resolved options.directory, the resolved wikiPath directory, the wikiTiddlersPath directory,
|
||||||
// or the 'originalpath' directory, then $tw.utils.encodeURIComponentExtended() and resolve to tiddler directory.
|
// or the 'originalpath' directory, then $tw.utils.encodeURIComponentExtended() and resolve to options.directory.
|
||||||
var writePath = $tw.hooks.invokeHook("th-make-tiddler-path",fullPath,fullPath),
|
var writePath = $tw.hooks.invokeHook("th-make-tiddler-path",fullPath,fullPath),
|
||||||
encode = (options.fileInfo || {writeError: false}).writeError == true;
|
encode = (options.fileInfo || {writeError: false}).writeError == true;
|
||||||
if(!encode) {
|
if(!encode) {
|
||||||
|
|
Loading…
Reference in New Issue