mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-07 13:15:28 +02:00
Minor updates to FileEntry / oputil
This commit is contained in:
parent
d7aabba847
commit
63b5eed504
2 changed files with 25 additions and 2 deletions
|
@ -369,7 +369,7 @@ module.exports = class FileEntry {
|
||||||
return Object.keys(FILE_WELL_KNOWN_META);
|
return Object.keys(FILE_WELL_KNOWN_META);
|
||||||
}
|
}
|
||||||
|
|
||||||
static findFileBySha(sha, cb) {
|
static findBySha(sha, cb) {
|
||||||
// full or partial SHA-256
|
// full or partial SHA-256
|
||||||
fileDb.all(
|
fileDb.all(
|
||||||
`SELECT file_id
|
`SELECT file_id
|
||||||
|
@ -397,6 +397,29 @@ module.exports = class FileEntry {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attempt to fine a file by an *existing* full path.
|
||||||
|
// Checkums may have changed and are not validated here.
|
||||||
|
static findByFullPath(fullPath, cb) {
|
||||||
|
// first, basic by-filename lookup.
|
||||||
|
FileEntry.findByFileNameWildcard(paths.basename(fuillPath), (err, entries) => {
|
||||||
|
if(err) {
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
if(!entries || !entries.length || entries.length > 1) {
|
||||||
|
return cb(Errors.DoesNotExist('No matches'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure the *full* path has not changed
|
||||||
|
// :TODO: if FS is case-insensitive, we probably want a better check here
|
||||||
|
const possibleMatch = entries[0];
|
||||||
|
if(possibleMatch.fullPath === fullPath) {
|
||||||
|
return cb(null, possibleMatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb(Errors.DoesNotExist('No matches'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static findByFileNameWildcard(wc, cb) {
|
static findByFileNameWildcard(wc, cb) {
|
||||||
// convert any * -> % and ? -> _ for SQLite syntax - see https://www.sqlite.org/lang_expr.html
|
// convert any * -> % and ? -> _ for SQLite syntax - see https://www.sqlite.org/lang_expr.html
|
||||||
wc = wc.replace(/\*/g, '%').replace(/\?/g, '_');
|
wc = wc.replace(/\*/g, '%').replace(/\?/g, '_');
|
||||||
|
|
|
@ -319,7 +319,7 @@ function getFileEntries(pattern, cb) {
|
||||||
return callback(null, entries); // already got it by FILE_ID
|
return callback(null, entries); // already got it by FILE_ID
|
||||||
}
|
}
|
||||||
|
|
||||||
FileEntry.findFileBySha(pattern, (err, fileEntry) => {
|
FileEntry.findBySha(pattern, (err, fileEntry) => {
|
||||||
return callback(null, fileEntry ? [ fileEntry ] : null );
|
return callback(null, fileEntry ? [ fileEntry ] : null );
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue