[net.notes] archiver.c bugs

alb (08/07/82)

I found two bugs this morning in archiver.c  Both occur if you
use the -d (delete only/don't archive) option to nfarchive.
In the first one, archiver.c tries to open the file in which the
archived notes would be if you hadn't specified the -d option.
This fails, because it never created the directory (first time
I ran it) for it.  The problem occurs because archiver.c checks
to see if it should make the directory (if the -d is not specified
and the directory does not exist, it makes it) but does not check to
see whether the -d flag has been specified before creating the archive
file.  If the directory does not exist when it tries to create the
file, it dumps.  The fix is simple.  Move the lines fopen()'ing and
fclose()'ing farchfile into the block of code above them that check
to see whether or not the -d flag was given.  (See the diff -c script
later on in this 'notes')

The second bug is in a printf() statement that is called when -d
has been given.  It tries to print an integer using %n; change
this to %d (line 145).

Following is a diff -c script of oarchiver.c and archiver.c after
I put these two fixes in:
*** oarchiver.c	Sat Aug  7 11:37:48 1982
--- archiver.c	Sat Aug  7 11:54:25 1982
***************
*** 82,87
  	    close (archfid);
  	    return - 1;					/* did not archive */
  	}
      }
  
      lock (&io, 'n');					/* would be a good idea */

--- 82,88 -----
  	    close (archfid);
  	    return - 1;					/* did not archive */
  	}
+ 	x ((farchfile = fopen (line, "w")) == NULL, "archiver: bad create");
      }
  
      lock (&io, 'n');					/* would be a good idea */
***************
*** 85,91
      }
  
      lock (&io, 'n');					/* would be a good idea */
-     x ((farchfile = fopen (line, "w")) == NULL, "archiver: bad create");
  /*
   * 	this open races with above check - can archive twice! 
   */

--- 86,91 -----
      }
  
      lock (&io, 'n');					/* would be a good idea */
  /*
   * 	this open races with above check - can archive twice! 
   */
***************
*** 108,113
  							/* save base note */
  	    dmprall (&io, &note, i, farchfile, NODETAIL);
  							/* save resps */
  	}
  	delnote (&io, i, NOLOCKIT);			/* delete entry */
  	ncount++;

--- 108,114 -----
  							/* save base note */
  	    dmprall (&io, &note, i, farchfile, NODETAIL);
  							/* save resps */
+ 	    x (fclose (farchfile) < 0, "archiver: close archive");
  	}
  	delnote (&io, i, NOLOCKIT);			/* delete entry */
  	ncount++;
***************
*** 113,119
  	ncount++;
      }
  
-     x (fclose (farchfile) < 0, "archiver: close archive");
  
      compress (&io, NOLOCKIT);				/* compress what's left */
      printf ("\n");					/* compress leaves you hanging */

--- 114,119 -----
  	ncount++;
      }
  
  
      compress (&io, NOLOCKIT);				/* compress what's left */
      printf ("\n");					/* compress leaves you hanging */
***************
*** 141,147
  	printf ("Archived: %s: %d notes into file %s at %s\n",
  		nfname, ncount, archfile, timeline);
      else
! 	printf ("Archiver deleted from %s %n notes at %s\n",
  		nfname, ncount, timeline);
      return 0;						/* and return */
  

--- 141,147 -----
  	printf ("Archived: %s: %d notes into file %s at %s\n",
  		nfname, ncount, archfile, timeline);
      else
! 	printf ("Archiver deleted from %s %d notes at %s\n",
  		nfname, ncount, timeline);
      return 0;						/* and return */