fix(git): split long path args to avoid Windows CreateProcess limit
Git operations that stage or restore many files could exceed the Windows command line length limit, causing os error 206 failures. This change splits file paths into size-bounded chunks and concatenates the output from multiple git invocations to keep commands within safe limits. - Chunk file path arguments for Windows compatibility - Add a local dev command to list pkg-config packages
This commit is contained in:
+36
-5
@@ -3415,16 +3415,47 @@ fn is_auth_error(details: &str) -> bool {
|
||||
|| d.contains("authentication required")
|
||||
}
|
||||
|
||||
// Windows' CreateProcess rejects command lines longer than ~32K chars with
|
||||
// "os error 206" (filename or extension too long). Staging/restoring a large
|
||||
// number of files can easily exceed that, so split the paths across multiple
|
||||
// invocations and concatenate their output.
|
||||
const MAX_PATH_ARGS_CHARS: usize = 8_000;
|
||||
|
||||
fn run_git_with_paths(
|
||||
repo: &Path,
|
||||
base_args: &[&str],
|
||||
files: &[String],
|
||||
) -> Result<Vec<u8>, String> {
|
||||
let mut args = Vec::with_capacity(base_args.len() + files.len() + 1);
|
||||
args.extend(base_args.iter().map(OsString::from));
|
||||
args.push(OsString::from("--"));
|
||||
args.extend(files.iter().map(OsString::from));
|
||||
run_git(repo, args)
|
||||
if files.is_empty() {
|
||||
let args: Vec<OsString> = base_args.iter().map(OsString::from).collect();
|
||||
return run_git(repo, args);
|
||||
}
|
||||
|
||||
let mut combined = Vec::new();
|
||||
let mut start = 0;
|
||||
while start < files.len() {
|
||||
let mut end = start;
|
||||
let mut chunk_chars = 0usize;
|
||||
while end < files.len() {
|
||||
let len = files[end].len() + 1;
|
||||
if end > start && chunk_chars + len > MAX_PATH_ARGS_CHARS {
|
||||
break;
|
||||
}
|
||||
chunk_chars += len;
|
||||
end += 1;
|
||||
}
|
||||
let chunk = &files[start..end];
|
||||
|
||||
let mut args = Vec::with_capacity(base_args.len() + chunk.len() + 1);
|
||||
args.extend(base_args.iter().map(OsString::from));
|
||||
args.push(OsString::from("--"));
|
||||
args.extend(chunk.iter().map(OsString::from));
|
||||
combined.extend(run_git(repo, args)?);
|
||||
|
||||
start = end;
|
||||
}
|
||||
|
||||
Ok(combined)
|
||||
}
|
||||
|
||||
fn run_git_with_paths_cancellable(
|
||||
|
||||
Reference in New Issue
Block a user