20561: Don't fail when inspecting a file outside the output directory 20561-file-copy-logging
authorPeter Amstutz <peter.amstutz@curii.com>
Tue, 30 May 2023 18:58:13 +0000 (14:58 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Tue, 30 May 2023 18:58:13 +0000 (14:58 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

lib/crunchrun/copier.go

index d440b8f8d3d03262823aedd2192c645209efdacb..734b2c2822f0653364a15ebdc4df64f1c0acb0e4 100644 (file)
@@ -161,7 +161,20 @@ func (cp *copier) walkMount(dest, src string, maxSymlinks int, walkMountsBelow b
        // srcRelPath is the path to the file/dir we are trying to
        // copy, relative to its mount point -- ".", "./foo.txt", ...
        srcRelPath := filepath.Join(".", srcMount.Path, src[len(srcRoot):])
-       outputRelPath := src[len(cp.ctrOutputDir):]
+
+       // outputRelPath is the path relative in the output directory
+       // that corresponds to the path in the output collection where
+       // the file will go, for logging
+       var outputRelPath = ""
+       if strings.HasPrefix(src, cp.ctrOutputDir) {
+               outputRelPath = strings.TrimPrefix(src[len(cp.ctrOutputDir):], "/")
+       }
+       if outputRelPath == "" {
+               // blank means copy a whole directory, so replace it
+               // with a wildcard to make it a little clearer what's
+               // going on since outputRelPath is only used for logging
+               outputRelPath = "*"
+       }
 
        switch {
        case srcMount.ExcludeFromOutput: