X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=archive_patch.sh;h=aebe780b74c86a5ad31a6c5522a9836d3083c4db;hb=ef5d2578315c704cc7fb722ae4dedf1d41ee4239;hp=082f69877b40e2e0d55dc3c10ff8a0f81ec8b07e;hpb=f9e21a1c58cd6ec79089571650a1f60d5f9317ad;p=cmccabe-bin
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