mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-08-07 06:14:44 +00:00
fix filesystem bugs (#5213)
This commit is contained in:
parent
a3a7d6450d
commit
b0f6d50b60
@ -217,6 +217,10 @@ Options include:
|
|||||||
*/
|
*/
|
||||||
exports.generateTiddlerFileInfo = function(tiddler,options) {
|
exports.generateTiddlerFileInfo = function(tiddler,options) {
|
||||||
var fileInfo = {}, metaExt;
|
var fileInfo = {}, metaExt;
|
||||||
|
// Propigate the isEditableFile flag
|
||||||
|
if(options.fileInfo) {
|
||||||
|
fileInfo.isEditableFile = options.fileInfo.isEditableFile || false;
|
||||||
|
}
|
||||||
// Check if the tiddler has any unsafe fields that can't be expressed in a .tid or .meta file: containing control characters, or leading/trailing whitespace
|
// Check if the tiddler has any unsafe fields that can't be expressed in a .tid or .meta file: containing control characters, or leading/trailing whitespace
|
||||||
var hasUnsafeFields = false;
|
var hasUnsafeFields = false;
|
||||||
$tw.utils.each(tiddler.getFieldStrings(),function(value,fieldName) {
|
$tw.utils.each(tiddler.getFieldStrings(),function(value,fieldName) {
|
||||||
@ -248,20 +252,22 @@ exports.generateTiddlerFileInfo = function(tiddler,options) {
|
|||||||
extFilters: options.extFilters,
|
extFilters: options.extFilters,
|
||||||
wiki: options.wiki
|
wiki: options.wiki
|
||||||
});
|
});
|
||||||
if(metaExt === ".tid") {
|
if(metaExt){
|
||||||
// Overriding to the .tid extension needs special handling
|
if(metaExt === ".tid") {
|
||||||
fileInfo.type = "application/x-tiddler";
|
// Overriding to the .tid extension needs special handling
|
||||||
fileInfo.hasMetaFile = false;
|
fileInfo.type = "application/x-tiddler";
|
||||||
} else if (metaExt === ".json") {
|
fileInfo.hasMetaFile = false;
|
||||||
// Overriding to the .json extension needs special handling
|
} else if (metaExt === ".json") {
|
||||||
fileInfo.type = "application/json";
|
// Overriding to the .json extension needs special handling
|
||||||
fileInfo.hasMetaFile = false;
|
fileInfo.type = "application/json";
|
||||||
} else if (metaExt) {
|
fileInfo.hasMetaFile = false;
|
||||||
//If the new type matches a known extention, use that MIME type's encoding
|
} else {
|
||||||
var extInfo = $tw.utils.getFileExtensionInfo(metaExt);
|
//If the new type matches a known extention, use that MIME type's encoding
|
||||||
fileInfo.type = extInfo ? extInfo.type : null;
|
var extInfo = $tw.utils.getFileExtensionInfo(metaExt);
|
||||||
fileInfo.encoding = $tw.utils.getTypeEncoding(metaExt);
|
fileInfo.type = extInfo ? extInfo.type : null;
|
||||||
fileInfo.hasMetaFile = true;
|
fileInfo.encoding = $tw.utils.getTypeEncoding(metaExt);
|
||||||
|
fileInfo.hasMetaFile = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,10 +282,6 @@ exports.generateTiddlerFileInfo = function(tiddler,options) {
|
|||||||
fileInfo: options.fileInfo,
|
fileInfo: options.fileInfo,
|
||||||
originalpath: options.originalpath
|
originalpath: options.originalpath
|
||||||
});
|
});
|
||||||
// Propigate the isEditableFile flag
|
|
||||||
if(options.fileInfo) {
|
|
||||||
fileInfo.isEditableFile = options.fileInfo.isEditableFile || false;
|
|
||||||
}
|
|
||||||
return fileInfo;
|
return fileInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -380,7 +382,7 @@ exports.generateTiddlerFilepath = function(title,options) {
|
|||||||
count++;
|
count++;
|
||||||
} while(fs.existsSync(fullPath));
|
} while(fs.existsSync(fullPath));
|
||||||
//If the path does not start with the wikiPath directory or the wikiTiddlersPath directory, or if the last write failed
|
//If the path does not start with the wikiPath directory or the wikiTiddlersPath directory, or if the last write failed
|
||||||
var encode = !(fullPath.indexOf($tw.boot.wikiPath) == 0 || fullPath.indexOf($tw.boot.wikiTiddlersPath) == 0) || ((options.fileInfo || {writeError: false}).writeError == true);
|
var encode = !(fullPath.indexOf(path.resolve($tw.boot.wikiPath)) == 0 || fullPath.indexOf($tw.boot.wikiTiddlersPath) == 0) || ((options.fileInfo || {writeError: false}).writeError == true);
|
||||||
if(encode){
|
if(encode){
|
||||||
//encodeURIComponent() and then resolve to tiddler directory
|
//encodeURIComponent() and then resolve to tiddler directory
|
||||||
fullPath = path.resolve(directory, encodeURIComponent(fullPath));
|
fullPath = path.resolve(directory, encodeURIComponent(fullPath));
|
||||||
|
@ -53,11 +53,17 @@ It is the responsibility of the filesystem adaptor to update this.boot.files for
|
|||||||
*/
|
*/
|
||||||
FileSystemAdaptor.prototype.getTiddlerFileInfo = function(tiddler,callback) {
|
FileSystemAdaptor.prototype.getTiddlerFileInfo = function(tiddler,callback) {
|
||||||
// Always generate a fileInfo object when this fuction is called
|
// Always generate a fileInfo object when this fuction is called
|
||||||
var title = tiddler.fields.title, newInfo;
|
var title = tiddler.fields.title, newInfo, pathFilters, extFilters;
|
||||||
|
if(this.wiki.tiddlerExists("$:/config/FileSystemPaths")){
|
||||||
|
pathFilters = this.wiki.getTiddlerText("$:/config/FileSystemPaths","").split("\n");
|
||||||
|
}
|
||||||
|
if(this.wiki.tiddlerExists("$:/config/FileSystemExtensions")){
|
||||||
|
extFilters = this.wiki.getTiddlerText("$:/config/FileSystemExtensions","").split("\n");
|
||||||
|
}
|
||||||
newInfo = $tw.utils.generateTiddlerFileInfo(tiddler,{
|
newInfo = $tw.utils.generateTiddlerFileInfo(tiddler,{
|
||||||
directory: this.boot.wikiTiddlersPath,
|
directory: this.boot.wikiTiddlersPath,
|
||||||
pathFilters: this.wiki.getTiddlerText("$:/config/FileSystemPaths","").split("\n"),
|
pathFilters: pathFilters,
|
||||||
extFilters: this.wiki.getTiddlerText("$:/config/FileSystemExtensions","").split("\n"),
|
extFilters: extFilters,
|
||||||
wiki: this.wiki,
|
wiki: this.wiki,
|
||||||
fileInfo: this.boot.files[title],
|
fileInfo: this.boot.files[title],
|
||||||
originalpath: this.wiki.extractTiddlerDataItem("$:/config/OriginalTiddlerPaths",title, "")
|
originalpath: this.wiki.extractTiddlerDataItem("$:/config/OriginalTiddlerPaths",title, "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user