pub struct Meta { /* private fields */ }Expand description
What identification needs to know about a path besides its name: its
FileKind and whether it is executable.
Build it from fs::Metadata (Meta::from_metadata), from a git index
mode without any system call (Meta::from_git_mode), or by hand.
Implementations§
Source§impl Meta
impl Meta
Sourcepub const fn new(kind: FileKind, executable: bool) -> Self
pub const fn new(kind: FileKind, executable: bool) -> Self
A meta with the given kind and executable flag.
Sourcepub const fn is_executable(self) -> bool
pub const fn is_executable(self) -> bool
Whether the entry is executable (only meaningful for regular files
and FileKind::Other).
Sourcepub const fn with_executable(self, executable: bool) -> Self
pub const fn with_executable(self, executable: bool) -> Self
The same meta with a different executable flag.
Sourcepub fn from_metadata(metadata: &Metadata, policy: ExecPolicy) -> Self
pub fn from_metadata(metadata: &Metadata, policy: ExecPolicy) -> Self
From lstat metadata (fs::symlink_metadata); executability is
decided by policy for regular files and FileKind::Other.
Sourcepub const fn from_git_mode(mode: u32) -> Option<Self>
pub const fn from_git_mode(mode: u32) -> Option<Self>
From a git index / tree mode, with git’s own executable bit:
| mode | meta |
|---|---|
100644 (any 100xxx without the owner x bit) | regular file |
100755 (any 100xxx with the owner x bit) | executable regular file |
120000 | symlink |
160000 (gitlink / submodule), 040000 (tree) | directory |
| anything else | None |
This needs no system call. It matches what identify would see on a
checkout where the work tree agrees with the index (e.g. after
pre-commit stashed unstaged changes) on Unix with
core.fileMode=true and core.symlinks=true. On Windows identify
considers every file executable; use Meta::from_git_mode_with
with ExecPolicy::PythonCompat to reproduce that.
§Symlinks: do not trust 120000 with core.symlinks=false
120000 says the index holds a symlink. With core.symlinks=false
(the usual configuration on Windows, and set automatically on file
systems without symlinks) git checks it out as a regular file that
contains the target path, which identify tags file, text and
executable on Windows. On Windows, or whenever core.symlinks is
false, lstat such entries instead (tags_from_path or
tags_from_metadata).
use file_identify::{FileKind, Meta};
assert_eq!(Meta::from_git_mode(0o100755), Some(Meta::regular(true)));
assert_eq!(Meta::from_git_mode(0o120000).map(Meta::kind), Some(FileKind::Symlink));
assert_eq!(Meta::from_git_mode(0), None);Sourcepub fn from_git_mode_with(mode: u32, policy: ExecPolicy) -> Option<Self>
pub fn from_git_mode_with(mode: u32, policy: ExecPolicy) -> Option<Self>
Like Meta::from_git_mode, with platform executable semantics:
ExecPolicy::PythonCompat on Windows marks every regular file
executable (as identify does); otherwise git’s bit is used.
A 120000 entry still gives FileKind::Symlink: on Windows a
checkout usually has a regular file there (core.symlinks=false), so
lstat those entries instead; see Meta::from_git_mode.