From 3abf6c03978d07fb45865f11cd3d176358d628af Mon Sep 17 00:00:00 2001 From: Songmu Date: Sun, 24 Mar 2019 03:25:51 +0900 Subject: [PATCH] fix force option behavior --- statik.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/statik.go b/statik.go index 91b2a643..1d342ece 100644 --- a/statik.go +++ b/statik.go @@ -76,6 +76,10 @@ func main() { // rename tries to os.Rename, but fall backs to copying from src // to dest and unlink the source if os.Rename fails. func rename(src, dest string) error { + if _, err := os.Stat(dest); !os.IsNotExist(err) && !*flagForce { + return fmt.Errorf("file %q already exists; use -f to overwrite", dest) + } + // Try to rename generated source. if err := os.Rename(src, dest); err == nil { return nil @@ -91,16 +95,6 @@ func rename(src, dest string) error { os.Remove(src) // ignore the error, source is in tmp. }() - if _, err = os.Stat(dest); !os.IsNotExist(err) { - if *flagForce { - if err = os.Remove(dest); err != nil { - return fmt.Errorf("file %q could not be deleted", dest) - } - } else { - return fmt.Errorf("file %q already exists; use -f to overwrite", dest) - } - } - wc, err := os.Create(dest) if err != nil { return err