Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#1165 fake outputs don't notify and task completes successfully #1247

Merged
merged 2 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions workflow/executor/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
"time"

"github.com/argoproj/argo/workflow/util/file"

"github.com/argoproj/argo/util"

"github.com/argoproj/argo/errors"
Expand Down Expand Up @@ -51,6 +53,11 @@ func (d *DockerExecutor) CopyFile(containerID string, sourcePath string, destPat
if err != nil {
return err
}
if !file.IsFileOrDirExistInGZip(sourcePath, destPath) {
errMsg := fmt.Sprintf("File or Artifact does not exist. %s", sourcePath)
log.Warn(errMsg)
return errors.InternalError(errMsg)
}
log.Infof("Archiving completed")
return nil
}
Expand Down
52 changes: 52 additions & 0 deletions workflow/util/file/fileutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package file

import (
"archive/tar"
"compress/gzip"
"io"
"os"
"strings"

log "github.com/sirupsen/logrus"
)

//IsFileOrDirExistInGZip return true if file or directory exists in GZip file
func IsFileOrDirExistInGZip(sourcePath string, gzipFilePath string) bool {

fi, err := os.Open(gzipFilePath)

if os.IsNotExist(err) {
return false
}
defer closeFile(fi)

fz, err := gzip.NewReader(fi)
if err != nil {
return false
}
tr := tar.NewReader(fz)
for {
hdr, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {

return false
}
if hdr.FileInfo().IsDir() && strings.Contains(strings.Trim(hdr.Name, "/"), strings.Trim(sourcePath, "/")) {
return true
}
if strings.Contains(sourcePath, hdr.Name) && hdr.Size > 0 {
return true
}
}
return false
}

func closeFile(f *os.File) {
err := f.Close()
if err != nil {
log.Warn("Failed to close the file. v%", err)
}
}