如何在Go中检测损坏的符号链接?

huangapple go评论80阅读模式
英文:

How to detect broken symlinks in Go?

问题

我尝试使用ff, _ := os.Open("Filename")打开文件,然后运行ffi, _ := ff.Stat()

这是我能找到的最接近提供任何细节的方法,但似乎没有遵循符号链接。

我真正想做的是从符号链接中提取原始文件名(该文件已被删除)。

我在Linux机器上。

英文:

I have tried opening the file with ff, _ := os.Open("Filename") and then running ffi, _ := ff.Stat().

Which is the closest thing I could find that provides any details, but that doesn't seem to be following the symlinks.

What I'm really trying to do is extract the original file name (which is deleted) from the symlink.

I'm on a Linux machine.

答案1

得分: 3

os.Readlink(filename)就可以了。

英文:

os.Readlink(filename) does it.

huangapple
  • 本文由 发表于 2011年12月3日 07:16:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/8363885.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定