Merge branch '1858_segfault_in_search'
[midnight-commander.git] / vfs / extfs / u7z
blobcc8d2d9de0664f98968bd852f33e616cd0a3a900
1 #! /bin/sh
3 # extfs support for p7zip
4 # Written by Pavel Roskin <proski@gnu.org>
5 # Some Bugfixes/workarounds by Sergiy Niskorodov <sgh@mail.zp.ua>
6 # Licensed under GNU GPL version 2 or later version.
8 P7ZIP=`which 7z 2>/dev/null` || P7ZIP=`which 7za 2>/dev/null`
10 mcu7zip_list ()
12 # Symlinks are not shown - no idea how to distinguish them
13 # Read-only files are not shown as such - it's rarely useful
14 ugid="`id -nu` `id -ng`"
15 date_re='^\(....\)-\(..\)-\(..\) \(..:..:..\)'
16 date_mc='\2-\3-\1 \4'
17 size_re='............'
18 $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"
21 mcu7zip_copyout ()
23 #first we check if we have old p7zip archive with prefix ./ in filename
24 $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \
25 EXFNAME='*./'"$2" || EXFNAME="$2"
26 $P7ZIP e -so "$1" "$EXFNAME" > "$3" 2>/dev/null
29 mcu7zip_copyin ()
31 $P7ZIP a -si"$2" "$1" <"$3" >/dev/null 2>&1
34 mcu7zip_mkdir ()
36 dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-u7z.XXXXXX"` || exit 1
37 mkdir -p "$dir"/"$2"
38 $P7ZIP a -w"$dir" "$1" "$dir"/"$2" >/dev/null 2>&1
39 rm -rf "$dir"
42 mcu7zip_rm ()
44 # NOTE: Version 4.20 fails to delete files in subdirectories
45 #first we check if we have old p7zip archive with prefix ./ in filename
46 $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \
47 EXFNAME='*./'"$2" || EXFNAME="$2"
48 $P7ZIP d "$1" "$EXFNAME" 2>&1 | grep -q E_NOTIMPL > /dev/null 2>&1 && \
49 { printf "Function not implemented...\n7z cannot delete from solid archive." >&2 ; exit 1 ; }
52 mcu7zip_rmdir ()
54 #first we check if we have old p7zip archive with prefix ./ in filename
55 $P7ZIP l "$1" "$2" | grep -q "0 files, 0 folders" && \
56 EXFNAME='*./'"$2" || EXFNAME="$2"
57 $P7ZIP d "$1" "$EXFNAME"/ 2>&1 | grep -q E_NOTIMPL > /dev/null 2>&1 && \
58 { printf "Function not implemented...\n7z cannot delete from solid archive." >&2 ; exit 1 ; }
61 # override any locale for dates
62 LC_DATE=C
63 export LC_DATE
65 umask 077
67 cmd="$1"
68 shift
70 case "$cmd" in
71 list) mcu7zip_list "$@" | sort -k 8 ;;
72 copyout) mcu7zip_copyout "$@" ;;
73 copyin) mcu7zip_copyin "$@" ;;
74 mkdir) mcu7zip_mkdir "$@" ;;
75 rm) mcu7zip_rm "$@" ;;
76 rmdir) mcu7zip_rmdir "$@" ;;
77 *) exit 1 ;;
78 esac
79 exit 0