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

View File

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