Re: extfs cleanup



First of all I would like to note, that this is my first contribution
to mc, so I don't know 'how things work' in mc too much.

> release of the next stable version.  I believe the redirection of output
> should be done in the extfs code, not in the scripts.  That's something

Of course - this is simpler and more reliable solution.

> Please make sure to use the CVS version or the current snapshot if you are

I've just downloaded the whole repository.

> Send the patches, not the whole files.  Explain all changes.

Ok. Here it comes (patches attached):

1. I agree with Standa (the next thread) that binary names/paths
shouldn't be set at compile time. Most people use binary packages, and
they may, for example, have mawk, but don't have gawk. I've fixed this
problem by looking in PATH (with type bash builtin) for either awk,
mawk or gawk. 

I think this fixes the problem, and we don't need any additional
variables - if binary isn't in one's PATH - it often simply means
isn't in the system. And no, I didn't have any problems with unzip.

2. Added DEBUG shell var, just for testing purposes.

3. Added die() function, which prints $1 on stderr and exit's with
error code 1.

4. Addedd cmd || die("Error") to any command that could fail.

5. Added binary existence check (with 'type -p binary')

6. Fixed dirty uzoo hack - symlink is no longer created in ~/.mc but
in /tmp which is better place for such file

7. Fixed urar using cp -p which always created files in archive with
perms. 600 (like mc tmp files)


If my fixes are helpful I can work on other extfs'. In fact many on
them are completly broken.


> I believe the reason is because extfs_open() issues "copyout" even when
> the file is opened with O_TRUNC.  This should be easy to fix.  I'm have 
> added a FIXME to the source.

I'll try to work on this issue - maybe this could teach me a bit of
'mc architecture'.


> You can use stderr for that in the CVS version, just don't write more that
> 4 kilobytes.

Ok, I'll try. I was working with 2002-12-04


> I still don't understand why you think "list" is different from other
> commands when is comes to error reporting.

Sorry, just checked, and it was fixed recently in CVS - now I see nice
error message. That's great.

Regards.


