tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg_install: move pkgdb under ${PREFIX}



Hi!

At the last pkgsrcCon (in 2019), pkgsrc-pmc decided to move the pkgdb
from its current default location (/var/db/pkg) to a location under
${PREFIX}.

It took me a while to get to it, but I've now prepared a patch set for
this change.

Following prior art (jperkin's bulk build packages), I've used
${PREFIX}/.pkgdb. Shortly after I made my patch, jmmv made a good
point about ${PREFIX}/libdata/pkgdb[1] in which he also made some good
arguments about the location under ${PREFIX}.

For migration, I've made the pkgsrc infrastructure and pkg_install
stop in the revelant places to let the admin know that they should
move the directory to the new location (including the actual command
to execute: "mv /var/db/pkg ${PREFIX}/.pkgdb") to make it clear and
easy to fix.

Please review the attached patch.

Thanks,
 Thomas


[1] https://jmmv.dev/2020/08/pkgdb-libdata-var.html
Index: mk/pbulk/pbulk.sh
===================================================================
RCS file: /cvsroot/pkgsrc/mk/pbulk/pbulk.sh,v
retrieving revision 1.8
diff -u -r1.8 pbulk.sh
--- mk/pbulk/pbulk.sh	29 Oct 2018 02:47:08 -0000	1.8
+++ mk/pbulk/pbulk.sh	28 Aug 2020 16:50:53 -0000
@@ -40,7 +40,7 @@
 
 # setting pkgdb directory:
 if [ -n "$unprivileged" -o -n "${PREFIX}" ]; then
-: ${PKGDBDIR:=${PREFIX}/var/db/pkg} 
+: ${PKGDBDIR:=${PREFIX}/.pkgdb} 
 fi
 
 # Do it early since adding it after it fails is problematic:
Index: mk/pkgformat/pkg/depends.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/pkgformat/pkg/depends.mk,v
retrieving revision 1.11
diff -u -r1.11 depends.mk
--- mk/pkgformat/pkg/depends.mk	14 Jan 2020 22:22:34 -0000	1.11
+++ mk/pkgformat/pkg/depends.mk	28 Aug 2020 16:50:54 -0000
@@ -188,8 +188,12 @@
 # _pkgformat-install-dependencies:
 #	Installs any missing dependencies.
 #
+# The ${TEST} at the beginning is for the default change for the
+# database directory from /var/db/pkg to ${PREFIX}/.pkgdb in August 2020.
+#
 _pkgformat-install-dependencies: .PHONY ${_DEPENDS_FILE}
 	${RUN}								\
+	${TEST} -n "${PKG_DBDIR_ERROR}" && ${ERROR_MSG} ${PKG_DBDIR_ERROR:Q} && exit 1; \
 	exec 3<&0;							\
 	${CAT} ${_DEPENDS_FILE} | 					\
 	while read type pattern dir; do					\
Index: mk/pkgformat/pkg/pkgformat-vars.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/pkgformat/pkg/pkgformat-vars.mk,v
retrieving revision 1.8
diff -u -r1.8 pkgformat-vars.mk
--- mk/pkgformat/pkg/pkgformat-vars.mk	12 Jan 2020 23:38:42 -0000	1.8
+++ mk/pkgformat/pkg/pkgformat-vars.mk	28 Aug 2020 16:50:54 -0000
@@ -16,7 +16,11 @@
 .endif
 
 # This is the package database directory for the default view.
-PKG_DBDIR?=		/var/db/pkg
+PKG_DBDIR?=		${PREFIX}/.pkgdb
+
+.if exists(/var/db/pkg) && !exists(${PKG_DBDIR})
+PKG_DBDIR_ERROR=	The default package database directory has changed. Please run: mv /var/db/pkg ${PKG_DBDIR}
+.endif
 
 # _PKG_DBDIR is the actual packages database directory where we register
 # packages.
@@ -32,11 +36,7 @@
 LINKFARM_CMD?=		${PKG_TOOLS_BIN}/linkfarm
 
 # Latest versions of tools required for correct pkgsrc operation.
-.if !empty(USE_PKG_ADMIN_DIGEST:M[Yy][Ee][Ss])
-PKGTOOLS_REQD=		20191008
-.else
-PKGTOOLS_REQD=		20100914
-.endif
+PKGTOOLS_REQD=		20200828
 # Latest version of pkg_install required to extract packages
 PKGTOOLS_VERSION_REQD=	20091115
 
Index: mk/pkgformat/pkg/register-dependencies
===================================================================
RCS file: /cvsroot/pkgsrc/mk/pkgformat/pkg/register-dependencies,v
retrieving revision 1.1
diff -u -r1.1 register-dependencies
--- mk/pkgformat/pkg/register-dependencies	15 Oct 2011 00:23:09 -0000	1.1
+++ mk/pkgformat/pkg/register-dependencies	28 Aug 2020 16:50:54 -0000
@@ -18,14 +18,14 @@
 # ENVIRONMENT
 #	PKG_DBDIR
 #		This is the package meta-data directory in which the
-#		packages are registered.  By default, this is /var/db/pkg.
+#		packages are registered.  By default, this is ${PREFIX}/.pkgdb .
 #
 ######################################################################
 
 : ${AWK:=awk}
 : ${CP:=cp}
 : ${ECHO:=echo}
-: ${PKG_DBDIR:=/var/db/pkg}
+: ${PKG_DBDIR:=${PREFIX}/.pkgdb}
 : ${RM:=rm}
 : ${TEST:=test}
 : ${TOUCH:=touch}
Index: pkgtools/pkg_install/Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/Makefile,v
retrieving revision 1.231
diff -u -r1.231 Makefile
--- pkgtools/pkg_install/Makefile	9 Aug 2020 21:40:42 -0000	1.231
+++ pkgtools/pkg_install/Makefile	28 Aug 2020 16:50:54 -0000
@@ -81,7 +81,7 @@
 MAKE_ENV+=		CATMAN_SECTION_SUFFIX=${CATMAN_SECTION_SUFFIX:Q}
 MAKE_ENV+=		MANINSTALL=${MANINSTALL:Q}
 
-PKG_DBDIR?=		/var/db/pkg
+PKG_DBDIR?=		${PREFIX}/.pkgdb
 EGDIR=			${PREFIX}/share/examples/pkg_install
 
 PLIST_SUBST+=		PKG_DBDIR=${PKG_DBDIR}
Index: pkgtools/pkg_install/files/configure
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/configure,v
retrieving revision 1.44
diff -u -r1.44 configure
--- pkgtools/pkg_install/files/configure	1 Jul 2020 10:15:20 -0000	1.44
+++ pkgtools/pkg_install/files/configure	28 Aug 2020 16:50:54 -0000
@@ -1344,7 +1344,7 @@
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
-  --with-pkgdbdir=DIR     Where to put the pkg database (/var/db/pkg)
+  --with-pkgdbdir=DIR     Where to put the pkg database (PREFIX/.pkgdb)
  --with-ssl		Enable OpenSSL based signature support
 
 Some influential environment variables:
@@ -4025,7 +4025,7 @@
 if test "${with_pkgdbdir+set}" = set; then :
   withval=$with_pkgdbdir;  pkgdbdir="$with_pkgdbdir"
 else
-   pkgdbdir="/var/db/pkg"
+   pkgdbdir="${prefix}/.pkgdb"
 fi
 
 
Index: pkgtools/pkg_install/files/configure.ac
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/configure.ac,v
retrieving revision 1.43
diff -u -r1.43 configure.ac
--- pkgtools/pkg_install/files/configure.ac	1 Jul 2020 10:15:20 -0000	1.43
+++ pkgtools/pkg_install/files/configure.ac	28 Aug 2020 16:50:54 -0000
@@ -39,9 +39,9 @@
 
 dnl Set the default pkg dbdir
 AC_ARG_WITH(pkgdbdir,
-[  --with-pkgdbdir=DIR     Where to put the pkg database (/var/db/pkg)],
+[  --with-pkgdbdir=DIR     Where to put the pkg database (PREFIX/.pkgdb)],
 [ pkgdbdir="$with_pkgdbdir" ],
-[ pkgdbdir="/var/db/pkg" ])
+[ pkgdbdir="${prefix}/.pkgdb" ])
 AC_SUBST(pkgdbdir)
 
 AC_ARG_WITH(ssl,
Index: pkgtools/pkg_install/files/admin/check.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/admin/check.c,v
retrieving revision 1.10
diff -u -r1.10 check.c
--- pkgtools/pkg_install/files/admin/check.c	22 Jan 2010 13:30:41 -0000	1.10
+++ pkgtools/pkg_install/files/admin/check.c	28 Aug 2020 16:50:54 -0000
@@ -77,7 +77,7 @@
 static int checkpattern_fn(const char *, void *);
 
 /*
- * Assumes CWD is in /var/db/pkg/<pkg>!
+ * Assumes CWD is in the database directory ($PREFIX/.pkgdb/<pkg>)!
  */
 static void 
 check1pkg(const char *pkgdir, int *filecnt, int *pkgcnt)
Index: pkgtools/pkg_install/files/admin/pkg_admin.1
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/admin/pkg_admin.1,v
retrieving revision 1.38
diff -u -r1.38 pkg_admin.1
--- pkgtools/pkg_install/files/admin/pkg_admin.1	11 Oct 2019 11:57:41 -0000	1.38
+++ pkgtools/pkg_install/files/admin/pkg_admin.1	28 Aug 2020 16:50:54 -0000
@@ -28,7 +28,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 8, 2019
+.Dd August 22, 2020
 .Dt PKG_ADMIN 1
 .Os
 .Sh NAME
@@ -295,9 +295,9 @@
 .Xr pkg_install.conf 5
 for options, that can also be specified using the environment.
 .Sh FILES
-.Bl -tag -width /var/db/pkg/pkgdb.byfile.db -compact
-.It Pa /var/db/pkg/pkgdb.byfile.db
-.It Pa /var/db/pkg/\*[Lt]pkg\*[Gt]/+CONTENTS
+.Bl -tag -width @PREFIX@/.pkgdb/pkgdb.byfile.db -compact
+.It Pa @PREFIX@/.pkgdb/pkgdb.byfile.db
+.It Pa @PREFIX@/.pkgdb/\*[Lt]pkg\*[Gt]/+CONTENTS
 .El
 .Sh SEE ALSO
 .Xr pkg_add 1 ,
Index: pkgtools/pkg_install/files/lib/Makefile.in
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/Makefile.in,v
retrieving revision 1.36
diff -u -r1.36 Makefile.in
--- pkgtools/pkg_install/files/lib/Makefile.in	19 Apr 2017 21:42:50 -0000	1.36
+++ pkgtools/pkg_install/files/lib/Makefile.in	28 Aug 2020 16:50:54 -0000
@@ -32,6 +32,7 @@
 	str.o var.o version.o vulnerabilities-file.o xwrapper.o
 
 CPPFLAGS+=	-DSYSCONFDIR=\"$(sysconfdir)\"
+CPPFLAGS+=	-DPREFIX=\"$(prefix)\"
 
 .if !empty(BOOTSTRAP)
 CPPFLAGS+=	-DBOOTSTRAP
Index: pkgtools/pkg_install/files/lib/pkgdb.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/pkgdb.c,v
retrieving revision 1.39
diff -u -r1.39 pkgdb.c
--- pkgtools/pkg_install/files/lib/pkgdb.c	20 Apr 2010 21:22:38 -0000	1.39
+++ pkgtools/pkg_install/files/lib/pkgdb.c	28 Aug 2020 16:50:54 -0000
@@ -70,12 +70,9 @@
  * Where we put logging information by default if PKG_DBDIR is unset.
  */
 #ifndef DEF_LOG_DIR
-#define DEF_LOG_DIR		"/var/db/pkg"
+#define DEF_LOG_DIR		PREFIX "/.pkgdb"
 #endif
 
-/* just in case we change the environment variable name */
-#define PKG_DBDIR		"PKG_DBDIR"
-
 static DB   *pkgdbp;
 static char pkgdb_dir_default[] = DEF_LOG_DIR;
 static char *pkgdb_dir = pkgdb_dir_default;
@@ -303,8 +300,21 @@
 const char *
 pkgdb_get_dir(void)
 {
+	/* Except for the return at this end, this code is for
+	   migration from the previous location /var/db/pkg to the new
+	   default (August 2020). */
+
+	struct stat sb;
+	if (strcmp(pkgdb_dir, DEF_LOG_DIR) == 0 &&
+	    stat(pkgdb_dir, &sb) == -1 && errno == ENOENT &&
+	    stat("/var/db/pkg", &sb) == 0) {
+		errx(EXIT_FAILURE,
+		     "The default PKG_DBDIR has changed, but this installation still uses the old one\n"
+		     "Please move the database and re-run this command:\n"
+		     "\tmv /var/db/pkg " DEF_LOG_DIR);
+	}
 
-	return pkgdb_dir;
+        return pkgdb_dir;
 }
 
 /*
Index: pkgtools/pkg_install/files/lib/version.h
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/version.h,v
retrieving revision 1.179
diff -u -r1.179 version.h
--- pkgtools/pkg_install/files/lib/version.h	1 Jul 2020 10:15:20 -0000	1.179
+++ pkgtools/pkg_install/files/lib/version.h	28 Aug 2020 16:50:54 -0000
@@ -27,6 +27,6 @@
 #ifndef _INST_LIB_VERSION_H_
 #define _INST_LIB_VERSION_H_
 
-#define PKGTOOLS_VERSION 20200701
+#define PKGTOOLS_VERSION 20200828
 
 #endif /* _INST_LIB_VERSION_H_ */


Home | Main Index | Thread Index | Old Index