Create copy destination if it doesn't exist.

This commit is contained in:
trading_peter 2022-01-20 20:59:48 +01:00
parent 311339685c
commit 2bd82e1981

18
main.go
View File

@ -2,6 +2,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os" "os"
"os/signal" "os/signal"
@ -143,13 +144,24 @@ func cp(opts options) {
} }
func isFile(path string) bool { func isFile(path string) bool {
stat, _ := os.Stat(path) stat, err := os.Stat(path)
if errors.Is(err, os.ErrNotExist) {
return false
}
return !stat.IsDir() return !stat.IsDir()
} }
func isDir(path string) bool { func isDir(path string) bool {
stat, _ := os.Stat(path) stat, err := os.Stat(path)
return stat.IsDir()
if errors.Is(err, os.ErrNotExist) {
os.MkdirAll(path, 0755)
return true
}
return err == nil && stat.IsDir()
} }
func build(opts options) { func build(opts options) {