-- 

  _.|._ |_  _.    : Adam Byrtek, alpha@(irc.pl|debian.org)
 (_|||_)| |(_|    : gg 1802819, pgp 0xB25952C0
     |            : jid alpha.jabberpl.org
--- urar.in	2002-08-26 06:44:20.000000000 +0200
+++ urar	2002-12-06 13:49:03.000000000 +0100
@@ -5,22 +5,24 @@
 # Updated by christian gennerat alcatel fr 1999
 #            Andrew V. Samoilov <sav bcs zp ua> 2000
 # beta version 2.0
-#
-DRAR=/usr/bin
-RAR=$DRAR/rar
-UNRAR=$DRAR/unrar # Prefer unrar (freeware)
-#
-# NOTE: rar ver 2.0 by Eugene Roshal
-# ftp.elf.stuba.sk/pub/pc/pack
-#
 
-if [ ! -x $UNRAR -a -x $RAR ]; then
-    UNRAR=$RAR
-fi
+# Updated by Adam Byrtek <alpha debian org>, Dec 2002
+# (error handling, binaries detection, unnecessary output redirected
+# to /dev/null, debug, some cleanups and fixes)
+
+
+#DEBUG=YES
+
+# throw error message to stderr
+die ()
+{
+    echo $1 >&2
+    exit 1
+}
 
 mcrarfs_list ()
 {
-     $UNRAR v -c- "$1" | @AWK@ -v uid=${UID-0} '
+     $UNRAR v -c- "$1" | $AWK -v uid=${UID-0} '
 BEGIN { flag=0; date="JanFebMarAprMayJunJulAugSepOctNovDec" }
 /^-------/ { flag++; if (flag > 1) exit 0; next }
 {
@@ -41,62 +43,102 @@
 	    $6="-rw-r--r--"
     printf "%s   1 %-8d %-8d %8d %3s %2d %4d %s %s\n", $6, uid, 0, $1, substr(date, (a[2]-1)*3+1, 3), a[1], a[3], $5, str
 }
-}' 2>/dev/null
+}' 2>/dev/null || die "List: archive error."
 }
 
 mcrarfs_copyin ()
 {
+    if [ -z $RAR ]; then
+        die "Copyin: binary 'rar' not found, sorry."
+    fi
+
 # copyin by christian gennerat alcatel fr
 # preserve pwd. It is clean, but is it necessary?
     pwd=`pwd`
-# Create a directory and copy in it the tmp file with the good name     
-    mkdir $3.dir
+# Create a directory and copy in it the tmp file with the good name
+    mkdir $3.dir &> /dev/null || die "Copyin: permision denied."
     cd $3.dir
     di="${2%/*}"
 # if file is to be written upper in the archive tree, make fake dir
     if test "$di" != "${2##*/}" ; then
         mkdir -p "$di" 
     fi
-# (cp -p) to preserve date, but $2 is dated now!
-    cp -p $3 "$3.dir/$2" 
-    $RAR a "$1" "$2" >/dev/null
+# (cp -p) to preserve date, but $2 is dated now! [ -p breaks mode - alpha ]
+    cp $3 "$3.dir/$2" 
+    $RAR a "$1" "$2" &>/dev/null || die "Copyin: archive error. Delete $3.dir"
     cd $pwd
     rm -rf $3.dir
 }
 
 mcrarfs_copyout ()
 {
-    $UNRAR p -c- -inul "$1" "$2" > $3 2>/dev/null
+    $UNRAR p -c- -inul "$1" "$2" > $3 2>/dev/null || die "Copyout: archive error."
 }
 
 mcrarfs_mkdir ()
 {
+    if [ -z $RAR ]; then
+        die "Mkdir: binary 'rar' not found, sorry."
+    fi
+    
 # preserve pwd. It is clean, but is it necessary?
     pwd=`pwd`
 # Create a directory and create in it a tmp directory with the good name     
     dir=tmpdir.${RANDOM}
-    mkdir $dir
+    mkdir $dir &>/dev/null || die "Mkdir: permision denied."
     cd $dir
     mkdir -p "$2"  
 # rar cannot create an empty directory    
     touch "$2"/.rarfs
-    $RAR a -r "$1" "$2" &>/dev/null
-    $RAR d "$1" "$2"/.rarfs &>/dev/null
+    $RAR a -r "$1" "$2" &>/dev/null || die "Mkdir: archive error. Delete $dir."
+    $RAR d "$1" "$2"/.rarfs &>/dev/null || die "Mkdir: archive error. Delete $dir."
     cd $pwd
     rm -rf $dir
 }
 
 mcrarfs_rm ()
 {
-    $RAR d "$1" "$2" &>/dev/null
+    if [ -z $RAR ]; then
+        die "Rm: binary 'rar' not found, sorry."
+    fi
+
+    $RAR d "$1" "$2" &>/dev/null || die "Rm: archive error"
 }
 
+
+# debug
+if [ x$DEBUGx == xYESx ]; then
+    echo $0 $1 $2 $3 $4 >> /tmp/mcdebug
+fi
+
+# chceck neccesary binaries
+# prefer unrar (freeware)
+UNRAR=`type -p unrar`
+if [ -z $UNRAR ]; then
+    UNRAR=`type -p rar`
+    if [ -z $UNRAR ]; then
+        die "Binary 'rar/unrar' not found, sorry."
+    fi
+fi
+RAR=`type -p rar`
+
+AWK=`type -p awk`
+if [ -z $AWK ]; then
+    AWK=`type -p mawk`
+    if [ -z $AWK ]; then
+        AWK=`type -p gawk`
+        if [ -z $AWK ]; then
+            die "Binary 'awk/mawk/gawk' not found, sorry."
+        fi
+    fi
+fi
+
 umask 077
 
 # uncomment this line for debugging
 #echo "`date +%T` ${0##*/} $1 $2 to=$3 tmp=$4" >>/tmp/${0##*/}.log
 case "$1" in
-  list)    mcrarfs_list    "$2" | sort +9 ; exit 0;;
+  list)    mcrarfs_list    "$2"; exit 0;;
   rm)      mcrarfs_rm      "$2" "$3" ; exit 0;;
   rmdir)   mcrarfs_rm      "$2" "$3" ; exit 0;;
   mkdir)   mcrarfs_mkdir   "$2" "$3" ; exit 0;;
