Skip to content

Commit

Permalink
fix(worker): fix worker cache for weird files (#3090)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <benjamin.coenen@corp.ovh.com>
  • Loading branch information
bnjjj authored and sguiheux committed Jul 27, 2018
1 parent d270042 commit b8fbeba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion engine/worker/cmd_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func cachePushCmd(w *currentWorker) func(cmd *cobra.Command, args []string) {
sdk.Exit("cache push HTTP error %v\n", err)
}
cdsError := sdk.DecodeError(body)
sdk.Exit("Error: http cod %d : %v\n", resp.StatusCode, cdsError)
sdk.Exit("Error: http code %d : %v\n", resp.StatusCode, cdsError)
}

fmt.Printf("Worker cache push with success (tag: %s)\n", args[0])
Expand Down
29 changes: 17 additions & 12 deletions sdk/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ func CreateTarFromPaths(cwd string, paths []string) (io.Reader, error) {
}

func tarWrite(cwd, path string, tw *tar.Writer, fi os.FileInfo) error {
filR, err := os.Open(path)
if err != nil {
return WrapError(err, "tarWrite> cannot open path")
}
defer filR.Close()

filename, err := filepath.Rel(cwd, path)
if err != nil {
return WrapError(err, "tarWrite> cannot find relative path")
Expand All @@ -101,15 +95,20 @@ func tarWrite(cwd, path string, tw *tar.Writer, fi os.FileInfo) error {
hdr.Typeflag = tar.TypeDir
}

// Useful to not copy files like socket or device files
if !fi.IsDir() && !fi.Mode().IsRegular() {
return nil
}

if fi.Mode()&os.ModeSymlink != 0 {
symlink, err := filepath.EvalSymlinks(path)
if err != nil {
return WrapError(err, "tarWrite> cannot get resolve path %s", path)
symlink, errEval := filepath.EvalSymlinks(path)
if errEval != nil {
return WrapError(errEval, "tarWrite> cannot get resolve path %s", path)
}

fil, err := os.Lstat(symlink)
if err != nil {
return WrapError(err, "tarWrite> cannot get resolve(lstat) link")
fil, errLs := os.Lstat(symlink)
if errLs != nil {
return WrapError(errLs, "tarWrite> cannot get resolve(lstat) link")
}

hdr.Size = fil.Size()
Expand All @@ -120,6 +119,12 @@ func tarWrite(cwd, path string, tw *tar.Writer, fi os.FileInfo) error {
}
}

filR, err := os.Open(path)
if err != nil {
return WrapError(err, "tarWrite> cannot open path")
}
defer filR.Close()

if err := tw.WriteHeader(hdr); err != nil {
return WrapError(err, "tarWrite> cannot write header")
}
Expand Down

0 comments on commit b8fbeba

Please sign in to comment.