mirror of
https://github.com/mudler/luet.git
synced 2025-08-29 20:23:17 +00:00
Add Touch file helper
This commit is contained in:
parent
32cf132a0c
commit
eb56956c65
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user