--- uzoo.in	2000-09-21 22:58:11.000000000 +0200
+++ uzoo	2002-12-06 13:48:39.000000000 +0100
@@ -1,19 +1,28 @@
 #! /bin/sh
 #
 # Zoo file system
-#
 # Copyright ? U. N. Known
 #
 # This filesystem is _dangerous_. It used to create symlinks in filesystem
 # with zoo file, it used to happily delete file from your filesystem.
 # Now it is 'only' very ugly (it creates temporary files in ~/.mc/
-#
 
-ZOO=zoo
+# Updated by Adam Byrtek <alpha debian org>, Dec 2002
+# (error handling, binaries detection, unnecessary output redirected
+# to /dev/null, some cleanups and fixes)
+
+#DEBUG=YES
+
+# throw error message to stderr
+die ()
+{
+    echo $1 >&2
+    exit 1
+}
 
 mczoofs_list ()
 {
-    $ZOO l $1 | @AWK@ -v uid=${UID-0} '
+    $ZOO l $1 | $AWK -v uid=${UID-0} '
 BEGIN { hyphens=0 }
 /^---/ { if (hyphens > 0) exit 0; hyphens=1; next }
 /^[^\ ]/ { next }
@@ -31,39 +40,58 @@
     printf "drwxr-xr-x   1 %-8d %-8d %8d %s %2d %4d %02d:%02d %s\n", uid, 0, $1, $5, $4, $6, a[1], a[2], $8
 else
     printf "-rw-r--r--   1 %-8d %-8d %8d %s %2d %4d %02d:%02d %s\n", uid, 0, $1, $5, $4, $6, a[1], a[2], $8
-}' 2>/dev/null
+}' 2>/dev/null || die "List: archive error."
     exit 0
 }
 
 mczoofs_copyout ()
 {
-    $ZOO xp $1 $2 | tail +6l > $3 2>/dev/null
+    $ZOO xp $1 $2 | tail +6l > $3  2> /dev/null || die "Copyout: archive error."
     exit 0
 }
 
+
+
+# debug
+if [ x$DEBUGx == xYESx ]; then
+    echo $0 $1 $2 $3 $4 >> /tmp/mcdebug
+fi
+
+# chceck neccesary binaries
+
+ZOO=`type -p zoo`
+if [ -z $ZOO ]; then
+    die "Binary 'zoo' not found, sorry. $1"
+fi
+
+AWK=`type -p awk`
+if [ -z $AWK ]; then
+    AWK=`type -p mawk`
+    if [ -z $AWK ]; then
+        AWK=`type -p gawk`
+        if [ -z $AWK ]; then
+            die "Binary 'awk/mawk/gawk' not found, sorry."
+        fi
+    fi
+fi
+
+
 # zoo is stupid and won't be happy when the name has no extension.
-# We have to do a small trick :) [pretty dirty, broken hack -- pavel]
-if echo $2 | grep '\.zoo$' >/dev/null; then
-  :
+# we have to do a small trick :)
+
+if echo $2 | grep '\.zoo$' &>/dev/null; then
+  ARCHIVE=$2
 else
-  SYMLINK=$HOME/.mc/temporary.$2.zoo
-  if test -f $SYMLINK; then
-    SYMLINK=$HOME/.mc/temporary.$2.
-  fi
-  if test -f $SYMLINK; then
-    echo "Ugh. I did not expect this to happen. Cleanup your ~/.mc."
-    sleep 5
-    exit 1
-  fi
-  ln -s $2 $SYMLINK
-  trap 'rm -f $SYMLINK' 0 1 2 3 5 13 15
-  $2=$SYMLINK
+  SYMLINK=/tmp/mc-uzoo-tmp.zoo
+  ln -fs $2 $SYMLINK &>/dev/null || die "Error. Is your /tmp writable?"
+  trap 'rm -f $SYMLINK &>/dev/null' 0 1 2 3 5 13 15
+  ARCHIVE=$SYMLINK
 fi
 
 umask 077
 
 case "$1" in
-  list) mczoofs_list $2; exit $?;;
-  copyout) mczoofs_copyout $2 $3 $4; exit $?;;
+  list) mczoofs_list $ARCHIVE; exit $?;;
+  copyout) mczoofs_copyout $ARCHIVE $3 $4; exit $?;;
 esac
 exit 1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]