mirror of
https://github.com/mudler/luet.git
synced 2025-09-01 07:09:13 +00:00
Add Touch file helper
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
copy "github.com/otiai10/copy"
|
copy "github.com/otiai10/copy"
|
||||||
)
|
)
|
||||||
@@ -39,6 +40,25 @@ func ListDir(dir string) ([]string, error) {
|
|||||||
return content, err
|
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.
|
// Exists reports whether the named file or directory exists.
|
||||||
func Exists(name string) bool {
|
func Exists(name string) bool {
|
||||||
if _, err := os.Stat(name); err != nil {
|
if _, err := os.Stat(name); err != nil {
|
||||||
|
Reference in New Issue
Block a user