feat: make sure internal path is mkdir before download

Fix https://github.com/haunt98/dotfiles/issues/26
main
sudo pacman -Syu 2022-10-31 22:43:54 +07:00
parent 1d3635053b
commit 22ff5073d1
No known key found for this signature in database
GPG Key ID: D6CB5C6C567C47B0
1 changed files with 7 additions and 0 deletions

View File

@ -69,6 +69,13 @@ func (c *configReal) Download() error {
return fmt.Errorf("io: failed to read all: %w", err) return fmt.Errorf("io: failed to read all: %w", err)
} }
// Copy from github.com/make-go-great/copy-go
// Make sure nested dir is exist before copying file
dstDir := filepath.Dir(p.Internal)
if err := os.MkdirAll(dstDir, os.ModePerm); err != nil {
return fmt.Errorf("failed to mkdir %s: %w", dstDir, err)
}
if err := os.WriteFile(p.Internal, data, 0o600); err != nil { if err := os.WriteFile(p.Internal, data, 0o600); err != nil {
return fmt.Errorf("os: failed to write file: %w", err) return fmt.Errorf("os: failed to write file: %w", err)
} }