File: mkdir_unix.go

package info (click to toggle)
golang-github-tonistiigi-fsutil 0.0~git20200331.f427cf1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 400 kB
  • sloc: makefile: 7
file content (32 lines) | stat: -rw-r--r-- 510 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// +build !windows

package fs

import (
	"time"

	"github.com/pkg/errors"
	"golang.org/x/sys/unix"
)

func fixRootDirectory(p string) string {
	return p
}

func Utimes(p string, tm *time.Time) error {
	if tm == nil {
		return nil
	}

	ts, err := unix.TimeToTimespec(*tm)
	if err != nil {
		return err
	}

	timespec := []unix.Timespec{ts, ts}
	if err := unix.UtimesNanoAt(unix.AT_FDCWD, p, timespec, unix.AT_SYMLINK_NOFOLLOW); err != nil {
		return errors.Wrapf(err, "failed to utime %s", p)
	}

	return nil
}