mirror of
https://github.com/eza-community/eza
synced 2024-10-02 22:23:45 +00:00
fix(fs): Fix absolute_path() for broken symlinks
This commit is contained in:
parent
4611e37a7f
commit
4799a49249
|
@ -343,7 +343,19 @@ impl<'dir> File<'dir> {
|
|||
/// Determine the full path resolving all symbolic links on demand.
|
||||
pub fn absolute_path(&self) -> Option<&PathBuf> {
|
||||
self.absolute_path
|
||||
.get_or_init(|| std::fs::canonicalize(&self.path).ok())
|
||||
.get_or_init(|| {
|
||||
if self.link_target().is_broken() {
|
||||
// workaround for broken symlinks to get absolute path for parent and then
|
||||
// append name of file; std::fs::canonicalize requires all path components
|
||||
// (including the last one) to exist
|
||||
self.path
|
||||
.parent()
|
||||
.and_then(|parent| std::fs::canonicalize(parent).ok())
|
||||
.map(|p| p.join(self.name.clone()))
|
||||
} else {
|
||||
std::fs::canonicalize(&self.path).ok()
|
||||
}
|
||||
})
|
||||
.as_ref()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue