diff --git a/pkg/helpers/file.go b/pkg/helpers/file.go index 00b0fa34..c2575a2d 100644 --- a/pkg/helpers/file.go +++ b/pkg/helpers/file.go @@ -19,6 +19,7 @@ import ( "io/ioutil" "os" "path/filepath" + "time" copy "github.com/otiai10/copy" ) @@ -39,6 +40,25 @@ func ListDir(dir string) ([]string, error) { return content, err } +// Touch creates an empty file +func Touch(f string) error { + _, err := os.Stat(f) + if os.IsNotExist(err) { + file, err := os.Create(f) + if err != nil { + return err + } + defer file.Close() + } else { + currentTime := time.Now().Local() + err = os.Chtimes(f, currentTime, currentTime) + if err != nil { + return err + } + } + return nil +} + // Exists reports whether the named file or directory exists. func Exists(name string) bool { if _, err := os.Stat(name); err != nil {