home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / bugs / 4bsd / 239 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  5.6 KB

  1. Path: sparky!uunet!pipex!unipalm!uknet!edcastle!mfg
  2. From: mfg@castle.ed.ac.uk (M Gordon)
  3. Newsgroups: comp.bugs.4bsd
  4. Subject: Re: A serious bug in unix2dos/dos2unix
  5. Message-ID: <29611@castle.ed.ac.uk>
  6. Date: 16 Dec 92 09:26:46 GMT
  7. References: <1992Dec12.224109.15621@cs.mcgill.ca> <2527@ispi.COM>
  8. Organization: Edinburgh University
  9. Lines: 189
  10.  
  11. jbayer@ispi.COM (Jonathan Bayer) writes:
  12.  
  13. >haiying@cs.mcgill.ca (Haiying ZHANG) writes:
  14.  
  15.  
  16. >>   I came across this bug a while ago. This has to do with using wild
  17. >>card in file names with unix2dos/dos2unix.
  18.  
  19. >>   If you use a wild card in the file name, be it a single * or a ?
  20. >>embedded in a pattern, these two handy utilities will wipe out your
  21. >>entire current directory with the exception of the first file. It will
  22. >>set all the rest of the file to size 0. 
  23.  
  24. >>   Although the man page does mention anything about wild card in
  25. >>filename making one believe that it is not supported, it should not in
  26. >>any case cause serious damaging to your files. While I am at it, these
  27. >>two programs look like a recompile of its DOS version. It should have
  28. >>provided more - options such as -Rfp etc. as in cp. 
  29.  
  30.  
  31. >First, what system are you running on?  Second, what are you trying to do?
  32. >On a Sun system the dos2unix command is designed to operate on ONE file only,
  33. >sending the output to the second file specification.  The wild cards are
  34. >expanded by the shell, and all the program sees is a long list of filenames.
  35.  
  36.  
  37. Running dos2unix with wildcards is incorrect, but it still shouldn't
  38. destroy all of the other files.  Having seen the source for dos2unix,
  39. what it does (at least on the Sun version) is
  40.  
  41.     for each argument
  42.       if it's an option
  43.     process it
  44.       else
  45.     if it's the first time we've seen a filename
  46.       open it for reading
  47.     else
  48.       open it for writing
  49.  
  50.  
  51. This is definitely a bug - it will process the first file on the
  52. command line, with output going into the last file, and truncate the
  53. others to zero length.  I ended up writing a script to process
  54. multiple files, which is appended below in a shar archive with a
  55. manual page.  The script should be installed as dos2unixdir, with
  56. a link to it called unix2dosdir.
  57.  
  58.  
  59. --------------------------------------------------------------------------------
  60. #    This is a shell archive.
  61. #    Remove everything above and including the cut line.
  62. #    Then run the rest of the file through sh.
  63. #----cut here-----cut here-----cut here-----cut here-----
  64. #!/bin/sh
  65. # shar:    Shell Archiver
  66. #    Run the following text with /bin/sh to create:
  67. #    dos2unixdir.1
  68. #    dos2unixdir
  69. # This archive created: Wed Dec 16 09:20:28 1992
  70. cat << \SHAR_EOF > dos2unixdir.1
  71. .TH  "DOS2UNIXDIR" "1L" "14th November 1991" "uk.ac.ed.ee"  "LOCAL commands"
  72. .SH NAME
  73. dos2unixdir
  74. .sp 1
  75. unix2dosdir \- run conversion programs on directory trees.
  76. .SH SYNOPSIS
  77. \fBdos2unixdir\fP \fI[-v] input-dir [output-dir]\fP
  78. .br
  79. \fBunix2dosdir\fP \fI[-v] input-dir [output-dir]\fP
  80. .SH DESCRIPTION
  81. \fBDos2unixdir\fP copies the directory tree rooted at \fIinput-dir\fP
  82. to \fIoutput-dir\fP,
  83. running the command \fIdos2unix -ascii -7\fP on each one.
  84. If \fIoutput-dir\fP is not given the files will be converted in place.
  85. The \fI-v\fP option makes \fBdos2unixdir\fP print the name of each file
  86. as it converts it.
  87. .PP
  88. \fBUnix2dosdir\fP is identical to \fBdos2unixdir\fP,
  89. except that it runs \fIunix2dos -ascii -7\fP on the files.
  90. .SH NOTES
  91. If \fIoutput-dir\fP is not empty the converter will only be run on files 
  92. that have been copied from \fIinput-dir\fP.
  93. To convert all of the files in a directory run \fBdos2unixdir\fP with one
  94. directory argument.
  95. .SH AUTHOR
  96. support@uk.ac.ed.ee : MFG
  97. SHAR_EOF
  98. cat << \SHAR_EOF > dos2unixdir
  99. #!/bin/sh
  100.  
  101. # A function to make a directory hierarchy - mostly taken from X11 mkdirhier
  102. mkdirhier ()
  103. {
  104.     parts=`echo $1 | sed 's/\(.\)\/\(.\)/\1 \2/g`
  105.  
  106.     path=""
  107.     for d in $parts
  108.     do
  109.         if [ "$path" = "" ]
  110.         then
  111.             dir=$d
  112.         else
  113.             dir=$path/$d
  114.         fi
  115.  
  116.         if [ ! -d $dir ]
  117.         then
  118.             [ "$verbose" = "yes" ] && echo "Making $dir" 
  119.             mkdir $dir
  120.         fi
  121.  
  122.         path=$dir
  123.     done
  124. }
  125.  
  126.  
  127. verbose=no
  128. progname=`expr $0 : '.*/\(.*\)'`
  129. conv_options="-ascii -7"
  130. if [ "$progname" = "dos2unixdir" ]
  131. then
  132.     conv=dos2unix
  133. elif [ "$progname" = "unix2dosdir" ]
  134. then
  135.     conv=unix2dos
  136. else
  137.     echo "Conversion program started with name $progname"
  138.     echo "I only understand being started as dos2unixdir or unix2dosdir"
  139.     exit 1
  140. fi
  141.  
  142. if [ "$1" = "-v" ]
  143. then
  144.     verbose=yes
  145.     shift
  146. fi
  147. topindir=$1
  148. topoutdir=$2
  149.  
  150. if [ ! -d $topindir ]
  151. then
  152.     echo "$0: $topindir - not a directory or doesn't exist"
  153.     exit 1
  154. fi
  155.  
  156. # If the input directory is a symbolic link (e.g. ~/floppy) find won't
  157. # follow it. Find doesn't have an option to make it follow symbolic
  158. # links so the following hack is necessary.
  159. [ -h $topindir ] && topindir="$topindir/."
  160.  
  161. if [ $# -eq 1 ]
  162. then
  163.     for infile in `find $topindir -type f -print`
  164.     do
  165.         [ "$verbose" = "yes" ] && echo $infile
  166.         $conv $conv_options $infile $infile
  167.     done
  168. elif [ $# -eq 2 ]
  169. then
  170.     if [ ! -d $topoutdir ]
  171.     then
  172.         echo "$0: $topoutdir - not a directory or doesn't exist"
  173.         exit 1
  174.     fi
  175.  
  176.     for infile in `find $topindir -type f -print`
  177.     do
  178.         reloutfile=`expr $infile : "$topindir/\(.*\)"`
  179.         reloutdir=`dirname $reloutfile`
  180.         outdir=$topoutdir/$reloutdir
  181.         baseoutfile=`basename $infile`
  182.         outfile=$outdir/$baseoutfile
  183.         [ ! -d $outdir ] && mkdirhier $outdir
  184.         [ "$verbose" = "yes" ] && echo $outfile
  185.         $conv $conv_options $infile $outfile
  186.     done
  187. else
  188.     echo "usage: $0 [-v] input-directory [output-directory]"
  189.     exit 1
  190. fi
  191. SHAR_EOF
  192. #    End of shell archive
  193. exit 0
  194.  
  195. --------------------------------------------------------------------------------
  196. -- 
  197. Michael Gordon - mfg@castle.ed.ac.uk OR ee.ed.ac.uk
  198. Computing Officer, EE Dept, Edinburgh University
  199. It's not an optical illusion, it just looks like one
  200.