-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Check if the layer has been restored properly. If the layer is cache or build and the layer TOML exists, then the layer directory should also exist and have contents. If it does not exist or is empty then the layer was not restored and we need to reload the laery. This adds checks for this condition and will print a different message to indicate that the layer is being reloaded, instead of contributed fresh. - Add sherpa utilites for checking if a file, directory or symlink exist. These were needed for the refactoring above and are also common across other buildpacks. A set of tests is also provided. - Fixes test "adds expected Syft SBOM file" which was previously passing because a previous test run creates the SBOM file this test requires. Refactoring of the test class exposed this error. The test has been corrected. Signed-off-by: Daniel Mikusa <[email protected]>
- Loading branch information
Daniel Mikusa
committed
Apr 25, 2022
1 parent
f02533e
commit 260d07c
Showing
5 changed files
with
367 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2018-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package sherpa | ||
|
||
import "os" | ||
|
||
// Exists returns true if the path exists. | ||
func Exists(path string) (bool, error) { | ||
if _, err := os.Stat(path); err == nil { | ||
return true, nil | ||
} else if os.IsNotExist(err) { | ||
return false, nil | ||
} else { | ||
return false, err | ||
} | ||
} | ||
|
||
// FileExists returns true if the path exists and is a regular file. | ||
func FileExists(path string) (bool, error) { | ||
if stat, err := os.Stat(path); err == nil { | ||
return stat.Mode().IsRegular(), nil | ||
} else if os.IsNotExist(err) { | ||
return false, nil | ||
} else { | ||
return false, err | ||
} | ||
} | ||
|
||
// DirExists returns true if the path exists and is a directory. | ||
func DirExists(path string) (bool, error) { | ||
if stat, err := os.Stat(path); err == nil { | ||
return stat.IsDir(), nil | ||
} else if os.IsNotExist(err) { | ||
return false, nil | ||
} else { | ||
return false, err | ||
} | ||
} | ||
|
||
// SymlinkExists returns true if the path exists and is a symlink. | ||
func SymlinkExists(path string) (bool, error) { | ||
if stat, err := os.Lstat(path); err == nil { | ||
return stat.Mode()&os.ModeSymlink != 0, nil | ||
} else if os.IsNotExist(err) { | ||
return false, nil | ||
} else { | ||
return false, err | ||
} | ||
} |
Oops, something went wrong.