mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
fix: handle errors reading go licenses (#2985)
Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Vendored
+1
-1
@@ -87,7 +87,7 @@ func subFs(fsys afero.Fs, subDirs ...string) (afero.Fs, error) {
|
||||
if errors.Is(err, afero.ErrFileNotFound) {
|
||||
err = fsys.MkdirAll(dir, dirPermissions)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create directory at '%s/%s': %v", dir, strings.Join(subDirs, "/"), err)
|
||||
return nil, fmt.Errorf("unable to create directory at '%s': %v", dir, err)
|
||||
}
|
||||
stat, err = fsys.Stat(dir)
|
||||
if err != nil {
|
||||
|
||||
Vendored
+12
@@ -1,6 +1,7 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -92,3 +93,14 @@ func Test_makeDiskKey(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_errors(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
cache := filepath.Join(tmp, "cache")
|
||||
// make a non-writable directory
|
||||
require.NoError(t, os.MkdirAll(cache, 0500|os.ModeDir))
|
||||
// attempt to make cache in non-writable directory
|
||||
dir := filepath.Join(cache, "dir")
|
||||
_, err := NewFromDir(dir, time.Hour)
|
||||
require.ErrorContains(t, err, fmt.Sprintf("unable to create directory at '%s':", dir))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user