Debian Codegraph @

extfs/udar

raw ◀ ▶
1 Debian patch touch this file
1 #! /bin/sh
2 #
3 # Written by Guus Jansman
4 # BSD type of licence (or Public Domain, GPL or closed source, basically
5 # whatever you want). The license type may be changed according to your
6 # wishes.
7 #
8 # This is a parser for Dar archives in Midnight Commander. You need
9 # the GPL dar program (version >= 2.3.0) written by Denis Corbin.
10
11 # Limitations:
12 # - The archive files can not be changed
13 # - Symbolic and hard links are not handled properly
14 # - Block and character special files are not handled
15 # - Files not stored in (differential) backups are not handled
16
17 # Changes
18 # 2010-09-27 Ralf Hoffmann <[email protected]>
19 # - hard links (h) and special dar file type (e) are handled
20 # as regular files
21
•22 DAR=dar
23
24 # dar expects the basename (without number and extension)
25 BASENAME="`echo "$2" | sed -e 's/\.[0-9]*\.[Dd][Aa][Rr]$//'`"
26
27 mcdarfs_list ()
28 {
29 $DAR -l "$BASENAME" -N -Q -as -ay 2>/dev/null | gawk -v uuid=$(id -ru) '
30 BEGIN { flag=0 }
31 /^-------/ { flag++; if (flag > 1) exit 0; next }
32 /^$/ { next }
33 {
34 if (flag == 0) next
35 line=$0
36 split(line, record, " ")
37
38 # Do not display removed files
39 if (record[1] == "[" && record[2] == "REMOVED")
40 {
41 next
42 }
43
44 # We want "line" to start with permutation
45 # TODO: better algorithm
46 while (length(record[1]) != 10 || match(substr(record[1], 2, 1), "[r-]") == 0)
47 {
48 # line without real contents
49 if (length(line) == 0) {
50 next
51 }
52 line=substr(line, length(record[1])+1)
53 while (length(line) != 0 && substr(line, 1, 1) != " ")
54 {
55 line=substr(line, 2)
56 }
57 split(line, record, " ")
58 }
59
60 perm=record[1]
61 # Block and character special files not supported
62 # Change [bc] to [bcl] if symbolic links should not show up either
63 if (match(substr(perm, 1, 1), "[bc]") != 0)
64 {
65 next
66 }
67 # change h and e types into regulat types
68 if (match(substr(perm, 1, 1), "[he]") != 0)
69 {
70 perm = "-" substr( perm, 2 );
71 }
72 uid=record[2]
73 if (match(uid, "^[0-9]*$") != 0)
74 {
75 uid=sprintf("%-8d", uid)
76 }
77 gid=record[3]
78 if (match(gid, "^[0-9]*$") != 0)
79 {
80 gid=sprintf("%-8d", gid)
81 }
82 size=record[4]
83 month=record[6]
84 day=record[7]
85 time=substr(record[8], 1, 5)
86 year=record[9]
87 name=substr(line, index(line, sprintf("%s:", time))+14)
88 # TODO: find symbolic link target (probably the link has to be extracted)
89 printf "%s 1 %s %s %8d %3s %02d %04d %s %s\n", perm, uid, gid, size, month, day, year, time, name
90 }'
91 }
92
93 mcdarfs_copyout ()
94 {
95 # Dummy directory necessary since dar cannot output to stdout or named file
96 mkdir "$3.dir.tmp"
97 chmod 700 "$3.dir.tmp"
98 if [ ! -d "$3.dir.tmp" ]; then exit 1; fi
99 $DAR -x "$BASENAME" -N -O -Q -wa -g "$2" -R "$3.dir.tmp" >/dev/null
100 if [ -e "$3.dir.tmp/$2" ]; then
101 mv "$3.dir.tmp/$2" "$3"
102 rm -rf "$3.dir.tmp"
103 else
104 rm -rf "$3.dir.tmp"
105 exit 1
106 fi
107 }
108
109 umask 077
110 cmd="$1"
111 shift
112 case "$cmd" in
113 list) mcdarfs_list "$@" ;;
114 copyout) mcdarfs_copyout "$@" ;;
115 *) exit 1 ;;
116 esac
117 exit 0