Skip to content

Commit

Permalink
Fix bug reading root symlink.
Browse files Browse the repository at this point in the history
When give an explicit file path on the command line like `foo` where `foo`
is a symlink, ripgrep should follow it even if `-L` isn't set. This is
consistent with the behavior of `foo/`.

Fixes #256
  • Loading branch information
BurntSushi committed Dec 6, 2016
1 parent 160f048 commit 7282706
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 37 deletions.
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions ignore/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,6 @@ impl DirEntryRaw {
depth: depth,
})
}

fn from_path(depth: usize, pb: PathBuf) -> Result<DirEntryRaw, Error> {
let md = try!(fs::symlink_metadata(&pb).map_err(|err| {
Error::Io(err).with_path(&pb)
}));
Ok(DirEntryRaw {
path: pb,
ty: md.file_type(),
follow_link: false,
depth: depth,
})
}
}

/// WalkBuilder builds a recursive directory iterator.
Expand Down Expand Up @@ -756,7 +744,7 @@ impl WalkParallel {
if path == Path::new("-") {
DirEntry::new_stdin()
} else {
match DirEntryRaw::from_path(0, path) {
match DirEntryRaw::from_link(0, path) {
Ok(dent) => DirEntry::new_raw(dent, None),
Err(err) => {
if f(Err(err)).is_quit() {
Expand Down
23 changes: 23 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,29 @@ clean!(regression_251, "привет", ".", |wd: WorkDir, mut cmd: Command| {
assert_eq!(lines, "foo:привет\nfoo:Привет\nfoo:ПрИвЕт\n");
});

// See: https://github.com/BurntSushi/ripgrep/issues/256
#[cfg(not(windows))]
clean!(regression_256, "test", "foo", |wd: WorkDir, mut cmd: Command| {
wd.create_dir("bar");
wd.create("bar/baz", "test");
wd.link_dir("bar", "foo");

let lines: String = wd.stdout(&mut cmd);
assert_eq!(lines, "foo/baz:test\n");
});

// See: https://github.com/BurntSushi/ripgrep/issues/256
#[cfg(not(windows))]
clean!(regression_256_j1, "test", "foo", |wd: WorkDir, mut cmd: Command| {
wd.create_dir("bar");
wd.create("bar/baz", "test");
wd.link_dir("bar", "foo");
cmd.arg("-j1");

let lines: String = wd.stdout(&mut cmd);
assert_eq!(lines, "foo/baz:test\n");
});

// See: https://github.com/BurntSushi/ripgrep/issues/7
sherlock!(feature_7, "-fpat", "sherlock", |wd: WorkDir, mut cmd: Command| {
wd.create("pat", "Sherlock\nHolmes");
Expand Down

0 comments on commit 7282706

Please sign in to comment.