mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
Since Go 1.23, os.Lstat reports NTFS junctions as irregular files instead of symlinks (winsymlink, active for go 1.25 in go.mod). Every check that looked only at os.ModeSymlink therefore missed the junctions skillshare itself creates on Windows: linked skills could be treated as local folders, backed up, copied through, or left behind on prune. Detect links through utils.IsLinkMode, which also asks the OS about the reparse tag of irregular entries, and count only real symlinks and junctions as links so OneDrive placeholders and deduplicated files stay regular files. restore.go also used os.Stat for its link check, which follows the link and never matched. Refs #299
26 lines
780 B
Go
26 lines
780 B
Go
//go:build windows
|
|
|
|
package utils
|
|
|
|
import "syscall"
|
|
|
|
// ioReparseTagMountPoint is the reparse tag of a junction (IO_REPARSE_TAG_MOUNT_POINT).
|
|
const ioReparseTagMountPoint = 0xA0000003
|
|
|
|
// platformIsJunction reports whether path is a junction. Other reparse points,
|
|
// such as OneDrive placeholders or deduplicated files, are not links.
|
|
func platformIsJunction(path string) bool {
|
|
ptr, err := syscall.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
var data syscall.Win32finddata
|
|
h, err := syscall.FindFirstFile(ptr, &data)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
syscall.FindClose(h)
|
|
// For a reparse point, FindFirstFile reports its tag in Reserved0.
|
|
return data.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0 && data.Reserved0 == ioReparseTagMountPoint
|
|
}
|