-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from joyme123/fix-windows
fix: fix build on windows
- Loading branch information
Showing
4 changed files
with
57 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//go:build !windows && !plan9 | ||
// +build !windows,!plan9 | ||
|
||
package cache | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func getFileID(filename string) (FileID, time.Time, error) { | ||
fi, err := os.Stat(filename) | ||
if err != nil { | ||
return FileID{}, time.Time{}, err | ||
} | ||
stat := fi.Sys().(*syscall.Stat_t) | ||
return FileID{ | ||
device: uint64(stat.Dev), // (int32 on darwin, uint64 on linux) | ||
inode: stat.Ino, | ||
}, fi.ModTime(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package cache | ||
|
||
import ( | ||
"syscall" | ||
"time" | ||
) | ||
|
||
// Note: it may be convenient to have this helper return fs.FileInfo, but | ||
// implementing this is actually quite involved on Windows. Since we only | ||
// currently use mtime, keep it simple. | ||
func getFileID(filename string) (FileID, time.Time, error) { | ||
filename16, err := syscall.UTF16PtrFromString(filename) | ||
if err != nil { | ||
return FileID{}, time.Time{}, err | ||
} | ||
h, err := syscall.CreateFile(filename16, 0, 0, nil, syscall.OPEN_EXISTING, uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS), 0) | ||
if err != nil { | ||
return FileID{}, time.Time{}, err | ||
} | ||
defer syscall.CloseHandle(h) | ||
var i syscall.ByHandleFileInformation | ||
if err := syscall.GetFileInformationByHandle(h, &i); err != nil { | ||
return FileID{}, time.Time{}, err | ||
} | ||
mtime := time.Unix(0, i.LastWriteTime.Nanoseconds()) | ||
return FileID{ | ||
device: uint64(i.VolumeSerialNumber), | ||
inode: uint64(i.FileIndexHigh)<<32 | uint64(i.FileIndexLow), | ||
}, mtime, nil | ||
} |