Subject: enhancement to pkg utils.
To: None <tech-pkg@netbsd.org>
From: Darren Reed <darrenr@reed.wattle.id.au>
List: tech-pkg
Date: 11/19/1998 23:57:03
Whilst using pkg_add for the first time(!) tonight, I was quite astounded
that it was rather dumb with file names.  That is, given the command
"pkg_add foo" and that the file "foo.tgz" was in the current directory,
it failed.

Then, to my amazement, "pkg_delete foo" did work, but perhaps that's not
so amazing if you pause to think about it.

In asking why pkg_add was so "dumb", nobody on icb (seemed to have much
of an idea) so I have since quickly made the hack below (see patches) to
the pkg libinstall.a.

This may even be better asked of the originator of that mess.

Darren

*** lib/lib.h.orig	Fri Aug 28 21:13:02 1998
--- lib/lib.h	Thu Nov 19 23:44:22 1998
***************
*** 135,140 ****
--- 135,141 ----
  char		*fileGetURL(char *, char *);
  char		*fileURLFilename(char *, char *, int);
  char		*fileURLHost(char *, char *, int);
+ char		*fileSearch(char *);
  char		*fileFindByPath(char *, char *);
  char		*fileGetContents(char *);
  Boolean		make_preserve_name(char *, int, char *, char *);

*** lib/file.c.orig	Fri Aug 28 21:13:02 1998
--- lib/file.c	Thu Nov 19 23:43:50 1998
***************
*** 630,632 ****
--- 630,659 ----
    
    return ftp;
  }
+ 
+ 
+ static char *suffixes[] = {
+ 	".tgz", ".tar.gz", ".tar.Z", ".tar", ".gz", ".Z",
+ 	NULL
+ };
+ 
+ 
+ char *
+ fileSearch(char *file)
+ {
+ 	char *cp, **cpp, path[MAXPATHLEN];
+ 
+ 	cp = fileFindByPath(NULL, file);
+ 	if (cp != NULL)
+ 		return cp;
+ 
+ 	for (cpp = suffixes; (cp = *cpp); cpp++) {
+ 		snprintf(path, sizeof(path) - 1, "%s%s", file, cp);
+ 		cp = fileFindByPath(NULL, path);
+ 		if (cp != NULL)
+ 			return strdup(cp);
+ 	}
+ 	return NULL;
+ }
+ 
+ 

*** add/main.c.orig	Sat Oct 18 05:23:52 1997
--- add/main.c	Thu Nov 19 23:43:17 1998
***************
*** 130,136 ****
  		if (fexists(*argv)) /* refers to a file directly */
  		    pkgs[ch] = realpath(*argv, pkgnames[ch]);
  		else {		/* look for the file in the expected places */
! 		    if (!(cp = fileFindByPath(NULL, *argv)))
  			warnx("can't find package '%s'", *argv);
  		    else
  			pkgs[ch] = strcpy(pkgnames[ch], cp);
--- 130,136 ----
  		if (fexists(*argv)) /* refers to a file directly */
  		    pkgs[ch] = realpath(*argv, pkgnames[ch]);
  		else {		/* look for the file in the expected places */
! 		    if (!(cp = fileSearch(*argv)))
  			warnx("can't find package '%s'", *argv);
  		    else
  			pkgs[ch] = strcpy(pkgnames[ch], cp);