-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
-X should batch the number of passed files to the maximum supported by the shell #410
Comments
Thank you for reporting this. That was a known limitation when we first implemented Thank you for the information about |
Note that actually counting the size of your arguments is not straightforward: https://github.com/tavianator/bfs/blob/master/exec.c#L61 On Linux at least, you have to count the total length of the command line arguments and environment variables (and auxiliary vector), including NUL terminators, plus the length of the This is all finicky enough that I also implemented code in bfs to detect and recover from |
It could be easier to implement on Windows, as the accounting only involves the size of the ''lpCommandLine'' parameter. However, it is still non-trivial since the escapes performed by the rust |
In #768, @BurritoBurrato suggests to add a This makes me think. Is there a reasonable (sub-optimal) limit that we could set for the batch size that should work for most platforms/environments? This wouldn't be ideal, but better than the current situation. |
I'm not sure. On Linux at least, the limit is a combination of all environment variables, and all command line arguments. So if it is run on an unusually large environment, the space remaining may be unusually small. If it's helpful, the output of
I'm not sure where xargs gets the buffer size of 131072 from. |
I can take a shot at implementing a |
Sounds good to me. |
I don't really think this is fixed yet. |
Agreed. |
I started to implement this. I took the liberty to do a 1:1 translation of your implementation in Limitations:
That being said, I was able to get the exact same numbers as the ones in the The library also contains a test that determines the limit experimentally (via a binary search on |
Oh awesome! I was actually going to do that today too but didn't get around to it. I'm definitely okay with it, and pretty much any licence is compatible with bfs's. I think the implementation is probably good enough for any unix, not just Linux. |
I got some time today to continue working on this. There is more work to be done.
Ref: current CI output: https://github.com/sharkdp/argmax/actions/runs/1469073321 I also found out that there is another limit that needs to be enforced (not relevant for Any help would be very much appreciated. *reasonably close: it shouldn't be an order of magnitude smaller than the actual limit. |
For Edit: seems like that is what's happening. This workaround fixes the failure for me: diff --git a/src/unix.rs b/src/unix.rs
index 9f4c419..04c7501 100644
--- a/src/unix.rs
+++ b/src/unix.rs
@@ -48,7 +48,7 @@ fn size_of_environment() -> i64 {
/// Required size to store a single ARG argument and the corresponding
/// pointer in argv**.
pub(crate) fn arg_size<O: AsRef<OsStr>>(arg: O) -> i64 {
- size_of::<*const c_char>() as i64 // size for the pointer in argv**
+ size_of::<u64>() as i64 // size for the pointer in argv**
+ arg.as_ref().len() as i64 // size for argument string
+ 1 // terminating NULL
} I don't know what the best fix is. To be perfectly accurate we'd have to know whether the binary we're executing is a 32- or 64-bit binary. Maybe it's okay to conservatively assume that pointers are always 8 bytes. |
I released a first version of the |
having this issue on macOS 10.15 as well |
I am working on this, but the details are pretty awkward. Since $ fd -X echo before {} after I have to support adding arguments after the paths. But that's pretty awkward with What I think we want is something like if cmd.has_room_for([arg, "after", ...]) {
assert!(cmd.try_arg(arg));
} else {
assert!(cmd.try_args(["after", ...]));
cmd.spawn();
cmd = Command::new(...);
} |
Right - I was afraid that |
It appears that if you run
getconf ARG_MAX
it returns the maximum length that the command string can be. Possibly include a command to artificially limit the number of arguments as well?The text was updated successfully, but these errors were encountered: