all repos — vite @ 0e6d0f0bcdb003d551090c622d0930e031e85bb1

a fast (this time, actually) and minimal static site generator

Check to ensure we don't overwrite existing files
Anirudh Oppiliappan x@icyphox.sh
Mon, 27 Dec 2021 17:43:13 +0530
commit

0e6d0f0bcdb003d551090c622d0930e031e85bb1

parent

f0b087d2355c05708cf48cf832273301e65d1095

1 files changed, 11 insertions(+), 5 deletions(-)

jump to
M commands/new.gocommands/new.go

@@ -1,6 +1,7 @@

package commands import ( + "errors" "fmt" "os" "path/filepath"

@@ -20,11 +21,16 @@ subtitle:

date: %s ---`, url, time.Now().Format("2006-01-02")) - _, err := os.Create(path) - if err != nil { - return err + if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) { + _, err := os.Create(path) + if err != nil { + return err + } + os.WriteFile(path, []byte(content), 0755) + fmt.Printf("vite: created new post at %s\n", path) + return nil } - os.WriteFile(path, []byte(content), 0755) - fmt.Printf("vite: created new post at %s\n", path) + + fmt.Printf("error: %s already exists\n", path) return nil }