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

Add 'executable' file type #246

Closed
sharkdp opened this issue Feb 24, 2018 · 8 comments
Closed

Add 'executable' file type #246

sharkdp opened this issue Feb 24, 2018 · 8 comments

Comments

@sharkdp
Copy link
Owner

sharkdp commented Feb 24, 2018

Add a new executable/x filetype for --type/-t filtering that only shows files with the executable bit.

For Windows, we could either disable this feature completely or search for files with exe/bat/com/cmd/msi.. file extensions.

@sharkdp
Copy link
Owner Author

sharkdp commented Feb 24, 2018

Note: we already have an is_executable function in output.rs which could be re-used for this. Currently, it always returns false on Windows.

@PramodBisht
Copy link
Contributor

@sharkdp I want to pick this up if nobody is working on that.

@sharkdp
Copy link
Owner Author

sharkdp commented Feb 28, 2018

@PramodBisht Sounds great!

PramodBisht added a commit to PramodBisht/fd that referenced this issue Mar 8, 2018
Some implementation to search by filetype `executables`
@PramodBisht
Copy link
Contributor

PramodBisht commented Mar 9, 2018

@sharkdp in PramodBisht@8f796e3 commit I have added changeset to show only executable, but I could not get running, maybe I am missing something. Could you give me some pointer what I am doing wrong?

@sharkdp
Copy link
Owner Author

sharkdp commented Mar 12, 2018

These changes look good to me. How did you test this? Which OS are you on?

@PramodBisht
Copy link
Contributor

@sharkdp I am using ubuntu 14.04. I executed target/debug/fd --type executable <some executable file name> I could not see any file list.

@sharkdp
Copy link
Owner Author

sharkdp commented Mar 13, 2018

I just got a closer look. There is indeed a logical error in that code. Let's take a look at these lines in walk.rs:

if (entry_type.is_file() && !file_types.files)
    || (entry_type.is_dir() && !file_types.directories)
    || (entry_type.is_symlink() && !file_types.symlinks)
    || (output::is_executable(&entry.metadata().unwrap()) && !file_types.executables)
{
    return ignore::WalkState::Continue;
}

The way this works is that certain filesystem entries are skipped if one (or more) of the statements like entry_type.is_file() && !file_types.files are fulfilled.

If you specify --type executable (and no other --type arguments), then currently file_types.executables = true but all other file_types.* fields are set to false. This means that all files, directories and symlinks will be skipped (whether or not they are executable).

It looks like the executable flag should actually work a little different than the other three. What we want to see is files that are executable (directories and symlinks also have an executable flag, but we are typically not that interested in them). So I think we should rename file_types.executables to file_types.executables_only and set both files and executables_only to true if --type executable has been specified. Then, we can modify the above to:

if (entry_type.is_file() && !file_types.files)
    || (entry_type.is_dir() && !file_types.directories)
    || (entry_type.is_symlink() && !file_types.symlinks)
    || (!output::is_executable(&entry.metadata().unwrap()) && file_types.executables_only)
{
    return ignore::WalkState::Continue;
}

This would also allow us to specify --type executable in combination with --type directory and --type symlink.

@sharkdp sharkdp added this to the 7.0 milestone Mar 13, 2018
PramodBisht added a commit to PramodBisht/fd that referenced this issue Mar 25, 2018
Some implementation to search by filetype `executables`
@PramodBisht PramodBisht mentioned this issue Mar 25, 2018
sharkdp pushed a commit that referenced this issue Mar 25, 2018
Some implementation to search by filetype `executables`
@sharkdp sharkdp closed this as completed Mar 25, 2018
@sharkdp
Copy link
Owner Author

sharkdp commented Mar 26, 2018

This is part of fd v7.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants