-
-
Notifications
You must be signed in to change notification settings - Fork 817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a uniform output format for searching ../ #113
Conversation
Ouch, now rebased after |
@sharkdp Could you figure out what happened here: https://ci.appveyor.com/project/sharkdp/fd/build/1.0.108/job/agyctswxi2ymut4m#L202 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some minor nitpicks as comments.
src/output.rs
Outdated
@@ -11,7 +11,11 @@ use std::os::unix::fs::PermissionsExt; | |||
use ansi_term; | |||
|
|||
pub fn print_entry(base: &Path, entry: &PathBuf, config: &FdOptions) { | |||
let path_full = base.join(entry); | |||
let path_full = if *entry != PathBuf::new() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider if !entry.as_os_str().is_empty()
to avoid the allocation.
tests/tests.rs
Outdated
@@ -4,6 +4,21 @@ mod testenv; | |||
|
|||
use testenv::TestEnv; | |||
|
|||
fn get_absolute_root_path(env: &TestEnv) -> String { | |||
let path = (*env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to dereference env
here. Rust does it automatically.
tests/tests.rs
Outdated
te.assert_output_subdirectory( | ||
&abs_path, | ||
&[ | ||
"--absolute-path", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag is not needed, will be removed.
Not sure ... does Windows treat |
Windows can work with I think the problem is that symlinks work differently on Windows. On Unix, a symlink I'm not certain if or how we should fix this. In my experience symlinks are still very rarely used in Windows land, so personally I wouldn't bother too much with this (i.e. disable the test on Windows or special case it). |
Thanks, I didn't know that.
👍, in particular if we can add your explanation above as a comment why it's disabled/special-cased on Windows. |
Playing around with this, I've noticed the following (I'm inside a test folder, in the
|
Building on AppVeyor is really slow, can you enable cache for the "target" directory?
|
Corrected:
|
@iology Nice! Do you think there is anything we can do about #113 (comment) ? |
It should be fixed, but you can try to create more complicated examples. Also please add/amend comments in the code if you see fit. Must have a nice holidy after this tiresome work. :P |
Err(_) => error("Error: could not get current directory."), | ||
}; | ||
let current_dir = current_dir_buf.as_path(); | ||
let current_dir = Path::new("."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this?
The detection of the current directory being missing does not seem to work anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it seems that .is_dir() doesn't really check the existence of path. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Path::exists
helps? Does this have to be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.exists() doesn't help too, on both stable&nightly branches. Path::new("") is ok, but "." and ".." are not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, "" doesn't mean current directory. I will ask the rust team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was wrong with the old way (env::current_dir
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
env::current_dir() does check the existence. The returned path is resolved, so its value is used only when we don't have an absolute path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Err(_) = env::current_dir()
can help, but for root_dir, user still can pass in "." or "..". I hope there is an elegant way to check their existence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm not sure if we should care the existence of "." and "..". Just let it crash?
}; | ||
|
||
if path_display == PathDisplay::Absolute && root_dir_buf.is_relative() { | ||
root_dir_buf = fshelper::absolute_path(root_dir_buf.as_path()).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid using unwrap
here:
> fd -a non/existing/relative/path
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 2, message: "No such file or directory" } }', /checkout/src/libcore/result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to add the pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are absolutely right 😄. So unwrap
was only called because the current directory did not exist (the issue above).
@@ -4,6 +4,20 @@ mod testenv; | |||
|
|||
use testenv::TestEnv; | |||
|
|||
fn get_absolute_root_path(env: &TestEnv) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you very much! Very nice work. |
* Fix path check * Fix full path matching * Allow more simple driver names in Windows tests * Factor out special is_dir() check for "." and ".."
closes #107, fixes #82 by the way (Yeah, I don't want to split this patch.)