Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
36 lines
900 B
Go
36 lines
900 B
Go
//go:build unix
|
|
|
|
package overlayfs
|
|
|
|
import (
|
|
"errors"
|
|
"io/fs"
|
|
"os"
|
|
"path/filepath"
|
|
"syscall"
|
|
"time"
|
|
)
|
|
|
|
func (over Overlayfs) Utimens(name string, access, modification time.Time) error {
|
|
if !over.isPathInsideOverlay(name) {
|
|
return &fs.PathError{Op: "utimens", Path: name, Err: fs.ErrInvalid}
|
|
} else if !over.isRW() {
|
|
return &fs.PathError{Op: "utimens", Path: name, Err: fs.ErrPermission}
|
|
}
|
|
|
|
for layer := range over.Lower {
|
|
if _, err := os.Stat(filepath.Join(over.Lower[layer], name)); err == nil {
|
|
// Clone file to upper if not exists
|
|
if err := over.copyFileToUpperIfAbsent(name); err != nil && !errors.Is(err, fs.ErrNotExist) {
|
|
return rewriteName(name, err)
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
return rewriteName(name, syscall.Utimes(filepath.Join(over.Upper, name), []syscall.Timeval{
|
|
syscall.NsecToTimeval(access.UnixNano()),
|
|
syscall.NsecToTimeval(modification.UnixNano()),
|
|
}))
|
|
}
|