mirror of
https://github.com/kopia/kopia.git
synced 2026-04-28 09:59:10 -04:00
* fixed godot linter errors * reformatted source with gofumpt * disabled some linters * fixed nolintlint warnings * fixed gci warnings * lint: fixed 'nestif' warnings * lint: fixed 'exhaustive' warnings * lint: fixed 'gocritic' warnings * lint: fixed 'noctx' warnings * lint: fixed 'wsl' warnings * lint: fixed 'goerr113' warnings * lint: fixed 'gosec' warnings * lint: upgraded linter to 1.30.0 * lint: more 'exhaustive' warnings Co-authored-by: Nick <nick@kasten.io>
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package fio
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// WriteFiles writes files to the directory specified by path, up to the
|
|
// provided size and number of files.
|
|
func (fr *Runner) WriteFiles(relPath string, opt Options) error {
|
|
fullPath := filepath.Join(fr.LocalDataDir, relPath)
|
|
return fr.writeFiles(fullPath, opt)
|
|
}
|
|
|
|
func (fr *Runner) writeFiles(fullPath string, opt Options) error {
|
|
err := os.MkdirAll(fullPath, 0o700)
|
|
if err != nil {
|
|
return errors.Wrap(err, "unable to make directory for write")
|
|
}
|
|
|
|
relWritePath, err := filepath.Rel(fr.LocalDataDir, fullPath)
|
|
if err != nil {
|
|
return errors.Wrapf(err, "error finding relative file path between %v and %v", fr.LocalDataDir, fullPath)
|
|
}
|
|
|
|
absWritePath := filepath.Join(fr.FioWriteBaseDir, relWritePath)
|
|
|
|
_, _, err = fr.RunConfigs(Config{
|
|
{
|
|
Name: "writeFiles",
|
|
Options: opt.Merge(
|
|
Options{
|
|
"readwrite": RandWriteFio,
|
|
"filename_format": "file_$filenum",
|
|
}.WithDirectory(absWritePath),
|
|
),
|
|
},
|
|
})
|
|
|
|
return err
|
|
}
|
|
|
|
// DeleteRelDir deletes a relative directory in the runner's data directory.
|
|
func (fr *Runner) DeleteRelDir(relDirPath string) error {
|
|
return os.RemoveAll(filepath.Join(fr.LocalDataDir, relDirPath))
|
|
}
|