From: Colin Patrick McCabe Date: Tue, 8 Nov 2011 19:05:59 +0000 (-0800) Subject: archive_patch: add -m option X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb6ae5435ed5f560403f0eb8b351951cca7439c6;p=cmccabe-bin archive_patch: add -m option Signed-off-by: Colin McCabe --- diff --git a/archive_patch.sh b/archive_patch.sh index 082f698..aebe780 100755 --- a/archive_patch.sh +++ b/archive_patch.sh @@ -20,12 +20,14 @@ usage() { echo "-c copy the file rather than moving it" echo "-d directory where the file should end up (default: .)" echo "-h This help message" + echo "-m Use the file's modification time, not the current time" echo } copy=0 destdir=. -while getopts "cd:h" flag +use_mtime=0 +while getopts "cd:hm" flag do case $flag in c) copy=1;; @@ -36,6 +38,8 @@ do exit 1 ;; + m) use_mtime=1;; + *) usage exit 1;; esac @@ -54,6 +58,11 @@ for file in "$@"; do [ -e "$file" ] || die "'$file' does not exist" done for file in "$@"; do - new_file_name=$destdir/`date +'%Y-%m-%d'`_`basename $file` + if [ $use_mtime -eq 1 ]; then + new_date=`stat -c '%y' "${file}" | sed 's/ .*//'` + new_file_name="${destdir}/${new_date}_`basename "${file}"`" + else + new_file_name="$destdir/`date +'%Y-%m-%d'`_`basename "${file}"`" + fi $cmd "${file}" "${new_file_name}" || die "failed on $file" done