summaryrefslogtreecommitdiff
path: root/pkg/system/chtimes_windows.go
blob: ab478f5c38e2de04acdd2d80e41e263a723ea016 (plain)
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
package system // import "github.com/docker/docker/pkg/system"

import (
	"time"

	"golang.org/x/sys/windows"
)

// setCTime will set the create time on a file. On Windows, this requires
// calling SetFileTime and explicitly including the create time.
func setCTime(path string, ctime time.Time) error {
	pathp, err := windows.UTF16PtrFromString(path)
	if err != nil {
		return err
	}
	h, err := windows.CreateFile(pathp,
		windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil,
		windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
	if err != nil {
		return err
	}
	defer windows.Close(h)
	c := windows.NsecToFiletime(ctime.UnixNano())
	return windows.SetFileTime(h, &c, nil, nil)
}