Skip to content

Commit b7603f9

Browse files
committed
storage: change logic of ArtifactExist method
Given that: * The produced artifact as advertisted in the path should always be a regular file (including the exclusion of symlinks). * The produced artifact should be readable, so any type of error should count as "does not exist". We should use `os.Lstat` to not follow symlinks; return `false` on any error we run in to, or return if the file mode information reports a regular file.
1 parent 0ae11b6 commit b7603f9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

controllers/storage.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,14 @@ func (s *Storage) RemoveAllButCurrent(artifact sourcev1.Artifact) error {
120120
return nil
121121
}
122122

123-
// ArtifactExist returns a boolean indicating whether the artifact file exists in storage
123+
// ArtifactExist returns a boolean indicating whether the artifact exists in storage and is a
124+
// regular file.
124125
func (s *Storage) ArtifactExist(artifact sourcev1.Artifact) bool {
125-
if _, err := os.Stat(artifact.Path); os.IsNotExist(err) {
126+
fi, err := os.Lstat(artifact.Path)
127+
if err != nil {
126128
return false
127129
}
128-
return true
130+
return fi.Mode().IsRegular()
129131
}
130132

131133
// Archive creates a tar.gz to the artifact path from the given dir excluding any VCS specific

0 commit comments

Comments
 (0)