Skip to content

Commit a2955fe

Browse files
authored
Merge pull request #87 from Diomendius/bugfix
Fix file-not-found errors when handling broken symlinks
2 parents 2157499 + 60e54f0 commit a2955fe

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/filesystem.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ impl Filesystem for RealFilesystem {
110110
let link_state = get_file_state(link).context("get link state")?;
111111
trace!("Link state: {:#?}", link_state);
112112

113-
let source = real_path(source).context("get real path of source")?;
114-
Ok(compare_symlink(&source, source_state, link_state))
113+
compare_symlink(source, source_state, link_state)
115114
}
116115

117116
fn compare_template(&mut self, target: &Path, cache: &Path) -> Result<TemplateComparison> {
@@ -277,8 +276,7 @@ impl Filesystem for RealFilesystem {
277276
let source_state = get_file_state(source).context("get source state")?;
278277
let link_state = get_file_state(link).context("get link state")?;
279278

280-
let source = real_path(source).context("get real path of source")?;
281-
Ok(compare_symlink(&source, source_state, link_state))
279+
compare_symlink(source, source_state, link_state)
282280
}
283281

284282
fn compare_template(&mut self, target: &Path, cache: &Path) -> Result<TemplateComparison> {
@@ -293,7 +291,7 @@ impl Filesystem for RealFilesystem {
293291
}
294292

295293
fn remove_file(&mut self, path: &Path) -> Result<()> {
296-
let metadata = path.metadata().context("get metadata")?;
294+
let metadata = path.symlink_metadata().context("get metadata")?;
297295
let result = if metadata.is_dir() {
298296
std::fs::remove_dir_all(path)
299297
} else {
@@ -589,8 +587,7 @@ impl Filesystem for DryRunFilesystem {
589587
state
590588
};
591589

592-
let source = real_path(source).context("get real path of source")?;
593-
Ok(compare_symlink(&source, source_state, link_state))
590+
compare_symlink(source, source_state, link_state)
594591
}
595592

596593
fn compare_template(&mut self, target: &Path, cache: &Path) -> Result<TemplateComparison> {
@@ -760,11 +757,11 @@ fn compare_symlink(
760757
source_path: &Path,
761758
source_state: FileState,
762759
link_state: FileState,
763-
) -> SymlinkComparison {
764-
match (source_state, link_state) {
760+
) -> Result<SymlinkComparison> {
761+
Ok(match (source_state, link_state) {
765762
(FileState::Missing, FileState::SymbolicLink(_)) => SymlinkComparison::OnlyTargetExists,
766763
(_, FileState::SymbolicLink(t)) => {
767-
if t == source_path {
764+
if t == real_path(source_path).context("get real path of source")? {
768765
SymlinkComparison::Identical
769766
} else {
770767
SymlinkComparison::Changed
@@ -773,7 +770,7 @@ fn compare_symlink(
773770
(FileState::Missing, FileState::Missing) => SymlinkComparison::BothMissing,
774771
(_, FileState::Missing) => SymlinkComparison::OnlySourceExists,
775772
_ => SymlinkComparison::TargetNotSymlink,
776-
}
773+
})
777774
}
778775

779776
#[derive(Debug, PartialEq)]

0 commit comments

Comments
 (0)