A FileMode represents the kind of tree entries used by git. It resembles regular file systems modes, although FileModes are considerably simpler (there are not so many), and there are some, like Submodule that has no file system equivalent.
const ( // Empty is used as the FileMode of tree elements when comparing // trees in the following situations: // // - the mode of tree elements before their creation. - the mode of // tree elements after their deletion. - the mode of unmerged // elements when checking the index. // // Empty has no file system equivalent. As Empty is the zero value // of FileMode, it is also returned by New and // NewFromOsNewFromOSFileMode along with an error, when they fail. Empty FileMode = 0 // Dir represent a Directory. Dir FileMode = 0040000 // Regular represent non-executable files. Please note this is not // the same as golang regular files, which include executable files. Regular FileMode = 0100644 // Deprecated represent non-executable files with the group writable // bit set. This mode was supported by the first versions of git, // but it has been deprecated nowadays. This library uses them // internally, so you can read old packfiles, but will treat them as // Regulars when interfacing with the outside world. This is the // standard git behaviour. Deprecated FileMode = 0100664 // Executable represents executable files. Executable FileMode = 0100755 // Symlink represents symbolic links to files. FileMode = 0120000 // Submodule represents git submodules. This mode has no file system // equivalent. Submodule FileMode = 0160000 )
New takes the octal string representation of a FileMode and returns the FileMode and a nil error. If the string can not be parsed to a 32 bit unsigned octal number, it returns Empty and the parsing error.
Example: "40000" means Dir, "100644" means Regular.
Please note this function does not check if the returned FileMode is valid in git or if it is malformed. For instance, "1" will return the malformed FileMode(1) and a nil error.
NewFromOSFileMode returns the FileMode used by git to represent the provided file system modes and a nil error on success. If the file system mode cannot be mapped to any valid git mode (as with sockets or named pipes), it will return Empty and an error.
Note that some git modes cannot be generated from os.FileModes, like Deprecated and Submodule; while Empty will be returned, along with an error, only when the method fails.
Bytes return a slice of 4 bytes with the mode in little endian encoding.
IsFile returns if the FileMode represents that of a file, this is, Regular, Deprecated, Executable or Link.
IsMalformed returns if the FileMode should not appear in a git packfile, this is: Empty and any other mode not mentioned as a constant in this package.
IsRegular returns if the FileMode represents that of a regular file, this is, either Regular or Deprecated. Please note that Executable are not regular even though in the UNIX tradition, they usually are: See the IsFile method.
String returns the FileMode as a string in the standatd git format, this is, an octal number padded with ceros to 7 digits. Malformed modes are printed in that same format, for easier debugging.
Example: Regular is "0100644", Empty is "0000000".
ToOSFileMode returns the os.FileMode to be used when creating file system elements with the given git mode and a nil error on success.
When the provided mode cannot be mapped to a valid file system mode (e.g. Submodule) it returns os.FileMode(0) and an error.
The returned file mode does not take into account the umask.