Skip to content

Commit

Permalink
Add old Microsoft .doc and related formats to automtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dfandrich committed Feb 29, 2024
1 parent 624ae1d commit c9eeb79
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions automtime
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -972,6 +984,10 @@ for f in "$@" ; do
TYPE=docbook
;;

*.doc | *.xls | *.ppt)
TYPE=doc
;;

*.docx | *.docm | *.xlsx | *.pptx)
TYPE=docx
;;
Expand Down
2 changes: 2 additions & 0 deletions test-automtime-expected
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
Binary file added testfiles/type1.doc
Binary file not shown.
Binary file added testfiles/type2.doc
Binary file not shown.

0 comments on commit c9eeb79

Please sign in to comment.