Skip to content

Commit bac08e0

Browse files
committed
Touch and TimE function
1 parent e0c7bb9 commit bac08e0

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

directory_filesystem.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func FClose(file *os.File) error {
116116
// fopen() binds a named resource, specified by filename, to a stream.
117117
// Mode : os.O_RDONLY | os.O_WRONLY | os.O_RDWR | os.O_APPEND | os.O_CREATE | os.O_EXCL | os.O_SYNC | os.O_TRUNC
118118
func FOpen(file string, mode int) (*os.File, error) {
119-
f, err := os.OpenFile(file, mode, 0644)
119+
f, err := os.OpenFile(file, mode|os.O_CREATE, 0644)
120120
if err != nil {
121121
return f,err
122122
}
@@ -376,6 +376,30 @@ func Stat(name string) (os.FileInfo, error) {
376376
return os.Stat(name)
377377
}
378378

379+
// Touch - Sets access and modification time of file
380+
// Original : https://www.php.net/manual/en/function.touch.php
381+
// Attempts to set the access and modification times of the file named in the filename parameter to the value given in time. Note that the access time is always modified, regardless of the number of parameters.
382+
// If the file does not exist, it will be created.
383+
func Touch(path string, t int64, at int64) bool {
384+
385+
_, err := FOpen(path,os.O_RDWR)
386+
if err != nil {
387+
log.Fatal(err)
388+
return false
389+
}
390+
391+
atim := time.Unix(at, 0)
392+
ttim := time.Unix(t, 0)
393+
394+
395+
if err := os.Chtimes(path,ttim,atim); err != nil {
396+
log.Fatal(err)
397+
return false
398+
}
399+
return true
400+
}
401+
402+
379403
// Unlink - Deletes a file.
380404
// Original : https://www.php.net/manual/en/function.unlink.php
381405
// Deletes filename. Similar to the Unix C unlink() function. An E_WARNING level error will be generated on failure.

utils.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"net/url"
55
"regexp"
66
"strings"
7+
"time"
78
"unicode/utf8"
89
)
910

@@ -48,4 +49,12 @@ func IsURL(str string) bool {
4849
return false
4950
}
5051
return rxURL.MatchString(str)
52+
}
53+
54+
// TimE - Return current Unix timestamp
55+
// Original : https://www.php.net/manual/en/function.time.php
56+
// Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
57+
func TimE() int64 {
58+
now := time.Now() // LocalTime
59+
return now.Unix()
5160
}

0 commit comments

Comments
 (0)