windows 符号链接和目录之间的区别
Difference between windows symbolic links and directories
我 运行 在尝试区分 windows 符号链接和目录时遇到了 Go 问题。
我用谷歌搜索,我能找到的是:
https://github.com/golang/go/issues/3498#issuecomment-142810957
不幸的是,它已经关闭并且没有被处理。
所以我的问题是,有什么解决方法吗?我尝试使用符号链接列出路径,但它 returning 与在空目录上 return 相同。
使用 python 我可以做这样的事情:
def test(dir):
try:
os.chdir(dir)
except Exception as e:
if "[Error 2]" in str(e):
return False
else:
return True
是否有任何 bash 命令可以用来从 go 调用来检测它?
我运行没主意:(
我看到的唯一测试(我刚刚在 Windows 上用 go 1.5.1 测试了它)在 os/os_test.go
:
fromstat, err = Lstat(from)
if err != nil {
t.Fatalf("lstat %q failed: %v", from, err)
}
if fromstat.Mode()&ModeSymlink == 0 {
t.Fatalf("symlink %q, %q did not create symlink", to, from)
}
它使用os/#Lstat
:
Lstat
returns a FileInfo
describing the named file.
If the file is a symbolic link, the returned FileInfo
describes the symbolic link. Lstat
makes no attempt to follow the link.
If there is an error, it will be of type *PathError
.
你还可以获得os.Stat()
of the same folder, and then call os.Samefile()
(as in this test):
if !SameFile(tostat, fromstat) {
t.Errorf("symlink %q, %q did not create symlink", to, from)
}
我 运行 在尝试区分 windows 符号链接和目录时遇到了 Go 问题。 我用谷歌搜索,我能找到的是: https://github.com/golang/go/issues/3498#issuecomment-142810957
不幸的是,它已经关闭并且没有被处理。
所以我的问题是,有什么解决方法吗?我尝试使用符号链接列出路径,但它 returning 与在空目录上 return 相同。
使用 python 我可以做这样的事情:
def test(dir):
try:
os.chdir(dir)
except Exception as e:
if "[Error 2]" in str(e):
return False
else:
return True
是否有任何 bash 命令可以用来从 go 调用来检测它?
我运行没主意:(
我看到的唯一测试(我刚刚在 Windows 上用 go 1.5.1 测试了它)在 os/os_test.go
:
fromstat, err = Lstat(from)
if err != nil {
t.Fatalf("lstat %q failed: %v", from, err)
}
if fromstat.Mode()&ModeSymlink == 0 {
t.Fatalf("symlink %q, %q did not create symlink", to, from)
}
它使用os/#Lstat
:
Lstat
returns aFileInfo
describing the named file.
If the file is a symbolic link, the returnedFileInfo
describes the symbolic link.Lstat
makes no attempt to follow the link.
If there is an error, it will be of type*PathError
.
你还可以获得os.Stat()
of the same folder, and then call os.Samefile()
(as in this test):
if !SameFile(tostat, fromstat) {
t.Errorf("symlink %q, %q did not create symlink", to, from)
}