Skip to content

Commit

Permalink
Reduce code around path reorienting and add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
ariasuni committed Sep 1, 2021
1 parent aff35a1 commit 144adc8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 27 deletions.
3 changes: 2 additions & 1 deletion devtools/dev-create-test-filesystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ mkdir -p "$TEST_ROOT/git3"
cd "$TEST_ROOT/git3"
git init >/dev/null

# Create a symbolic link pointing to a non-existing file
# Create symbolic links pointing to non-existing files
ln -s aaa/aaa/a b
ln -s /aaa

# This normally fails with:
find "$TEST_ROOT/git3" -exec touch {} -h -t $FIXED_DATE \;
Expand Down
10 changes: 3 additions & 7 deletions src/fs/feature/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,9 @@ impl Git {
/// you’d ask a repo about “./README.md” but it only knows about
/// “/vagrant/README.md”, prefixed by the workdir.
fn reorient(path: &Path) -> PathBuf {
use std::env::current_dir;

// TODO: I’m not 100% on this func tbh
let path = match current_dir() {
Err(_) => Path::new(".").join(&path),
Ok(dir) => dir.join(&path),
};
let path = std::env::current_dir()
.unwrap()
.with_file_name(&path);

path.canonicalize().unwrap_or(path)
}
Expand Down
20 changes: 1 addition & 19 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,6 @@ impl<'dir> File<'dir> {
}


/// Re-prefixes the path pointed to by this file, if it’s a symlink, to
/// make it an absolute path that can be accessed from whichever
/// directory exa is being run from.
fn reorient_target_path(&self, path: &Path) -> PathBuf {
if path.is_absolute() {
path.to_path_buf()
}
else if let Some(dir) = self.parent_dir {
dir.join(&*path)
}
else if let Some(parent) = self.path.parent() {
parent.join(&*path)
}
else {
self.path.join(&*path)
}
}

/// Again assuming this file is a symlink, follows that link and returns
/// the result of following it.
///
Expand All @@ -245,7 +227,7 @@ impl<'dir> File<'dir> {
Err(e) => return FileTarget::Err(e),
};

let absolute_path = self.reorient_target_path(&path);
let absolute_path = self.path.with_file_name(&path);

// Use plain `metadata` instead of `symlink_metadata` - we *want* to
// follow links.
Expand Down
1 change: 1 addition & 0 deletions xtests/outputs/git3_long.ansitxt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lrwxrwxrwx 4 cassowary  1 Jan 12:34 -N aaa -> /aaa
lrwxrwxrwx 9 cassowary  1 Jan 12:34 -N b -> aaa/aaa/a

0 comments on commit 144adc8

Please sign in to comment.