libgit2 / git2go:如何获取Blob的文件模式?
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.
我正在使用 libgit2 ( git2go - godoc.org上的文档),我想知道是否有可能获得Blob的文件模式(例如“ 100644”)。 p>
背景:我想解析符号引用,并且似乎符号链接的文件模式为 120000 code>,并且符号链接的内容是(相对 )我想获取的原始文件的路径。 p>
div>
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.
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.