ls 4.4 KB

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