summaryrefslogtreecommitdiffstats
path: root/src/vfs/extfs/helpers/lslR.in
blob: f568c02a5f8957adf7029537e9eeec57890a4d57 (plain)
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
#! /bin/sh

# Based on previous version of lslR
# Modified by Tomas Novak <tnovak@ipex.cz>   April 2000
#   (to allow spaces in filenames)
#
# It's assumed that lslR was generated in C locale.
LC_ALL=C
export LC_ALL=C

AWK=@AWK@

mclslRfs_list () {
case "$1" in
  *.lz)  MYCAT="lzip -dc";;
  *.lz4) MYCAT="lz4 -dc";;
  *.lzma) MYCAT="lzma -dc";;
  *.lzo) MYCAT="lzop -dc";;
  *.xz)  MYCAT="xz -dc";;
  *.zst) MYCAT="zstd -dc";;
  *.bz2) MYCAT="bzip2 -dc";;
  *.gz)  MYCAT="gzip -dc";;
  *.z)   MYCAT="gzip -dc";;
  *.Z)   MYCAT="gzip -dc";;
  *)     MYCAT="cat";;
esac

MYCAT=${MC_TEST_EXTFS_LIST_CMD:-$MYCAT}  # Let the test framework hook in.

$MYCAT "$1" | $AWK '
BEGIN {
  dir="";
  empty=1;
  rx = "[^ 	]+[ 	]+";
  # Pattern to match 7 first fields.
  rx7 = "^" rx rx rx rx rx rx "[^ 	]+[ 	]";
  # Pattern to match 8 first fields.
  rx8 = "^" rx rx rx rx rx rx rx "[^ 	]+[ 	]";
}
/^total\ [0-9]*$/ { next }
/^$/ { empty=1; next }
empty==1 && /:$/ {
  empty=0
  if ($0 ~ /^\//) dir=substr($0, 2);
  else dir=$0;
  if (dir ~ /\/:$/) sub(/:$/, "", dir);
  else sub(/:$/, "/", dir);
  if (dir ~ /^[ 	]/) dir="./"dir;
  next;
}
( NF > 7 ) {
  empty=0
  # gensub() is not portable.
  name=$0
  i=index($6, "-")
  if (i) {
    sub(rx7, "", name)
    NF = 7
    $6=substr($6,i+1)"-"substr($6,1,i-1)
  }
  else {
    sub(rx8, "", name)
    NF = 8
  }
  printf "%s %s%s\n", $0, dir, name
}
 {
  empty=0
}' 
}

case "$1" in
  list) mclslRfs_list "$2"; exit 0;;
esac
exit 1