Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top