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

Restricting search to starting filesystem of all paths #349

Closed
wavexx opened this issue Jan 24, 2024 · 6 comments
Closed

Restricting search to starting filesystem of all paths #349

wavexx opened this issue Jan 24, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@wavexx
Copy link

wavexx commented Jan 24, 2024

I'd like to always restrict the search to the filesystems of all paths which are given on the command line during interactive usage, as find -xdev does. As a common example:

ug pattern /var

should search inside the filesystem of /var, but exclude any other fs (such as a nested tmpfs). The --include-fs requires doubling all the arguments, which doesn't really work well with shell aliases or functions. For example, if I give two starting paths on two filesystems, it's generally implied I want both filesystems to be included:

ug pattern /fs1 /fs2

which would require --include-fs=/fs1,/fs2 or two extra args. The suggested --include-fs=. is not really a good substitute for this behavior, since very often $CWD has nothing to do with the searched paths.

@genivia-inc genivia-inc added the enhancement New feature or request label Jan 24, 2024
@genivia-inc
Copy link
Member

Yes, I agree that this is a valid use case to only recursively search the specified targets without descending into other FS. Like find -x, this is something we can do.

The only question is whether we need yet another long option for this. Because we have two related options --include-fs= and --exclude-fs= we may want to use one of them for this feature, for example when no mount argument is specified. So perhaps --exclude-fs without an argument is suitable for this feature? Since find -x or find -xdev pronounce as "ex", it might be a reasonable choice?

@wavexx
Copy link
Author

wavexx commented Jan 24, 2024

Seems reasonable, and I agree that avoiding another flag is a good thing™

@genivia-inc
Copy link
Member

genivia-inc commented Jan 25, 2024

I've implemented the new feature in my dev version to try it out.

So you can use --exclude-fs or --exclude-fs= without MOUNT points.

For the help info and man page, I'm considering the following update:

    --exclude-fs=MOUNTS
            Exclude file systems specified by MOUNTS from recursive searches.
            MOUNTS is a comma-separated list of mount points or pathnames to
            directories.  When omitted, prevents descending into file systems
            that are not associated with the specified file and directory
            search targets.  Note that --exclude-fs=MOUNTS take priority over
            --include-fs=MOUNTS.  This option may be repeated.

As a minor point, I want to clarify that if no search targets are explicitly specified, then implicitly the search target is the working directory. In that case, only the FS associated with the working directory is searched.

Alternative wording:

    --exclude-fs=MOUNTS
            Exclude file systems specified by MOUNTS from recursive searches.
            MOUNTS is a comma-separated list of mount points or pathnames to
            directories.  When omitted, only descends into the file systems
            associated with the specified file and directory search targets.
            Note that --exclude-fs=MOUNTS take priority over
            --include-fs=MOUNTS.  This option may be repeated.

I like this a bit better. Less confusing. No double negation in a sentence.

To avoid breaking symmetry of these two options, a default --include-fs could be useful as a shorthand for --include-fs=.:

    --include-fs=MOUNTS
            Only file systems specified by MOUNTS are included in recursive
            searches.  MOUNTS is a comma-separated list of mount points or
            pathnames to directories.  When omitted, restricts recursive
            searches to the file system of the working directory only, same as
            --include-fs=. (dot). Note that --exclude-fs=MOUNTS take priority
            over --include-fs=MOUNTS.  This option may be repeated.

@wavexx
Copy link
Author

wavexx commented Jan 25, 2024

As a minor point, I want to clarify that if no search targets are explicitly specified, then implicitly the search target is the working directory. In that case, only the FS associated with the working directory is searched.

Very good point!

@genivia-inc
Copy link
Member

As a minor point, I want to clarify that if no search targets are explicitly specified, then implicitly the search target is the working directory. In that case, only the FS associated with the working directory is searched.

Very good point!

In that case it's the same as --include-fs=. because we're searching the working directory without descending into other devices. So there are two ways to get the same. But writing that in the man page would make it more confusing than it really is.

@genivia-inc genivia-inc self-assigned this Feb 15, 2024
genivia-inc added a commit that referenced this issue Feb 16, 2024
faster: implement #288
new feature #342
new feature #349
fix #350
fix #355
@genivia-inc
Copy link
Member

Implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants