fb move FILENAME_WC ... DST support: Allow moving entries via their filenames inc. wildcard support

This commit is contained in:
Bryan Ashby 2017-05-23 21:55:22 -06:00
parent 1c92b349cd
commit 3a41a6b2e1
3 changed files with 106 additions and 42 deletions

View file

@ -353,6 +353,41 @@ module.exports = class FileEntry {
);
}
static findByFileNameWildcard(wc, cb) {
// convert any * -> % and ? -> _ for SQLite syntax - see https://www.sqlite.org/lang_expr.html
wc = wc.replace(/\*/g, '%').replace(/\?/g, '_');
fileDb.all(
`SELECT file_id
FROM file
WHERE file_name LIKE "${wc}"
`,
(err, fileIdRows) => {
if(err) {
return cb(err);
}
if(!fileIdRows || 0 === fileIdRows.length) {
return cb(Errors.DoesNotExist('No matches'));
}
const entries = [];
async.each(fileIdRows, (row, nextRow) => {
const fileEntry = new FileEntry();
fileEntry.load(row.file_id, err => {
if(!err) {
entries.push(fileEntry);
}
return nextRow(err);
});
},
err => {
return cb(err, entries);
});
}
);
}
static findFiles(filter, cb) {
filter = filter || {};