libgit2 / git2go:如何获取 blob 的文件模式?

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

libgit2 / git2go: How to get file mode of a blob?

问题

我正在使用libgit2的Go绑定(git2go - godoc.org上的文档),我想知道是否可以获取blob的文件模式(例如"100644")。

背景:我想解析符号引用,似乎符号链接的文件模式是120000,而符号链接的内容是原始文件的(相对)路径,我想获取这个路径。

英文:

I am using the Go bindings of libgit2 (git2go - documentation on godoc.org) and I wonder if it's possible to get the file mode (such as "100644") of a blob.

Background: I'd like to resolve symbolic references and it seems that symbolic links have a file mode of 120000 and the contents of the symlink is the (relative) path of the original which I'd like to get.

答案1

得分: 4

我刚刚提交了一个修改,将Filemode条目添加到结构体中。我不太确定为什么一开始添加时会被忽略。

一旦你有了var entry TreeEntry,你可以使用entry.Filemode来获取模式。还有一些预定义的常量,这样你就不必使用大的八进制数或Unix函数来操作了。对于符号链接,可以使用git.FilemodeLink

你应该记住,这是关于模式和条目类型的,因为git并不以这种方式存储权限,所以你不应该从这些值中读取任何与权限相关的信息。

英文:

I've just pushed a commit which adds the Filemode entry to the struct. I'm not quite sure why it was missed when first added.

Once you have your var entry TreeEntry you can use entry.Filemode to get the mode. There are also a few constants defined so you don't have to play with large octal numbers or the unix functions. For symlinks, it'd be git.FilemodeLink.

You should remember that this is about mode and type of entry, as git doesn't store permissions as such and you shouldn't read anything permission-wise into these values.

答案2

得分: 0

我不确定是否正确理解了你的问题。无论如何,也许你正在寻找的是:

func Lstat(name string) (fi FileInfo, err error)

Lstat返回描述指定文件的FileInfo。如果文件是一个符号链接,返回的FileInfo描述的是符号链接本身。Lstat不会尝试跟踪链接。如果发生错误,错误类型将为*PathError。

func Stat(name string) (fi FileInfo, err error)

Stat返回描述指定文件的FileInfo。如果发生错误,错误类型将为*PathError。

英文:

I'm far from sure if I understand your question correctly. Anyway, maybe you're looking for:

func Lstat(name string) (fi FileInfo, err error)

> 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.

func Stat(name string) (fi FileInfo, err error)

> Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

huangapple
  • 本文由 发表于 2013年9月9日 15:06:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/18693055.html
匿名

发表评论

匿名网友

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

确定