-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip] migrate DB definitions from grype
Signed-off-by: Alex Goodman <[email protected]>
- Loading branch information
Showing
220 changed files
with
17,402 additions
and
268 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
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,68 @@ | ||
package file | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path" | ||
|
||
"github.com/spf13/afero" | ||
) | ||
|
||
func CopyDir(fs afero.Fs, src string, dst string) error { | ||
var err error | ||
var fds []os.DirEntry | ||
var srcinfo os.FileInfo | ||
|
||
if srcinfo, err = fs.Stat(src); err != nil { | ||
return err | ||
} | ||
|
||
if err = fs.MkdirAll(dst, srcinfo.Mode()); err != nil { | ||
return err | ||
} | ||
|
||
if fds, err = os.ReadDir(src); err != nil { | ||
return err | ||
} | ||
for _, fd := range fds { | ||
srcPath := path.Join(src, fd.Name()) | ||
dstPath := path.Join(dst, fd.Name()) | ||
|
||
if fd.IsDir() { | ||
if err = CopyDir(fs, srcPath, dstPath); err != nil { | ||
return fmt.Errorf("could not copy dir (%s -> %s): %w", srcPath, dstPath, err) | ||
} | ||
} else { | ||
if err = CopyFile(fs, srcPath, dstPath); err != nil { | ||
return fmt.Errorf("could not copy file (%s -> %s): %w", srcPath, dstPath, err) | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func CopyFile(fs afero.Fs, src, dst string) error { | ||
var err error | ||
var srcFd afero.File | ||
var dstFd afero.File | ||
var srcinfo os.FileInfo | ||
|
||
if srcFd, err = fs.Open(src); err != nil { | ||
return err | ||
} | ||
defer srcFd.Close() | ||
|
||
if dstFd, err = fs.Create(dst); err != nil { | ||
return err | ||
} | ||
defer dstFd.Close() | ||
|
||
if _, err = io.Copy(dstFd, srcFd); err != nil { | ||
return err | ||
} | ||
if srcinfo, err = fs.Stat(src); err != nil { | ||
return err | ||
} | ||
return fs.Chmod(dst, srcinfo.Mode()) | ||
} |
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
Oops, something went wrong.