From a84af09f62c19d52b17696efec3c107cdec71941 Mon Sep 17 00:00:00 2001
From: Andreas Mohr <and@gmx.li>
Date: Sat, 5 Mar 2016 17:43:52 +0000
Subject: [PATCH] Extfs helper u7z: fix parsing 7z archive without datetime entry
7z archive can hold entries without datetime info (7z a -mtm- ...)
and will use archive file datetime info instead.
Currently u7z helper hide/skip these entries. Fix it by detect these entries
and obtain archive file datetime by stat command (fallback to ls -lan)
Bug #2707 reported by birdie
- whitespace ident
Signed-off-by: Andreas Mohr <and@gmx.li>
---
src/vfs/extfs/helpers/u7z | 59 ++++++++++++++++++++++++++---------------------
1 file changed, 33 insertions(+), 26 deletions(-)
diff --git a/src/vfs/extfs/helpers/u7z b/src/vfs/extfs/helpers/u7z
index 88916ff..592260e 100755
a
|
b
|
P7ZIP=`which 7z 2>/dev/null` || P7ZIP=`which 7za 2>/dev/null` || P7ZIP=`which 7z |
21 | 21 | |
22 | 22 | mcu7zip_list () |
23 | 23 | { |
24 | | # Symlinks are not shown - no idea how to distinguish them |
25 | | # Read-only files are not shown as such - it's rarely useful |
26 | | ugid="`id -nu` `id -ng`" |
27 | | date_re='^\(....\)-\(..\)-\(..\) \(..:..:..\)' |
28 | | date_mc='\2-\3-\1 \4' |
29 | | size_re='............' |
30 | | $P7ZIP l "$1" | sed -n "s/$date_re D.... $size_re $size_re\(.*\)/drwxr-xr-x 1 $ugid 0 $date_mc \5/p;s/$date_re \..... \($size_re\) $size_re\(.*\)/-rw-r--r-- 1 $ugid \5 $date_mc \6/p" |
| 24 | # Symlinks are not shown - no idea how to distinguish them |
| 25 | # Read-only files are not shown as such - it's rarely useful |
| 26 | ugid="`id -nu` `id -ng`" |
| 27 | date_re='^\(....\)-\(..\)-\(..\) \(..:..:..\)' |
| 28 | date_mc='\2-\3-\1 \4' |
| 29 | size_re='............' |
| 30 | # archive entries can have no datetime info, 7z will use archive file datetime |
| 31 | date_archive=`stat -c %y "$1" 2>/dev/null | sed -n "s/${date_re}.*/${date_mc}/p" 2>/dev/null` |
| 32 | [ "${date_archive}"x = x ] && date_archive=`ls -lan "$1" 2>/dev/null | awk '{print $6,"",$7,"",$8}' 2>/dev/null` |
| 33 | [ "${date_archive}"x = x ] && date_archive="01-01-1970 00:00:00" |
| 34 | $P7ZIP l "$1" | sed -n "s/$date_re D.... $size_re $size_re\(.*\)/drwxr-xr-x 1 $ugid 0 $date_mc \5/p;\ |
| 35 | s/$date_re \..... \($size_re\) $size_re\(.*\)/-rw-r--r-- 1 $ugid \5 $date_mc \6/p;\ |
| 36 | s/^\s*D.... $size_re $size_re\(.*\)/drwxr-xr-x 1 $ugid 0 $date_archive \1/p;\ |
| 37 | s/^\s*\..... \($size_re\) $size_re\(.*\)/-rw-r--r-- 1 $ugid \1 $date_archive \2/p" |
31 | 38 | } |
32 | 39 | |
33 | 40 | mcu7zip_copyout () |
34 | 41 | { |
35 | | #first we check if we have old p7zip archive with prefix ./ in filename |
36 | | $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \ |
37 | | EXFNAME='*./'"$2" || EXFNAME="$2" |
38 | | $P7ZIP e -so "$1" "$EXFNAME" > "$3" 2>/dev/null |
| 42 | #first we check if we have old p7zip archive with prefix ./ in filename |
| 43 | $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \ |
| 44 | EXFNAME='*./'"$2" || EXFNAME="$2" |
| 45 | $P7ZIP e -so "$1" "$EXFNAME" > "$3" 2>/dev/null |
39 | 46 | } |
40 | 47 | |
41 | 48 | mcu7zip_copyin () |
… |
… |
mcu7zip_copyin () |
45 | 52 | |
46 | 53 | mcu7zip_mkdir () |
47 | 54 | { |
48 | | dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-u7z.XXXXXX"` || exit 1 |
49 | | mkdir -p "$dir"/"$2" |
50 | | $P7ZIP a -w"$dir" "$1" "$dir"/"$2" >/dev/null 2>&1 |
51 | | rm -rf "$dir" |
| 55 | dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-u7z.XXXXXX"` || exit 1 |
| 56 | mkdir -p "$dir"/"$2" |
| 57 | $P7ZIP a -w"$dir" "$1" "$dir"/"$2" >/dev/null 2>&1 |
| 58 | rm -rf "$dir" |
52 | 59 | } |
53 | 60 | |
54 | 61 | mcu7zip_rm () |
55 | 62 | { |
56 | | # NOTE: Version 4.20 fails to delete files in subdirectories |
57 | | #first we check if we have old p7zip archive with prefix ./ in filename |
58 | | $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \ |
59 | | EXFNAME='*./'"$2" || EXFNAME="$2" |
60 | | $P7ZIP d "$1" "$EXFNAME" 2>&1 | grep -q E_NOTIMPL > /dev/null 2>&1 && \ |
61 | | { printf "Function not implemented...\n7z cannot delete from solid archive." >&2 ; exit 1 ; } |
| 63 | # NOTE: Version 4.20 fails to delete files in subdirectories |
| 64 | #first we check if we have old p7zip archive with prefix ./ in filename |
| 65 | $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \ |
| 66 | EXFNAME='*./'"$2" || EXFNAME="$2" |
| 67 | $P7ZIP d "$1" "$EXFNAME" 2>&1 | grep -q E_NOTIMPL > /dev/null 2>&1 && \ |
| 68 | { printf "Function not implemented...\n7z cannot delete from solid archive." >&2 ; exit 1 ; } |
62 | 69 | } |
63 | 70 | |
64 | 71 | mcu7zip_rmdir () |
65 | 72 | { |
66 | | #first we check if we have old p7zip archive with prefix ./ in filename |
67 | | $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \ |
68 | | EXFNAME='*./'"$2" || EXFNAME="$2" |
69 | | $P7ZIP d "$1" "$EXFNAME"/ 2>&1 | grep -q E_NOTIMPL > /dev/null 2>&1 && \ |
70 | | { printf "Function not implemented...\n7z cannot delete from solid archive." >&2 ; exit 1 ; } |
| 73 | #first we check if we have old p7zip archive with prefix ./ in filename |
| 74 | $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \ |
| 75 | EXFNAME='*./'"$2" || EXFNAME="$2" |
| 76 | $P7ZIP d "$1" "$EXFNAME"/ 2>&1 | grep -q E_NOTIMPL > /dev/null 2>&1 && \ |
| 77 | { printf "Function not implemented...\n7z cannot delete from solid archive." >&2 ; exit 1 ; } |
71 | 78 | } |
72 | 79 | |
73 | 80 | # override any locale for dates |