Improve book.findFile to be case incensitive

This commit is contained in:
Samy Pessé
2015-11-16 10:31:24 +01:00
parent 751cdd9b3b
commit e38f3bb884
2 changed files with 17 additions and 4 deletions
+5 -4
View File
@@ -614,12 +614,13 @@ Book.prototype.findFile = function(filename) {
var filepath = basename+ext;
return that.fileExists(filepath)
.then(function(exists) {
if (!exists) return null;
return fs.findFile(that.root, filepath)
.then(function(realFilepath) {
if (!realFilepath) return null;
return {
parser: parsers.get(ext),
path: filepath
path: realFilepath
};
});
});
+12
View File
@@ -30,6 +30,7 @@ var fsUtils = {
fs.exists(path, d.resolve);
return d.promise;
},
findFile: findFile,
existsSync: fs.existsSync.bind(fs),
readFileSync: fs.readFileSync.bind(fs),
clean: cleanFolder,
@@ -178,4 +179,15 @@ function cleanFolder(root) {
});
}
// Find a file in a folder (case incensitive)
// Return the real filename
function findFile(root, filename) {
return Q.nfcall(fs.readdir, root)
.then(function(files) {
return _.find(files, function(file) {
return (file.toLowerCase() == filename.toLowerCase());
});
});
}
module.exports = fsUtils;