From 2bd82e1981ce4e52e54e96235c73ad0fd6da1bb1 Mon Sep 17 00:00:00 2001 From: trading_peter Date: Thu, 20 Jan 2022 20:59:48 +0100 Subject: [PATCH] Create copy destination if it doesn't exist. --- main.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 658b5bd..b165d15 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "os" "os/signal" @@ -143,13 +144,24 @@ func cp(opts options) { } 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() } func isDir(path string) bool { - stat, _ := os.Stat(path) - return stat.IsDir() + stat, err := os.Stat(path) + + if errors.Is(err, os.ErrNotExist) { + os.MkdirAll(path, 0755) + return true + } + + return err == nil && stat.IsDir() } func build(opts options) {