Skip to content
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

fd cannot search files under a RAM disk #752

Closed
pgp opened this issue Mar 28, 2021 · 7 comments · Fixed by #811
Closed

fd cannot search files under a RAM disk #752

pgp opened this issue Mar 28, 2021 · 7 comments · Fixed by #811

Comments

@pgp
Copy link

pgp commented Mar 28, 2021

Describe the bug you encountered:

when performing search (e.g. fd somepattern) under a ramdisk (using ImDisk as RAM disk utility), the following error is returned immediately:

[fd error] Cannot retrieve current directory (has it been deleted?)

Instead, the builtin windows prompt command:
dir /S /P somepattern
works correctly.

What version of fd are you using?
8.2.1

Which operating system / distribution are you on?
Windows 8.1 x64

@pgp pgp added the bug label Mar 28, 2021
@sergeevabc
Copy link

Also, it does not work with virtual disks created by apps encrypting folders (e.g. cppcryptfs).

@sharkdp
Copy link
Owner

sharkdp commented Apr 3, 2021

Thank you for reporting this.

This is due to this check in main.rs:

    let current_directory = Path::new(".");
    if !filesystem::is_dir(current_directory) {
        return Err(anyhow!(
            "Could not retrieve current directory (has it been deleted?)."
        ));
    }

We probably shouldn't check whether . is a directory... just if it exists(?). Apparently on these special file systems, . is not a directory? Can someone confirm this?

@pgp
Copy link
Author

pgp commented Apr 4, 2021

I did a quick check using the os.stat command within python, and the st_mode integer is identical for folders under the RAM disk, and folders on the main hard drive. Also, the rest of the os.stat output does not present notable differences, so the issue might be located somewhere (or it could be due to a bad implementation of filesystem::is_dir)...

I'll try to run the filesystem::is_dir snippet under the two kinds of directories as well, and let you know.

@pgp
Copy link
Author

pgp commented Apr 4, 2021

Well, it seems that the culprit is the path.canonicalize().is_ok() part in the is_dir implementation, which returns false in the RAM disk case. The other check within the parenthesis (path.file_name().is_some()) returns false for both filesystems, at least when providing the current directory "."

@tavianator
Copy link
Collaborator

Python has run into very similar issues with ImDisk before: https://bugs.python.org/issue26658

I'm guessing that canonicalize() is trying to do the same thing as Python used to, i.e. figure out the drive letter associated with the mount point. That seems surprisingly aggressive to me -- I expect it to resolve symlinks, but not other junction/reparse points. Might be worth reporting as a Rust bug.

@bl-ue
Copy link

bl-ue commented May 30, 2021

Having the same issue. I'm using ImDisk for a virtual R:\ drive and fd can't do a thing in it.

@sharkdp sharkdp added the windows label Aug 8, 2021
sharkdp added a commit that referenced this issue Aug 8, 2021
This fixes a bug on Windows where `fd` could not be used on ram disks
and encrypted folders.

closes #752
@sharkdp
Copy link
Owner

sharkdp commented Aug 8, 2021

I took another look at this.

Related issues on the Rust tracker: rust-lang/rust#59117 (and rust-lang/rust#74327)

We might be able to use the normpath crate to fix this: https://docs.rs/normpath/0.3.0/normpath/trait.PathExt.html#tymethod.normalize

sharkdp added a commit that referenced this issue Aug 8, 2021
This fixes a bug on Windows where `fd` could not be used on ram disks
and encrypted folders.

closes #752
sharkdp added a commit that referenced this issue Aug 8, 2021
This fixes a bug on Windows where `fd` could not be used on ram disks
and encrypted folders.

closes #752
@sharkdp sharkdp added this to the fd 9.x milestone Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants