Add portability wrapper for stat(1)

Fixes #1344.
This commit is contained in:
Andrew Gaul 2020-08-01 19:29:17 +09:00
parent 83361e7905
commit 0c1bc0f803
2 changed files with 14 additions and 13 deletions

View File

@ -210,20 +210,12 @@ function test_chmod {
# create the test file again
mk_test_file
if [ `uname` = "Darwin" ]; then
ORIGINAL_PERMISSIONS=$(stat -f "%p" $TEST_TEXT_FILE)
else
ORIGINAL_PERMISSIONS=$(stat --format=%a $TEST_TEXT_FILE)
fi
ORIGINAL_PERMISSIONS=$(get_permissions $TEST_TEXT_FILE)
chmod 777 $TEST_TEXT_FILE;
# if they're the same, we have a problem.
if [ `uname` = "Darwin" ]; then
CHANGED_PERMISSIONS=$(stat -f "%p" $TEST_TEXT_FILE)
else
CHANGED_PERMISSIONS=$(stat --format=%a $TEST_TEXT_FILE)
fi
CHANGED_PERMISSIONS=$(get_permissions $TEST_TEXT_FILE)
if [ $CHANGED_PERMISSIONS == $ORIGINAL_PERMISSIONS ]
then
echo "Could not modify $TEST_TEXT_FILE permissions"
@ -308,7 +300,7 @@ function test_external_directory_creation {
OBJECT_NAME="$(basename $PWD)/directory/${TEST_TEXT_FILE}"
echo "data" | aws_cli s3 cp - "s3://${TEST_BUCKET_1}/${OBJECT_NAME}"
ls | grep directory
stat --format=%a directory | grep ^750$
get_permissions directory | grep ^750$
ls directory
cmp <(echo "data") directory/${TEST_TEXT_FILE}
rm -f directory/${TEST_TEXT_FILE}

View File

@ -238,7 +238,7 @@ function get_ctime() {
if [ `uname` = "Darwin" ]; then
stat -f "%c" "$1"
else
stat -c %Z "$1"
stat -c "%Z" "$1"
fi
}
@ -246,9 +246,18 @@ function get_mtime() {
if [ `uname` = "Darwin" ]; then
stat -f "%m" "$1"
else
stat -c %Y "$1"
stat -c "%Y" "$1"
fi
}
function get_permissions() {
if [ `uname` = "Darwin" ]; then
stat -f "%p" "$1"
else
stat -c "%a" "$1"
fi
}
function check_content_type() {
INFO_STR=`aws_cli s3api head-object --bucket ${TEST_BUCKET_1} --key $1`
if [[ "${INFO_STR}" != *"$2"* ]]