Ticket #2471: isoinfo adds ";1" to the end of file name when Joliet w/o Rock Ridge...
[midnight-commander.git] / lib / vfs / mc-vfs / extfs / iso9660.in
blob964c4f8a33d67a8368399104306366b71771adec
1 #! /bin/sh
3 # ISO9660 VFS for MC by Michael Shigorin <mike@altlinux.org>,
4 # modifications by Grigory Milev <week@altlinux.org>
5 # and Kachalov Anton <mouse@linux.ru.net> April 2003
6 # based on lslR by Tomas Novak <tnovak@ipex.cz> April 2000
7 # -- look there for additional parsing comments if needed
9 # tested to comply with isoinfo 2.0's output
11 test_iso () {
12 CHARSET=`locale charmap 2>/dev/null`
13 if test -z "$CHARSET"; then
14 CHARSET=`locale 2>/dev/null | @GREP@ LC_CTYPE | sed -n -e 's/.*\.\(.*\)"$/\1/p'`
16 if test -n "$CHARSET"; then
17 CHARSET=`echo "$CHARSET" | tr '[A-Z]' '[a-z]' | sed -e 's/^iso-/iso/'`
18 isoinfo -j $CHARSET -i /dev/null 2>&1 | @GREP@ "Iconv not yet supported\|Unknown charset" >/dev/null && CHARSET=
20 if test -n "$CHARSET"; then
21 JOLIET_OPT="-j $CHARSET -J"
22 else
23 JOLIET_OPT="-J"
25 ISOINFO="isoinfo -R"
26 isoinfo -d -i "$1" 2>/dev/null | @GREP@ "UCS level 1\|NO Joliet" > /dev/null || ISOINFO="$ISOINFO $JOLIET_OPT"
28 if [ `isoinfo -d -i "$1" 2>/dev/null | @GREP@ "Joliet with UCS level 3 found" | wc -l` == 1 ] ; then
29 if [ `isoinfo -d -i "$1" 2>/dev/null | @GREP@ "NO Rock Ridge" | wc -l` == 1 ] ; then
30 SEMICOLON="YES"
35 mcisofs_list () {
36 # left as a reminder to implement compressed image support =)
37 case "$1" in
38 *.lzma) MYCAT="lzma -dc";;
39 *.xz) MYCAT="xz -dc";;
40 *.bz2) MYCAT="bzip2 -dc";;
41 *.gz) MYCAT="gzip -dc";;
42 *.z) MYCAT="gzip -dc";;
43 *.Z) MYCAT="gzip -dc";;
44 *) MYCAT="cat";;
45 esac
47 $ISOINFO -l -i "$1" 2>/dev/null | @AWK@ -v SEMICOLON=$SEMICOLON '
48 BEGIN {
49 dir="";
50 # Pattern to match 8 first fields.
51 rx = "[^ ]+[ ]+";
52 rx = "^" rx rx rx rx rx rx rx rx;
53 irx = "^\\[ *-?[0-9]* *[0-9]+\\] +";
55 /^$/ { next }
56 /^d---------/ { next }
57 /^Directory listing of [^ ].*$/ {
58 dir=substr($0, 23);
59 next;
61 { $11 != "" } {
62 name=$0
63 sub(rx, "", name)
64 attr=substr($0, 1, length($0)-length(name))
65 # strip inodes and extra dir entries; fix perms
66 sub(irx, "", name)
67 sub("^---------- 0 0 0", "-r--r--r-- 1 root root", attr)
68 sub(" $", "", name)
69 # for Joliet UCS level 3
70 if (SEMICOLON = "YES") sub(";1$", "", name);
71 ## sub(";[0-9]+$", "", name) ## would break copyout
72 # skip . and ..
73 if (name ~ /^\.\.?/) next;
74 printf "%s%s%s\n", attr, dir, name
75 }'
78 mcisofs_copyout () {
79 if [ "x$SEMICOLON" == "xYES" ]; then
80 $ISOINFO -i "$1" -x "/$2;1" 2>/dev/null > "$3"
81 else
82 $ISOINFO -i "$1" -x "/$2" 2>/dev/null > "$3"
86 LC_ALL=C
88 cmd="$1"
89 shift
91 case "$cmd" in
92 list)
93 test_iso "$@";
94 mcisofs_list "$@";
95 exit 0;;
96 copyout)
97 test_iso "$@";
98 mcisofs_copyout "$@";
99 exit 0;;
100 esac
101 exit 1