From b17b0385db147776ab9cd93d11741e51cf51e23e Mon Sep 17 00:00:00 2001 From: Chris Darroch Date: Fri, 12 Jul 2024 21:39:19 -0700 Subject: [PATCH] /t-migrate-{ex,im}port.sh: avoid using mktemp In commit 96775c62f71d795af1547f6ef92c2a8602fd32df of PR #2929 the "migrate import (--object-map)" test was added to the test suite for the "git lfs migrate import" command to validate the --object-map option for that command, which was introduced in the same PR. This test makes use of the mktemp(1) shell command to generate a unique temporary directory, into which the test then writes several files including the Git LFS migration's object map file. Likewise, in commit 7632a205d378709bcf1d3733c31a0f43668c4821 of PR #3084, a similar "migrate export (--object-map)" test was added to the test suite for the "git lfs migrate export" command, which was introduced in that PR, and this test also uses the mktemp(1) shell command to create a unique temporary directory. However, neither test removes these temporary directories after completion, so they remain in place indefinitely in whatever system location is used by the mktemp(1) command. This is in addition to the temporary directory created by the mktemp(1) command which is used throughout all our test suites, whose path we store in the GIT_LFS_TEST_DIR variable so it can be reused by all test suites after the first one to run. (At least, that is the intent of the variable, but in practice, because we do not export it, and because each test script runs in its own shell session, each script creates another temporary directory. We will address this issue in a subsequent PR.) In a previous commit in this PR we introduced a new lfstest-genrandom utility program for our test suite, so we can now make use of it to replace both instances where our migration tests make an extra call to the mktemp(1) shell command (beyond the one used to populate the GIT_LFS_TEST_DIR variable). In both tests, we now create a unique directory whose path begins with the path in the GIT_LFS_TEST_DIR variable, followed by a directory name partially generated by our lfstest-genrandom program. We pass the --base64url flag to the program ensure it returns only characters safe to use in a file or directory name on any OS platform. --- t/t-migrate-export.sh | 3 ++- t/t-migrate-import.sh | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t-migrate-export.sh b/t/t-migrate-export.sh index 75e08fb36d..a88ad9fd84 100755 --- a/t/t-migrate-export.sh +++ b/t/t-migrate-export.sh @@ -455,7 +455,8 @@ begin_test "migrate export (--object-map)" setup_multiple_local_branches_tracked - output_dir=$(mktemp -d) + output_dir="$GIT_LFS_TEST_DIR/export-object-map-$(lfstest-genrandom --base64url 32)" + mkdir -p "$output_dir" git log --all --pretty='format:%H' > "${output_dir}/old_sha.txt" git lfs migrate export --everything --include="*" --object-map "${output_dir}/object-map.txt" diff --git a/t/t-migrate-import.sh b/t/t-migrate-import.sh index 8c4769631d..1170176152 100755 --- a/t/t-migrate-import.sh +++ b/t/t-migrate-import.sh @@ -935,7 +935,8 @@ begin_test "migrate import (--object-map)" setup_multiple_local_branches - output_dir=$(mktemp -d) + output_dir="$GIT_LFS_TEST_DIR/import-object-map-$(lfstest-genrandom --base64url 32)" + mkdir -p "$output_dir" git log --all --pretty='format:%H' > "${output_dir}/old_sha.txt" git lfs migrate import --everything --object-map "${output_dir}/object-map.txt"