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.
This commit is contained in:
Hidde Beydals 2020-09-01 16:01:19 +02:00
parent 0ae11b6d3f
commit b7603f9fd3
1 changed files with 5 additions and 3 deletions

View File

@ -120,12 +120,14 @@ func (s *Storage) RemoveAllButCurrent(artifact sourcev1.Artifact) error {
return nil
}
// ArtifactExist returns a boolean indicating whether the artifact file exists in storage
// ArtifactExist returns a boolean indicating whether the artifact exists in storage and is a
// regular file.
func (s *Storage) ArtifactExist(artifact sourcev1.Artifact) bool {
if _, err := os.Stat(artifact.Path); os.IsNotExist(err) {
fi, err := os.Lstat(artifact.Path)
if err != nil {
return false
}
return true
return fi.Mode().IsRegular()
}
// Archive creates a tar.gz to the artifact path from the given dir excluding any VCS specific