Add GLOB support to oputil fb scan...

This commit is contained in:
Bryan Ashby 2018-03-10 11:37:23 -07:00
parent f6f1de4bd8
commit 9c87d45433
3 changed files with 32 additions and 2 deletions

View File

@ -15,6 +15,7 @@ exports.getDefaultConfigPath = getDefaultConfigPath;
exports.getConfigPath = getConfigPath; exports.getConfigPath = getConfigPath;
exports.initConfigAndDatabases = initConfigAndDatabases; exports.initConfigAndDatabases = initConfigAndDatabases;
exports.getAreaAndStorage = getAreaAndStorage; exports.getAreaAndStorage = getAreaAndStorage;
exports.looksLikePattern = looksLikePattern;
const exitCodes = exports.ExitCodes = { const exitCodes = exports.ExitCodes = {
SUCCESS : 0, SUCCESS : 0,
@ -87,4 +88,13 @@ function getAreaAndStorage(tags) {
} }
return entry; return entry;
}); });
}
function looksLikePattern(tag) {
// globs can start with @
if(tag.indexOf('@') > 0) {
return false;
}
return /[*?[\]!()+|^]/.test(tag);
} }

View File

@ -7,7 +7,10 @@ const ExitCodes = require('./oputil_common.js').ExitCodes;
const argv = require('./oputil_common.js').argv; const argv = require('./oputil_common.js').argv;
const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases; const initConfigAndDatabases = require('./oputil_common.js').initConfigAndDatabases;
const getHelpFor = require('./oputil_help.js').getHelpFor; 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 Errors = require('../enig_error.js').Errors;
const async = require('async'); const async = require('async');
@ -16,6 +19,7 @@ const paths = require('path');
const _ = require('lodash'); const _ = require('lodash');
const moment = require('moment'); const moment = require('moment');
const inq = require('inquirer'); const inq = require('inquirer');
const glob = require('glob');
exports.handleFileBaseCommand = handleFileBaseCommand; exports.handleFileBaseCommand = handleFileBaseCommand;
@ -119,6 +123,14 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
const FileEntry = require('../file_entry.js'); 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.eachSeries(storageLocations, (storageLoc, nextLocation) => {
async.waterfall( async.waterfall(
[ [
@ -134,7 +146,7 @@ function scanFileAreaForChanges(areaInfo, options, cb) {
function scanPhysFiles(descHandler, callback) { function scanPhysFiles(descHandler, callback) {
const physDir = storageLoc.dir; const physDir = storageLoc.dir;
fs.readdir(physDir, (err, files) => { readDir(physDir, (err, files) => {
if(err) { if(err) {
return callback(err); return callback(err);
} }
@ -498,6 +510,12 @@ function scanFileAreas() {
options.areaAndStorageInfo = getAreaAndStorage(argv._.slice(2)); 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( async.series(
[ [
function init(callback) { function init(callback) {

View File

@ -49,6 +49,8 @@ import-areas args:
actions: actions:
scan AREA_TAG[@STORAGE_TAG] scan specified area 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 info AREA_TAG|SHA|FILE_ID display information about areas and/or files
SHA may be a full or partial SHA-256 SHA may be a full or partial SHA-256