ls 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #LIST /${FISH_DIR}
  2. export LC_TIME=C
  3. fish_list_lsq ()
  4. {
  5. FISH_DIR="$1"
  6. ls -Qlan "${FISH_DIR}" 2>/dev/null | grep '^[^cbt]' | (
  7. while read p l u g s m d y n; do
  8. echo "P$p $u.$g"
  9. echo "S$s"
  10. echo "d$m $d $y"
  11. echo ":$n"
  12. echo
  13. done
  14. )
  15. ls -Qlan "${FISH_DIR}" 2>/dev/null | grep '^[cb]' | (
  16. while read p l u g a i m d y n; do
  17. echo "P$p $u.$g"
  18. echo "E$a$i"
  19. echo "d$m $d $y"
  20. echo ":$n"
  21. echo
  22. done
  23. )
  24. echo '### 200'
  25. }
  26. fish_list_sed ()
  27. {
  28. FISH_DIR="$1"
  29. ls -lan "${FISH_DIR}" 2>/dev/null | grep '^[^cbt]' | (
  30. while read p l u g s rec; do
  31. if [ -n "$g" ]; then
  32. if [ -n "$FISH_HAVE_DATE_MDYT" ]; then
  33. filename=`echo "$rec"| sed 's/[^[:space:]]\+ \+[^[:space:]]\+ \+[^[:space:]]\+ //'`
  34. filedate=`echo "$rec"| sed 's/\([^[:space:]]\+ \+[^[:space:]]\+ \+[^[:space:]]\+\) .*/\1/'`
  35. else
  36. filename=`echo "$rec"| sed 's/[^[:space:]]\+ \+[^[:space:]]\+ //'`
  37. filedate=`echo "$rec"| sed 's/\([^[:space:]]\+ \+[^[:space:]]\+\) .*/\1/'`
  38. fi
  39. pfile=\"`echo "$filename" | sed -e 's#^\(.*\) -> \(.*\)#\1" -> "\2#'`\"
  40. echo "P$p $u.$g"
  41. echo "S$s"
  42. if [ -n "$FISH_HAVE_DATE_MDYT" ]; then
  43. echo "d$filedate"
  44. else
  45. echo "D$filedate"
  46. fi
  47. echo ":$pfile"
  48. echo
  49. fi
  50. done
  51. )
  52. ls -lan "${FISH_DIR}" 2>/dev/null | grep '^[cb]' | (
  53. while read p l u g a i rec; do
  54. if [ -n "$g" ]; then
  55. if [ -n "$FISH_HAVE_DATE_MDYT" ]; then
  56. filename=`echo "$rec"| sed 's/[^[:space:]]\+ \+[^[:space:]]\+ \+[^[:space:]]\+ //'`
  57. filedate=`echo "$rec"| sed 's/\([^[:space:]]\+ \+[^[:space:]]\+ \+[^[:space:]]\+\) .*/\1/'`
  58. else
  59. filename=`echo "$rec"| sed 's/[^[:space:]]\+ \+[^[:space:]]\+ //'`
  60. filedate=`echo "$rec"| sed 's/\([^[:space:]]\+ \+[^[:space:]]\+\) .*/\1/'`
  61. fi
  62. pfile=\"`echo "$filename" | sed -e 's#^\(.*\) -> \(.*\)#\1" -> "\2#'`\"
  63. echo "P$p $u.$g"
  64. echo "E$a$i"
  65. if [ -n "$FISH_HAVE_DATE_MDYT" ]; then
  66. echo "d$filedate"
  67. else
  68. echo "D$filedate"
  69. fi
  70. echo ":$pfile"
  71. echo
  72. fi
  73. done
  74. )
  75. echo '### 200'
  76. }
  77. fish_list_poor_ls ()
  78. {
  79. FISH_DIR="$1"
  80. ls -lan "${FISH_DIR}" 2>/dev/null | grep '^[^cbt]' | (
  81. while read p l u g s m d y n n2 n3; do
  82. if [ -n "$g" ]; then
  83. if [ "$m" = "0" ]; then
  84. s=$d; m=$y; d=$n; y=$n2; n=$n3
  85. else
  86. n=$n" "$n2" "$n3
  87. fi
  88. echo "P$p $u $g"
  89. echo "S$s"
  90. echo "d$m $d $y"
  91. echo ":"$n
  92. echo
  93. fi
  94. done
  95. )
  96. ls -lan "${FISH_DIR}" 2>/dev/null | grep '^[cb]' | (
  97. while read p l u g a i m d y n n2 n3; do
  98. if [ -n "$g" ]; then
  99. if [ "$a" = "0" ]; then
  100. a=$m; i=$d; m=$y; d=$n; y=$n2; n=$n3
  101. else
  102. n=$n" "$n2" "$n3
  103. fi
  104. echo "P$p $u $g"
  105. echo "S$s"
  106. echo "d$m $d $y"
  107. echo ":"$n
  108. echo
  109. fi
  110. done
  111. )
  112. echo '### 200'
  113. }
  114. fish_list_perl ()
  115. {
  116. FISH_DIR=$1
  117. perl -e '
  118. use strict;
  119. use POSIX;
  120. use Fcntl;
  121. use POSIX ":fcntl_h"; #S_ISLNK was here until 5.6
  122. import Fcntl ":mode" unless defined &S_ISLNK; #and is now here
  123. my $dirname = $ARGV[0];
  124. if (opendir (DIR, $dirname)) {
  125. while((my $filename = readdir (DIR))){
  126. my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat("$dirname/$filename");
  127. my $mloctime= strftime("%%m-%%d-%%Y %%H:%%M", localtime $mtime);
  128. my $strutils_shell_escape_regex = s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'\''"\ \\])/\\$1/g;
  129. my $e_filename = $filename;
  130. $e_filename =~ $strutils_shell_escape_regex;
  131. if (S_ISLNK ($mode)) {
  132. my $linkname = readlink ("$dirname/$filename");
  133. $linkname =~ $strutils_shell_escape_regex;
  134. printf("R%%o %%o $uid.$gid\nS$size\nd$mloctime\n:\"$e_filename\" -> \"$linkname\"\n\n", S_IMODE($mode), S_IFMT($mode));
  135. } else {
  136. printf("R%%o %%o $uid.$gid\nS$size\nd$mloctime\n:\"$e_filename\"\n\n", S_IMODE($mode), S_IFMT($mode));
  137. }
  138. }
  139. printf("### 200\n");
  140. closedir(DIR);
  141. } else {
  142. printf("### 500\n");
  143. }
  144. exit 0
  145. ' "/${FISH_DIR}"
  146. }
  147. if [ -n "${FISH_HAVE_PERL}" ]; then
  148. fish_list_perl "/${FISH_FILENAME}"
  149. elif [ -n "${FISH_HAVE_LSQ}" ]; then
  150. fish_list_lsq "/${FISH_FILENAME}"
  151. elif [ -n "${FISH_HAVE_SED}" ]; then
  152. fish_list_sed "/${FISH_FILENAME}"
  153. else
  154. fish_list_poor_ls "/${FISH_FILENAME}"
  155. fi