-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc-4.7.5.3-alt-extfs-udar.patch
140 lines (135 loc) · 3.83 KB
/
mc-4.7.5.3-alt-extfs-udar.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
diff --git a/lib/vfs/mc-vfs/extfs/Makefile.am b/lib/vfs/mc-vfs/extfs/Makefile.am
index d955a2c..963b8ea 100644
--- a/lib/vfs/mc-vfs/extfs/Makefile.am
+++ b/lib/vfs/mc-vfs/extfs/Makefile.am
@@ -6,7 +6,7 @@ EXTFSCONFFILES = extfs.ini sfs.ini
EXTFS_MISC = README
# Scripts hat don't need adaptation to the local system
-EXTFS_CONST = bpp rpm trpm u7z
+EXTFS_CONST = bpp rpm trpm u7z udar
# Scripts that need adaptation to the local system - source files
EXTFS_IN = \
diff --git a/lib/vfs/mc-vfs/extfs/udar b/lib/vfs/mc-vfs/extfs/udar
new file mode 100644
index 0000000..3103f82
--- /dev/null
+++ b/lib/vfs/mc-vfs/extfs/udar
@@ -0,0 +1,105 @@
+#!/bin/sh
+
+# This is a parser for Dar archives in Midnight Commander. You need
+# the GPL dar program (version >= 2.3.0) written by Denis Corbin.
+
+# Author: Guus Jansman
+
+# Limitations:
+# - The archive file can not be changed
+# - Symbolic and hard links are not handled properly
+# - Block and character special files are not handled
+# - Files not stored in (differential) backups are not handled
+# - Dar files in archives are not handled (due filename restriction)
+
+DAR=dar
+
+# dar expects the basename (without number and extension)
+BASENAME="`echo "$2" | sed -e 's/\.[0-9]*\.[Dd][Aa][Rr]$//'`"
+
+mcdarfs_list ()
+{
+$DAR -l "$BASENAME" -N -Q -as 2>/dev/null | gawk -v uuid=${UID-0} '
+BEGIN { flag=0 }
+/^-------/ { flag++; if (flag > 1) exit 0; next }
+/^$/ { next }
+{
+ if (flag == 0) next
+ line=$0
+ split(line, record, " ")
+
+ # Do not display removed files
+ if (record[1] == "[" && record[2] == "REMOVED")
+ {
+ next
+ }
+
+ # We want "line" to start with permutation
+ # TODO: better algorithm
+ while (length(record[1]) != 10 || match(substr(record[1], 2, 1), "[r-]") == 0)
+ {
+ # line without real contents
+ if (length(line) == 0) {
+ next
+ }
+ line=substr(line, length(record[1])+1)
+ while (length(line) != 0 && substr(line, 1, 1) != " ")
+ {
+ line=substr(line, 2)
+ }
+ split(line, record, " ")
+ }
+
+ perm=record[1]
+ # Block and character special files not supported
+ # Change [bc] to [bcl] if symbolic links should not show up either
+ if (match(substr(perm, 1, 1), "[bc]") != 0)
+ {
+ next
+ }
+ uid=record[2]
+ if (match(uid, "^[0-9]*$") != 0)
+ {
+ uid=sprintf("%-8d", uid)
+ }
+ gid=record[3]
+ if (match(gid, "^[0-9]*$") != 0)
+ {
+ gid=sprintf("%-8d", gid)
+ }
+ size=record[4]
+ month=record[6]
+ day=record[7]
+ tm=substr(record[8], 1, 5)
+ year=record[9]
+ name=substr(line, index(line, sprintf("%s:", tm))+14)
+ # TODO: find symbolic link target (probably the link has to be extracted)
+ printf "%s 1 %s %s %8d %3s %02d %04d %s %s\n", perm, uid, gid, size, month, day, year, tm, name
+}'
+}
+
+mcdarfs_copyout ()
+{
+ # Dummy directory necessary since dar cannot output to stdout or named file
+ mkdir "$3.dir.tmp"
+ chmod 700 "$3.dir.tmp"
+ if [ ! -d "$3.dir.tmp" ]; then exit 1; fi
+ $DAR -x "$BASENAME" -N -O -Q -wa -g "$2" -R "$3.dir.tmp" >/dev/null 2>&1
+ if [ -e "$3.dir.tmp/$2" ]; then
+ mv "$3.dir.tmp/$2" "$3"
+ rm -rf "$3.dir.tmp"
+ else
+ rm -rf "$3.dir.tmp"
+ exit 1
+ fi
+}
+
+umask 077
+cmd="$1"
+shift
+case "$cmd" in
+ list) mcdarfs_list "$@" ;;
+ copyout) mcdarfs_copyout "$@" ;;
+ *) exit 1 ;;
+esac
+exit 0
diff --git a/misc/mc.ext.in b/misc/mc.ext.in
index 4860c95..04f9873 100644
--- a/misc/mc.ext.in
+++ b/misc/mc.ext.in
@@ -654,6 +654,11 @@ regex/\.xz$
View=%view{ascii} xz -dc %f 2>/dev/null
+# dar
+regex/\.[0-9]*\.[Dd][Aa][Rr]$
+ Open=%cd %p#udar
+ View=%view{ascii} dar -l `echo %f | sed 's/\.[0-9]*\.[Dd][Aa][Rr]$//'` -N
+
### Default ###
# Default target for anything not described above