Files
skillshare/internal/utils/link_windows.go
T
Willie 97499ebcc4 fix: recognise Windows junctions wherever links are detected
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
2026-09-28 13:53:16 +08:00

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
}