3 # extfs support for p7zip
4 # Written by Pavel Roskin <proski@gnu.org>
5 # Some Bugfixes/workarounds by Sergiy Niskorodov <sgh@mail.zp.ua>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 P7ZIP
=`which 7z 2>/dev/null` || P7ZIP
=`which 7za 2>/dev/null` || P7ZIP
=`which 7zr 2>/dev/null` || P7ZIP
=""
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
='^\(....\)-\(..\)-\(..\) \(..:..:..\)'
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"
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
50 $P7ZIP a
-si"$2" "$1" <"$3" >/dev
/null
2>&1
55 dir
=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-u7z.XXXXXX"` ||
exit 1
57 $P7ZIP a
-w"$dir" "$1" "$dir"/"$2" >/dev
/null
2>&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 ; }
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 ; }
80 # override any locale for dates
86 if [ -z "$P7ZIP" ]; then
87 echo "Error: could not find p7zip (looked for 7z, 7za and 7zr)" >&2
95 list
) mcu7zip_list
"$@" |
sort -k 8 ;;
96 copyout
) mcu7zip_copyout
"$@" ;;
97 copyin
) mcu7zip_copyin
"$@" ;;
98 mkdir
) mcu7zip_mkdir
"$@" ;;
99 rm) mcu7zip_rm
"$@" ;;
100 rmdir) mcu7zip_rmdir
"$@" ;;