NetBSD Problem Report #60149

From www@netbsd.org  Tue Mar 31 13:53:42 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.netbsd.org", Issuer "R12" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 8BF791A9239
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 31 Mar 2026 13:53:42 +0000 (UTC)
Message-Id: <20260331135341.855231A923E@mollari.NetBSD.org>
Date: Tue, 31 Mar 2026 13:53:41 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: pkg_add -P $DESTDIR -K /usr/pkg/pkgdb sometimes uses /var/db/pkg instead
X-Send-Pr-Version: www-1.0
X-From4GNATS: "campbell+netbsd@mumble.net via gnats" <gnats-admin@NetBSD.org>

>Number:         60149
>Category:       pkg
>Synopsis:       pkg_add -P $DESTDIR -K /usr/pkg/pkgdb sometimes uses /var/db/pkg instead
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 31 13:55:00 +0000 2026
>Originator:     Taylor R Campbell
>Release:        current
>Organization:
The Ghost of /var/db/pkg Past
>Environment:
>Description:

	According to the pkg_add(1) man page, the command

		pkg_add -P $DESTDIR -K /usr/pkg/pkgdb $pkgs

	is supposed to install packages into a package database of
	$DESTDIR/usr/pkg/pkgdb.

	But if, _outside_ the destdir (!), /usr/pkg/pkgdb does not
	exist and /var/db/pkg does exist, then it uses
	$DESTDIR/var/db/pkg instead.

	This applies only on NetBSD, and only to the exact default
	paths, that is, /var/db/pkg and $PREFIX/pkgdb.  So if you use
	`-K /usr/pkg/pkgde' instead of `-K /usr/pkg/pkgdb', it doesn't
	happen.

>How-To-Repeat:

	touch /var/db/pkg
	pkg_add -P $DESTDIR -K /usr/pkg/pkgdb $pkgs

>Fix:

	Workaround: Use `-K /./usr/pkg/pkgdb' to bypass the naive
	string comparison.

	Possible fixes:
	1. Change the stat calls in lib/pkgdb.c pkgdb_get_dir to be
	   DESTDIR-relative.
	2. Don't do this if the `-K' argument was explicit.
	3. Come up with a transition plan that enables us to ditch this
	   logic forever.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.