Merge branch '1858_segfault_in_search'
[midnight-commander.git] / vfs / extfs / urar.in
blob6d29cd0975cacc675f8364883d30071e4b715f15
1 #! /bin/sh
3 # Written by andrey joukov
4 # (C) 1996 2:5020/337.13@fidonet.org
5 # Updated by christian.gennerat@alcatel.fr 1999
6 # Andrew V. Samoilov <sav@bcs.zp.ua> 2000
7 # beta version 2.0
9 # rar and unrar can be found on http://www.rarlabs.com/
11 RAR=rar
12 UNRAR=$RAR
14 # Prefer unrar (freeware). Try to find unrar in $PATH.
15 save_IFS="$IFS"; IFS=:
16 for dir in $PATH; do
17 IFS="$save_IFS"
18 test -z "$dir" && dir=.
19 if test -x "$dir/unrar" -a -f "$dir/unrar"; then
20 UNRAR="$dir/unrar"
21 break
23 done
25 if [ ! -x $UNRAR -a -x $RAR ]; then
26 UNRAR=$RAR
29 mcrarfs_list ()
31 $UNRAR v -c- "$1" | @AWK@ -v uid=`id -u` -v gid=`id -g` '
32 BEGIN { flag=0 }
33 /^-------/ { flag++; if (flag > 1) exit 0; next }
35 if (flag == 0) next
36 if ( !/ [0-9][0-9]:[0-9][0-9] /) str = $0 # there is no time spec in this line
37 else {
38 if (str ~ /^\^/)
39 str=substr(str, 2)
40 split($4, a, "-")
41 if (index($6, "D") != 0)
42 $6="drwxr-xr-x"
43 else
44 if (index($6, ".") != 0)
45 $6="-rw-r--r--"
46 printf "%s 1 %s %s %d %02d/%02d/%02d %s %s\n", $6, uid, gid, $1, a[2], a[1], a[3], $5, str
51 mcrarfs_copyin ()
53 # copyin by christian.gennerat@alcatel.fr
54 # preserve pwd. It is clean, but is it necessary?
55 pwd=`pwd`
56 # Create a directory and copy in it the tmp file with the good name
57 mkdir "$3.dir"
58 cd "$3.dir"
59 di="${2%/*}"
60 # if file is to be written upper in the archive tree, make fake dir
61 if test x"$di" != x"${2##*/}" ; then
62 mkdir -p "$di"
64 cp -fp "$3" "$3.dir/$2"
65 $RAR a "$1" "$2" >/dev/null
66 cd "$pwd"
67 rm -rf "$3.dir"
70 mcrarfs_copyout ()
72 $UNRAR p -p- -c- -inul "$1" "$2" > "$3"
75 mcrarfs_mkdir ()
77 # preserve pwd. It is clean, but is it necessary?
78 pwd=`pwd`
79 # Create a directory and create in it a tmp directory with the good name
80 dir=`mktemp -d "${MC_TMPDIR:-/tmp}/mctmpdir-urar.XXXXXX"` || exit 1
81 cd "$dir"
82 mkdir -p "$2"
83 # rar cannot create an empty directory
84 touch "$2"/.rarfs
85 $RAR a -r "$1" "$2" >/dev/null
86 $RAR d "$1" "$2/.rarfs" >/dev/null
87 cd "$pwd"
88 rm -rf "$dir"
91 mcrarfs_rm ()
93 $RAR d "$1" "$2" >/dev/null
96 LC_ALL=C
97 export LC_ALL
99 umask 077
101 cmd="$1"
102 shift
104 case "$cmd" in
105 # Workaround for a bug in mc - directories must precede files to
106 # avoid duplicate entries, so we sort output by filenames
107 list) mcrarfs_list "$@" | sort -k 8 ;;
108 rm) mcrarfs_rm "$@" ;;
109 rmdir) mcrarfs_rm "$@" ;;
110 mkdir) mcrarfs_mkdir "$@" ;;
111 copyin) mcrarfs_copyin "$@" ;;
112 copyout) mcrarfs_copyout "$@" ;;
113 *) exit 1 ;;
114 esac
115 exit 0