Skip to content

Commit

Permalink
Fix scalar diagnose failures (#543)
Browse files Browse the repository at this point in the history
This resolves #541.

The root cause here is that this loop that intended to get all files
from the `info` directory of the shared object cache _never worked_, but
previously we did not propagate that to a complete failure.

The reason it didn't work is that we tried to read file contents from
the directory path.

I also noticed a silly retry issue because we are now using `run_git()`
which does three retries due to concurrency issues in the functional
tests. We don't want to repeat failures three times in `scalar
diagnose`.
  • Loading branch information
derrickstolee authored Nov 8, 2022
2 parents 0de34d5 + cf052e5 commit e380c61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ BASIC_CFLAGS += -DSHA1DC_FORCE_ALIGNED_ACCESS
endif
ifneq ($(filter leak,$(SANITIZERS)),)
BASIC_CFLAGS += -DSUPPRESS_ANNOTATED_LEAKS
BASIC_CFLAGS += -O0
SANITIZE_LEAK = YesCompiledWithIt
endif
ifneq ($(filter address,$(SANITIZERS)),)
Expand Down
11 changes: 11 additions & 0 deletions diagnose.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)
}

if (shared_cache) {
size_t path_len;

strbuf_reset(&buf);
strbuf_addf(&path, "%s/pack", shared_cache);
strbuf_reset(&buf);
Expand All @@ -336,16 +338,25 @@ int create_diagnostics_archive(struct strbuf *zip_path, enum diagnose_mode mode)

strbuf_reset(&path);
strbuf_addf(&path, "%s/info", shared_cache);
path_len = path.len;

if (is_directory(path.buf)) {
DIR *dir = opendir(path.buf);
struct dirent *e;

while ((e = readdir(dir))) {
if (!strcmp(".", e->d_name) || !strcmp("..", e->d_name))
continue;
if (e->d_type == DT_DIR)
continue;

strbuf_reset(&buf);
strbuf_addf(&buf, "--add-virtual-file=info/%s:", e->d_name);

strbuf_setlen(&path, path_len);
strbuf_addch(&path, '/');
strbuf_addstr(&path, e->d_name);

if (strbuf_read_file(&buf, path.buf, 0) < 0) {
res = error_errno(_("could not read '%s'"), path.buf);
goto diagnose_cleanup;
Expand Down
2 changes: 2 additions & 0 deletions scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,8 @@ static int cmd_diagnose(int argc, const char **argv)
setup_enlistment_directory(argc, argv, usage, options, &diagnostics_root);
strbuf_addstr(&diagnostics_root, "/.scalarDiagnostics");

/* Here, a failure should not repeat itself. */
git_retries = 1;
res = run_git("diagnose", "--mode=all", "-s", "%Y%m%d_%H%M%S",
"-o", diagnostics_root.buf, NULL);

Expand Down

0 comments on commit e380c61

Please sign in to comment.