diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ab3ecb..5759a7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -146,10 +146,14 @@ jobs: run: | mkdir -p "$PWD/tb" for i in $(/usr/bin/toybox); do ln -s /usr/bin/toybox "$PWD/tb/$i"; done + # Toybox file doesn't support decoding Microsoft compound documents + sed -i.orig -e '/type[0-9]\.doc\>/d' test-automtime-expected - name: 'Run tests using Toybox' run: PATH="$PWD/tb:$PATH" make check -k - name: 'Prepare for dash filename tests' run: | + # Start by restoring the golden file modified for Toybox tests + mv -f test-automtime-expected.orig test-automtime-expected # These tests consist of renaming all the test files to start with # a dash so they look like command-line options in order to test that # file names are properly escaped when passed in to programs. diff --git a/automtime b/automtime index 12361eb..f52f995 100755 --- a/automtime +++ b/automtime @@ -249,6 +249,18 @@ mtime_docbook () { TIME="$(normalize_time "$RAWTIME")" } +# File type: doc (Microsoft composite document) +# requires: file +mtime_doc () { + RAWTIME=$(file - < "$f" | sed -n -e 's@^.*Last Saved Time/Date: \([^,]\+\)\>.*$@\1@p') + # First revision sometimes doesn't included Last Saved, so use Create then + if [ -z "$RAWTIME" ] ; then + RAWTIME=$(file - < "$f" | sed -n -e 's@^.*Create Time/Date: \([^,]\+\)\>.*$@\1@p') + fi + # $RAWTIME is like Tue Mar 23 12:34:56 2010 + TIME="$(normalize_time "$RAWTIME")" +} + # File type: docx (Microsoft Office Open XML) # requires: unzip, xmlstarlet mtime_docx () { @@ -972,6 +984,10 @@ for f in "$@" ; do TYPE=docbook ;; + *.doc | *.xls | *.ppt) + TYPE=doc + ;; + *.docx | *.docm | *.xlsx | *.pptx) TYPE=docx ;; diff --git a/test-automtime-expected b/test-automtime-expected index 04aaefe..1437204 100644 --- a/test-automtime-expected +++ b/test-automtime-expected @@ -8,6 +8,7 @@ 'testfiles/type1.dbk' '2023-01-12 10:46:09' 'testfiles/type1.deb' '2023-04-26 18:21:00 +0000' 'testfiles/type1.diff' '2023-04-01 20:18:48 +0000' +'testfiles/type1.doc' '2024-02-28 23:52:53' 'testfiles/type1.docx' '2021-10-14 12:16:10 +0000' 'testfiles/type1.egg' '2023-03-16 14:24:00' 'testfiles/type1.epub' '2021-10-19 01:40:52' @@ -63,6 +64,7 @@ 'testfiles/type2.amf' '2021-10-20 16:56:58' 'testfiles/type2.dat' '2021-10-13 07:53' 'testfiles/type2.dbk' '2023-01-12 00:00:00' +'testfiles/type2.doc' '2024-01-31 00:36:45' 'testfiles/type2.gcode' '2012-05-16 08:25:51' 'testfiles/type2.gpx' '2012-11-22 10:34:01 +0000' 'testfiles/type2.iso' '2023-06-08 20:22:20.33 -0700' diff --git a/testfiles/type1.doc b/testfiles/type1.doc new file mode 100644 index 0000000..9c12a27 Binary files /dev/null and b/testfiles/type1.doc differ diff --git a/testfiles/type2.doc b/testfiles/type2.doc new file mode 100644 index 0000000..390a3b8 Binary files /dev/null and b/testfiles/type2.doc differ