-
Notifications
You must be signed in to change notification settings - Fork 1
/
fs_windows.go
53 lines (48 loc) · 1.11 KB
/
fs_windows.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package logx
import (
"os"
"syscall"
"unsafe"
)
func isLinkFile(filename string) (name string, ok bool) {
fi, err := os.Lstat(filename)
if err != nil {
return
}
if fi.Mode()&os.ModeSymlink != 0 {
name, err = os.Readlink(filename)
if err != nil {
return
}
return name, true
} else {
return
}
return
}
//https://gist.github.com/bradleypeabody/10572010
var (
k32 = syscall.MustLoadDLL("kernel32.dll")
createSymbolicLink = k32.MustFindProc("CreateSymbolicLinkW")
)
func createLinkFile(oldpath, newpath string) error {
os.Remove(oldpath)
st, err := os.Stat(oldpath)
if err != nil {
return err
}
linkType := 0
if st.Mode() == os.ModeDir {
linkType = 1
}
_, _, callErr := createSymbolicLink.Call(
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(newpath))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(oldpath))),
uintptr(linkType),
)
errno, _ := callErr.(syscall.Errno)
if errno != 0 {
return callErr
}
return nil
}