Thread View: linux.kernel.git
1 messages
1 total messages
Started by Junio C Hamano
Wed, 25 Nov 2026 00:24
Re: [PATCH v2 2/2] archive: defer --add-file stat() until after option parsing
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 00:24
Date: Wed, 25 Nov 2026 00:24
75 lines
16067 bytes
16067 bytes
Dominik Maier <dmnk@google.com> writes:
> add_file_cb() calls stat() on each --add-file argument while
> parse_options() is still running, before parse_archive_args() checks
> is_remote. When git-upload-archive parses client arguments, it probes
> the requested path on the server filesystem and reports "File not found"
> or "Not a regular file" instead of rejecting --add-file with --remote.
>
> Move the stat() and regular-file checks into parse_archive_args() after
> parse_options() finishes, refusing entries with a NULL content pointer
> when is_remote is set. This rejects remote --add-file before touching
> the filesystem, allows a later --no-add-file to cancel an earlier
> --add-file, and lets --add-virtual-file work with --remote since its
> content is supplied inline.
>
> Suggested-by: René Scharfe <l.s.r@web.de>
> Signed-off-by: Dominik Maier <dmnk@google.com>
> ---
> archive.c | 24 +++++++++++++++++-------
> t/t5000-tar-tree.sh | 24 ++++++++++++++++++++++++
> 2 files changed, 41 insertions(+), 7 deletions(-)
This seems to follow René's suggestion cleanly and resolves all three
issues without touching the filesystem when --remote or --no-add-file is
used.
> diff --git a/archive.c b/archive.c
> index 2348ab12ed..413fc1cd11 100644
> --- a/archive.c
> +++ b/archive.c
> @@ -586,11 +586,8 @@ static int add_file_cb(const struct option *opt, const char *arg, int unset)
>
> if (!strcmp(opt->long_name, "add-file")) {
> path = prefix_filename(args->prefix, arg);
> - if (stat(path, &info->stat))
> - die(_("File not found: %s"), path);
> - if (!S_ISREG(info->stat.st_mode))
> - die(_("Not a regular file: %s"), path);
> - info->content = NULL; /* read the file later */
> + memset(&info->stat, 0, sizeof(info->stat));
> + info->content = NULL; /* stat and read the file later */
Keeping prefix_filename() in add_file_cb() preserves relative path
resolution when invoked from a subdirectory, while deferring stat(2).
> @@ -706,8 +704,20 @@ static int parse_archive_args(int argc, const char **argv,
> die(_("the option '%s' requires '%s'"), "--exec", "--remote");
> if (output)
> die(_("Unexpected option --output"));
> - if (is_remote && args->extra_files.nr)
> - die(_("options '%s' and '%s' cannot be used together"), "--add-file", "--remote");
> + for_each_string_list_item(item, &args->extra_files) {
> + const char *path = item->string;
> + struct extra_file_info *info = item->util;
> +
> + if (info->content)
> + continue;
> + if (is_remote)
> + die(_("options '%s' and '%s' cannot be used together"),
> + "--add-file", "--remote");
> + if (stat(path, &info->stat))
> + die(_("File not found: %s"), path);
> + if (!S_ISREG(info->stat.st_mode))
> + die(_("Not a regular file: %s"), path);
> + }
setup_git_directory() is called only after parse_archive_args() returns
to write_archive(), so the working directory has not changed between
add_file_cb() and this loop, which means 'path' is correct. Entries
added by '--add-virtual-file' always have a non-NULL '.content' from
xstrdup(), so skipping them here lets '--remote' work without touching
the server filesystem.
Looking good.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads