瀏覽代碼

Allow passing multiple filters as an array

All filters must match for a file to be included.
Tor Arne Vestbø 4 年之前
父節點
當前提交
388355c441
共有 5 個文件被更改,包括 30 次插入11 次删除
  1. 4 1
      Readme.md
  2. 10 3
      package-lock.json
  3. 1 1
      package.json
  4. 1 1
      tools/cli.js
  5. 14 5
      tools/reports/backup/files.js

+ 4 - 1
Readme.md

@@ -113,7 +113,10 @@ ibackuptool -b $UDID --report system.wifi,phone.calls,phone.voicemail -f csv -o
 ```
 
 ## Extracting files
-the `--extract <path>` parameter paired with the backup.files report will extract all files in a backup, with filenames matching an optional filter (specified by `--filter <filter>`).
+the `--extract <path>` parameter paired with the backup.files report will extract all files in a backup.
+
+To limit which files are extracted, pass one or more filters via `--filter <filter>`.
+Each filter must match for the file to be included.
 
 ```bash
 # Export all photos onto "~/Desktop/Photos"

+ 10 - 3
package-lock.json

@@ -661,9 +661,9 @@
       }
     },
     "commander": {
-      "version": "2.20.3",
-      "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
-      "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
+      "version": "6.1.0",
+      "resolved": "https://registry.npmjs.org/commander/-/commander-6.1.0.tgz",
+      "integrity": "sha512-wl7PNrYWd2y5mp1OK/LhTlv8Ff4kQJQRXXAvF+uU/TPNiVJUxZLRYGj/B0y/lPGAVcSbJqH2Za/cvHmrPMC8mA=="
     },
     "commondir": {
       "version": "1.0.1",
@@ -2227,6 +2227,13 @@
         "lodash.set": "^4.3.0",
         "lodash.uniq": "^4.5.0",
         "path-is-absolute": "^1.0.0"
+      },
+      "dependencies": {
+        "commander": {
+          "version": "2.20.3",
+          "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
+          "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
+        }
       }
     },
     "json5": {

+ 1 - 1
package.json

@@ -18,7 +18,7 @@
     "bplist-parser": "^0.1.1",
     "buffer-reader": "^0.1.0",
     "chalk": "^1.1.3",
-    "commander": "^2.15.1",
+    "commander": "^6.1.0",
     "fs-extra": "^4.0.3",
     "json2csv": "^3.11.5",
     "plist": "^2.1.0",

+ 1 - 1
tools/cli.js

@@ -37,7 +37,7 @@ program
   .option('-o, --output <path>', 'Specify an output directory for files to be written to.')
   .option(`-v, --verbose`, 'Verbose debugging output')
   .option(`    --plugins <plugins>`, 'List of pluging modules to use')
-  .option(`    --filter <filter>`, 'Filter output fo r individual reports. See the README for usage.')
+  .option(`    --filter <filter...>`, 'Filters output for individual reports.')
   .option('    --join-reports', 'Join JSON reports together. (available for -f json or -f raw only!)')
   .option(`    --no-color`, 'Disable colorized output')
   .option(`    --dump`, 'alias for "--formatter raw"')

+ 14 - 5
tools/reports/backup/files.js

@@ -97,11 +97,20 @@ function getManifest (backup) {
 
 /// Filter exclusion check
 function isIncludedByFilter (filter, item, filePath) {
-  return filter === 'all' ||
-    filter === undefined ||
-    (filter && item.domain.indexOf(filter) > -1) ||
-    (filter && item.filename.indexOf(filter) > -1) ||
-    (filePath.indexOf(filter) > -1)
+  if (filter === 'all' || filter === undefined)
+    return true;
+
+  for (var f of Array.isArray(filter) ? filter : [filter]) {
+    if (!isIncludedBySingleFilter(f, item, filePath))
+      return false;
+  }
+  return true;
+}
+
+function isIncludedBySingleFilter (filter, item, filePath) {
+  return item.domain.indexOf(filter) > -1 ||
+    item.filename.indexOf(filter) > -1 ||
+    filePath.indexOf(filter) > -1;
 }
 
 /// Extract files