From fb6ae5435ed5f560403f0eb8b351951cca7439c6 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Tue, 8 Nov 2011 11:05:59 -0800 Subject: [PATCH] archive_patch: add -m option Signed-off-by: Colin McCabe --- archive_patch.sh | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-) 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 -- 1.6.6.rc1.39.g9a42