diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-07-18 13:25:28 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-07-22 14:49:22 +0000 |
| commit | 6ce0983056e7e9efff04681de67e6310b88fdc16 (patch) | |
| tree | ccaa5d515f42645bc9cb9b3366c28533b6ba9b89 /pkg/osutil/fileutil.go | |
| parent | 055e9354ef02e1231d7e2c369f57baf59b98011d (diff) | |
pkg/manager: add a test for PatchFocusAreas
For that, make a part of the tar_test.go reusable.
Diffstat (limited to 'pkg/osutil/fileutil.go')
| -rw-r--r-- | pkg/osutil/fileutil.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/osutil/fileutil.go b/pkg/osutil/fileutil.go index 850335cfe..cd5b602cf 100644 --- a/pkg/osutil/fileutil.go +++ b/pkg/osutil/fileutil.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "os" + "path/filepath" ) // CopyFile atomically copies oldFile to newFile preserving permissions and modification time. @@ -50,6 +51,21 @@ func Rename(oldFile, newFile string) error { return err } +// FillDirectory is used to fill in directory structure for tests. +func FillDirectory(dir string, fileContent map[string]string) error { + for path, content := range fileContent { + fullPath := filepath.Join(dir, path) + dirPath := filepath.Dir(fullPath) + if err := MkdirAll(dirPath); err != nil { + return fmt.Errorf("mkdir %q failed: %w", dirPath, err) + } + if err := WriteFile(fullPath, []byte(content)); err != nil { + return fmt.Errorf("write file failed: %w", err) + } + } + return nil +} + // WriteTempFile writes data to a temp file and returns its name. func WriteTempFile(data []byte) (string, error) { // Note: pkg/report knows about "syzkaller" prefix as it appears in crashes as process name. |
