lib/backup: properly create missing parent directories in fs.CreateFile

This commit is contained in:
Aliaksandr Valialkin 2020-06-05 19:28:14 +03:00
parent d120197676
commit 4e8d6b80e0

View File

@ -209,10 +209,10 @@ func (fs *FS) DeleteFile(filePath string) error {
//
// The file is overwritten if it exists.
func (fs *FS) CreateFile(filePath string, data []byte) error {
if err := fs.mkdirAll(filePath); err != nil {
path := filepath.Join(fs.Dir, filePath)
if err := fs.mkdirAll(path); err != nil {
return err
}
path := filepath.Join(fs.Dir, filePath)
if err := ioutil.WriteFile(path, data, 0600); err != nil {
return fmt.Errorf("cannot write %d bytes to %q: %s", len(data), path, err)
}