X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a1adf1ed6f93ce0769f307a86b6389e9e8e630a9..16f704326f44fd1e5e5e60b936c9b5895d6a6ff8:/sdk/go/crunchrunner/upload.go diff --git a/sdk/go/crunchrunner/upload.go b/sdk/go/crunchrunner/upload.go index 06a6678e5c..2848d1087c 100644 --- a/sdk/go/crunchrunner/upload.go +++ b/sdk/go/crunchrunner/upload.go @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + package main import ( @@ -5,14 +9,15 @@ import ( "crypto/md5" "errors" "fmt" - "git.curoverse.com/arvados.git/sdk/go/keepclient" - "git.curoverse.com/arvados.git/sdk/go/manifest" "io" "log" "os" "path/filepath" "sort" "strings" + + "git.curoverse.com/arvados.git/sdk/go/keepclient" + "git.curoverse.com/arvados.git/sdk/go/manifest" ) type Block struct { @@ -86,7 +91,26 @@ type ManifestWriter struct { } func (m *ManifestWriter) WalkFunc(path string, info os.FileInfo, err error) error { - if info.IsDir() { + if err != nil { + return err + } + + targetPath, targetInfo := path, info + if info.Mode()&os.ModeSymlink != 0 { + // Update targetpath/info to reflect the symlink + // target, not the symlink itself + targetPath, err = filepath.EvalSymlinks(path) + if err != nil { + return err + } + targetInfo, err = os.Stat(targetPath) + if err != nil { + return fmt.Errorf("stat symlink %q target %q: %s", path, targetPath, err) + } + } + + if targetInfo.Mode()&os.ModeType != 0 { + // Skip directories, pipes, other non-regular files return nil } @@ -130,8 +154,8 @@ func (m *ManifestWriter) WalkFunc(path string, info os.FileInfo, err error) erro stream.offset += count - stream.ManifestStream.FileTokens = append(stream.ManifestStream.FileTokens, - fmt.Sprintf("%v:%v:%v", fileStart, count, fn)) + stream.ManifestStream.FileStreamSegments = append(stream.ManifestStream.FileStreamSegments, + manifest.FileStreamSegment{uint64(fileStart), uint64(count), fn}) return nil } @@ -189,11 +213,11 @@ func (m *ManifestWriter) ManifestText() string { buf.WriteString(" ") buf.WriteString(b) } - for _, f := range v.FileTokens { + for _, f := range v.FileStreamSegments { buf.WriteString(" ") - f = strings.Replace(f, " ", "\\040", -1) - f = strings.Replace(f, "\n", "", -1) - buf.WriteString(f) + name := strings.Replace(f.Name, " ", "\\040", -1) + name = strings.Replace(name, "\n", "", -1) + buf.WriteString(fmt.Sprintf("%d:%d:%s", f.SegPos, f.SegLen, name)) } buf.WriteString("\n") }