func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { dir.Dev = stat.Dev dir.Ino = uint64(stat.Ino) dir.Nlink = uint64(stat.Nlink) dir.Mode = stat.Mode dir.Uid = stat.Uid dir.Gid = stat.Gid dir.Rdev = stat.Rdev dir.Size = uint64(stat.Size) dir.Blksize = uint64(stat.Blksize) dir.Blocks = uint64(stat.Blocks) dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim)) dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim)) dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim)) for i := len(name) - 1; i >= 0; i-- { if name[i] == '/' { name = name[i+1 : len(name)] break } } dir.Name = name if isSymlink(lstat) && !isSymlink(stat) { dir.FollowedSymlink = true } return dir }
func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo { fi.Dev = uint64(stat.Dev) fi.Ino = stat.Ino fi.Nlink = uint64(stat.Nlink) fi.Mode = uint32(stat.Mode) fi.Uid = int(stat.Uid) fi.Gid = int(stat.Gid) fi.Rdev = uint64(stat.Rdev) fi.Size = stat.Size fi.Blksize = int64(stat.Blksize) fi.Blocks = stat.Blocks fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec) fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec) fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec) for i := len(name) - 1; i >= 0; i-- { if name[i] == '/' { name = name[i+1:] break } } fi.Name = name if isSymlink(lstat) && !isSymlink(stat) { fi.FollowedSymlink = true } return fi }
func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo { fi.Dev = uint64(stat.Dev) fi.Ino = stat.Ino fi.Nlink = uint64(stat.Nlink) fi.Mode = uint32(stat.Mode) fi.Uid = int(stat.Uid) fi.Gid = int(stat.Gid) fi.Rdev = uint64(stat.Rdev) fi.Size = stat.Size fi.Blksize = int64(stat.Blksize) fi.Blocks = stat.Blocks fi.Atime_ns = syscall.TimespecToNsec(stat.Atimespec) fi.Mtime_ns = syscall.TimespecToNsec(stat.Mtimespec) fi.Ctime_ns = syscall.TimespecToNsec(stat.Ctimespec) fi.Name = basename(name) if isSymlink(lstat) && !isSymlink(stat) { fi.FollowedSymlink = true } return fi }
//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 { ctimespec := syscall.NsecToTimespec(ctime.UnixNano()) pathp, e := syscall.UTF16PtrFromString(path) if e != nil { return e } h, e := syscall.CreateFile(pathp, syscall.FILE_WRITE_ATTRIBUTES, syscall.FILE_SHARE_WRITE, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0) if e != nil { return e } defer syscall.Close(h) c := syscall.NsecToFiletime(syscall.TimespecToNsec(ctimespec)) return syscall.SetFileTime(h, &c, nil, nil) }