Address some Shellcheck SC2012 warnings (#2306)

This commit is contained in:
Andrew Gaul 2023-09-10 12:50:18 +09:00 committed by GitHub
parent 3d73d5a687
commit 7e20278489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View File

@ -337,6 +337,7 @@ function test_chown {
# if they're the same, we have a problem. # if they're the same, we have a problem.
local CHANGED_PERMISSIONS local CHANGED_PERMISSIONS
# TODO: add helper
if [ "$(uname)" = "Darwin" ]; then if [ "$(uname)" = "Darwin" ]; then
CHANGED_PERMISSIONS=$(stat -f "%u:%g" "${TEST_TEXT_FILE}") CHANGED_PERMISSIONS=$(stat -f "%u:%g" "${TEST_TEXT_FILE}")
else else
@ -1847,8 +1848,8 @@ function test_concurrent_directory_updates {
for _ in $(seq 10); do for _ in $(seq 10); do
for i in $(seq 5); do for i in $(seq 5); do
local file local file
# shellcheck disable=SC2012,SC2046 # shellcheck disable=SC2046
file=$(ls $(seq 5) | "${SED_BIN}" -n "$((RANDOM % 5 + 1))p") file=$(echo [1-5] | "${SED_BIN}" -n "$((RANDOM % 5 + 1))p")
cat "${file}" >/dev/null || true cat "${file}" >/dev/null || true
rm -f "${file}" rm -f "${file}"
echo "foo" > "${file}" || true echo "foo" > "${file}" || true
@ -1985,8 +1986,7 @@ function test_cache_file_stat() {
# get cache file inode number # get cache file inode number
# #
local CACHE_FILE_INODE local CACHE_FILE_INODE
# shellcheck disable=SC2012 CACHE_FILE_INODE=$(get_inode "${CACHE_DIR}/${TEST_BUCKET_1}/${CACHE_TESTRUN_DIR}/${BIG_FILE}")
CACHE_FILE_INODE=$(ls -i "${CACHE_DIR}/${TEST_BUCKET_1}/${CACHE_TESTRUN_DIR}/${BIG_FILE}" 2>/dev/null | awk '{print $1}')
if [ -z "${CACHE_FILE_INODE}" ]; then if [ -z "${CACHE_FILE_INODE}" ]; then
echo "Not found cache file or failed to get inode: ${CACHE_DIR}/${TEST_BUCKET_1}/${CACHE_TESTRUN_DIR}/${BIG_FILE}" echo "Not found cache file or failed to get inode: ${CACHE_DIR}/${TEST_BUCKET_1}/${CACHE_TESTRUN_DIR}/${BIG_FILE}"
return 1; return 1;
@ -2029,8 +2029,7 @@ function test_cache_file_stat() {
# #
# get cache file inode number # get cache file inode number
# #
# shellcheck disable=SC2012 CACHE_FILE_INODE=$(get_inode "${CACHE_DIR}/${TEST_BUCKET_1}/${CACHE_TESTRUN_DIR}/${BIG_FILE}")
CACHE_FILE_INODE=$(ls -i "${CACHE_DIR}/${TEST_BUCKET_1}/${CACHE_TESTRUN_DIR}/${BIG_FILE}" 2>/dev/null | awk '{print $1}')
if [ -z "${CACHE_FILE_INODE}" ]; then if [ -z "${CACHE_FILE_INODE}" ]; then
echo "Not found cache file or failed to get inode: ${CACHE_DIR}/${TEST_BUCKET_1}/${CACHE_TESTRUN_DIR}/${BIG_FILE}" echo "Not found cache file or failed to get inode: ${CACHE_DIR}/${TEST_BUCKET_1}/${CACHE_TESTRUN_DIR}/${BIG_FILE}"
return 1; return 1;
@ -2211,8 +2210,7 @@ function test_ensurespace_move_file() {
MOVED_PERMISSIONS=$(stat --format=%u:%g "${BIG_FILE}") MOVED_PERMISSIONS=$(stat --format=%u:%g "${BIG_FILE}")
fi fi
local MOVED_FILE_LENGTH local MOVED_FILE_LENGTH
# shellcheck disable=SC2012 MOVED_FILE_LENGTH=$(get_size "${BIG_FILE}")
MOVED_FILE_LENGTH=$(ls -l "${BIG_FILE}" | awk '{print $5}')
# #
# check # check
@ -2547,9 +2545,8 @@ function test_file_names_longer_than_posix() {
rm -f "${a256}" rm -f "${a256}"
echo data | aws_cli s3 cp - "s3://${TEST_BUCKET_1}/${DIR_NAME}/${a256}" echo data | aws_cli s3 cp - "s3://${TEST_BUCKET_1}/${DIR_NAME}/${a256}"
# shellcheck disable=SC2012 files=(*)
count=$(ls | wc -l) if [ "${#files[@]}" = 0 ]; then
if [ "${count}" = 0 ]; then
echo "failed to list long file name" echo "failed to list long file name"
return 1 return 1
fi fi

View File

@ -95,11 +95,19 @@ function del_xattr() {
fi fi
} }
function get_inode() {
if [ "$(uname)" = "Darwin" ]; then
stat -f "%i" "$1"
else
stat --format "%i" "$1"
fi
}
function get_size() { function get_size() {
if [ "$(uname)" = "Darwin" ]; then if [ "$(uname)" = "Darwin" ]; then
stat -f "%z" "$1" stat -f "%z" "$1"
else else
stat -c %s "$1" stat --format "%s" "$1"
fi fi
} }