diff --git a/internal/util/files.go b/internal/util/files.go new file mode 100644 index 0000000..d656624 --- /dev/null +++ b/internal/util/files.go @@ -0,0 +1,18 @@ +package util + +import "os" + +// RemoveFileIfExists removes filename if exists, or does nothing if the file +// is not there. Returns an error, if it occurred during deletion. +func RemoveFileIfExists(filename string) error { + _, err := os.Stat(filename) + if err != nil { + if !os.IsNotExist(err) { + return err + } + // no db file + return nil + } + + return os.Remove(filename) +}