wrapped stat in safety function to split between gnu and bsd

This commit is contained in:
James Tomasino 2018-03-30 11:49:13 -04:00
parent 6b683df3be
commit 416f8707b1
1 changed files with 22 additions and 4 deletions

26
burrow
View File

@ -23,6 +23,11 @@ config_git_commit=false
config_git_push=false
config_autoindent=true
# coreutils function wrappers
function stat_func {
return 0
}
# vars from flags
flag_debug=0
flag_version=0
@ -71,6 +76,18 @@ OPTIONAL FLAGS:
END
}
function check_coreutils {
if stat -c"%U" /dev/null >/dev/null 2>/dev/null ; then
function stat_func {
stat -c %Y "$1"
}
else
function stat_func {
stat -Lnqr "$1" | awk '{print $9}'
}
fi
}
function parse_input {
getopt -T > /dev/null
if [ $? -eq 4 ]; then
@ -264,13 +281,13 @@ function make_post_unprocess {
fi
# Get timestamp of tempfile
temp_post_time=$(stat -c %Y "$temp_post")
temp_post_time=$(stat_func "$temp_post")
# Edit tempfile
$EDITOR "$temp_post"
# Verify that timestamp changed after editing, or abort
temp_post_time_check=$(stat -c %Y "$temp_post")
temp_post_time_check=$(stat_func "$temp_post")
if [[ "$temp_post_time" != "$temp_post_time_check" ]] ; then
cp "${temp_post}" "$post_file"
rm "${temp_post}"
@ -302,11 +319,11 @@ function make_post_temp {
fi
# Check timestamp before editing file
temp_post_time=$(stat -c %Y "$temp_post")
temp_post_time=$(stat_func "$temp_post")
$EDITOR "$temp_post"
# Verify that timestamp changed after editing, or abort
temp_post_time_check=$(stat -c %Y "$temp_post")
temp_post_time_check=$(stat_func "$temp_post")
# If we saved a change, create the new file
if [[ "$temp_post_time" != "$temp_post_time_check" ]] ; then
@ -475,6 +492,7 @@ function update_burrow {
}
function main {
check_coreutils "$@"
parse_input "$@"
if [[ $arg_shortlist -gt 0 ]]; then