Add GLOB support to oputil fb scan...
This commit is contained in:
parent
f6f1de4bd8
commit
9c87d45433
|
@ -15,6 +15,7 @@ exports.getDefaultConfigPath = getDefaultConfigPath;
|
|||
exports.getConfigPath = getConfigPath;
|
||||
exports.initConfigAndDatabases = initConfigAndDatabases;
|
||||
exports.getAreaAndStorage = getAreaAndStorage;
|
||||
exports.looksLikePattern = looksLikePattern;
|
||||
|
||||
const exitCodes = exports.ExitCodes = {
|
||||
SUCCESS : 0,
|
||||
|
@ -88,3 +89,12 @@ function getAreaAndStorage(tags) {
|
|||
return entry;
|
||||
});
|
||||
}
|
||||
|
||||
function looksLikePattern(tag) {
|
||||
// globs can start with @
|
||||
if(tag.indexOf('@') > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /[*?[\]!()+|^]/.test(tag);
|
||||
}
|
|
@ -7,7 +7,10 @@ const ExitCodes = require('./oputil_common.js').ExitCodes;
|
|||
const argv = require('./oputil_common.js').argv;
|
||||
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
|
||||
const getHelpFor = require('./oputil_help.js').getHelpFor;
|
||||
const getAreaAndStorage = require('./oputil_common.js').getAreaAndStorage;
|
||||
const {
|
||||
getAreaAndStorage,
|
||||
looksLikePattern
|
||||
} = require('./oputil_common.js');
|
||||
const Errors = require('../enig_error.js').Errors;
|
||||
|
||||
const async = require('async');
|
||||
|
@ -16,6 +19,7 @@ const paths = require('path');
|
|||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
const inq = require('inquirer');
|
||||
const glob = require('glob');
|
||||
|
||||
exports.handleFileBaseCommand = handleFileBaseCommand;
|
||||
|
||||
|
@ -119,6 +123,14 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
|
|||
|
||||
const FileEntry = require('../file_entry.js');
|
||||
|
||||
const readDir = options.glob ?
|
||||
(dir, next) => {
|
||||
return glob(options.glob, { cwd : dir, nodir : true }, next);
|
||||
} :
|
||||
(dir, next) => {
|
||||
return fs.readdir(dir, next);
|
||||
};
|
||||
|
||||
async.eachSeries(storageLocations, (storageLoc, nextLocation) => {
|
||||
async.waterfall(
|
||||
[
|
||||
|
@ -134,7 +146,7 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
|
|||
function scanPhysFiles(descHandler, callback) {
|
||||
const physDir = storageLoc.dir;
|
||||
|
||||
fs.readdir(physDir, (err, files) => {
|
||||
readDir(physDir, (err, files) => {
|
||||
if(err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
@ -498,6 +510,12 @@ function scanFileAreas() {
|
|||
|
||||
options.areaAndStorageInfo = getAreaAndStorage(argv._.slice(2));
|
||||
|
||||
const last = argv._[argv._.length - 1];
|
||||
if(options.areaAndStorageInfo.length > 1 && looksLikePattern(last)) {
|
||||
options.glob = last;
|
||||
options.areaAndStorageInfo.length -= 1;
|
||||
}
|
||||
|
||||
async.series(
|
||||
[
|
||||
function init(callback) {
|
||||
|
|
|
@ -49,6 +49,8 @@ import-areas args:
|
|||
|
||||
actions:
|
||||
scan AREA_TAG[@STORAGE_TAG] scan specified area
|
||||
may also contain optional GLOB as last parameter,
|
||||
for examle: scan some_area *.zip
|
||||
|
||||
info AREA_TAG|SHA|FILE_ID display information about areas and/or files
|
||||
SHA may be a full or partial SHA-256
|
||||
|
|
Loading…
Reference in New Issue