Selaa lähdekoodia

Deal with directories and symlinks without treating them as missing

Using backup.getFileName for directory or symlink entries would throw
an exception due to the file missing, so we never got to stat the
file and check if it was a directory.

By using the stat mode from the backup itself we can skip both
directories and symlinks before we get to the backup.getFileName
step.

Ideally we'd restore symlinks too, but this is left for future
work. Restoring the mode of the files probably doesn't add much,
but in theory we could do that too.
Tor Arne Vestbø 5 vuotta sitten
vanhempi
commit
a421bdcc5e
1 muutettua tiedostoa jossa 13 lisäystä ja 4 poistoa
  1. 13 4
      tools/reports/backup/files.js

+ 13 - 4
tools/reports/backup/files.js

@@ -117,11 +117,22 @@ function extractFiles (backup, destination, filter, items) {
     }
 
     try {
+      var stat = new Mode(item)
+      if (stat.isDirectory()) {
+        // Created implicitly below
+        continue
+      }
+
+      if (stat.isSymbolicLink()) {
+        log.warning('skipping symlink', item.filename)
+        // FIXME: Restore symlinks
+        continue
+      }
+
       let sourceFile = backup.getFileName(item.fileID)
-      var stat = fs.lstatSync(sourceFile)
 
       // Only process files that exist.
-      if (stat.isFile() && fs.existsSync(sourceFile)) {
+      if (fs.existsSync(sourceFile)) {
         log.action('export', item.filename)
 
         // Calculate the output dir.
@@ -133,8 +144,6 @@ function extractFiles (backup, destination, filter, items) {
 
         // Save output info to the data item.
         item.output_dir = outDir
-      } else if (stat.isDirectory()) {
-      // Do nothing..
       } else {
         log.error('not found', sourceFile)
       }