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

Bug#990516: why do I have to be root to download a deb file using apt?



On Thu, Jul 01, 2021 at 10:30:52AM +0200, Harald Dunkel wrote:
> Package: apt
> Version: 2.2.4
> 
> Trying to download a package using an unprivileged account fails with
> 
> % apt -o dir::cache::archives="/tmp/" -d install mg
> E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
> E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
> 
> How comes dpkg has a say in what deb files I download?

The command for downloading packages is apt download.

apt install is the command for installing packages; and --download-only
makes it stop after downloading. The dpkg lock is released when
--download-only is specified, after the prompt happened and the
archives lock has been acquired. I'm not sure that is safe, or
not acquiring locks on --simulate, as hooks might not expect to
run in parallel.

Not sure I want to change it, though it could be, see patch
below. There's some value in consistency, and acquiring the
archive lock without the frontend lock also breaks waiting
for lock, as it only waits on the dpkg lock (and would then
fail to acquire the archives lock) - nasty.

So I'd argue it's best the way it is right now, and if you
need to hack stuff, you can use -o debug::nolocking=1

diff --git a/apt-private/private-cachefile.h b/apt-private/private-cachefile.h
index ccd47107b..287e2a3a2 100644
--- a/apt-private/private-cachefile.h
+++ b/apt-private/private-cachefile.h
@@ -30,7 +30,8 @@ class APT_PUBLIC CacheFile : public pkgCacheFile
    };
    bool OpenForInstall()
    {
-      if (_config->FindB("APT::Get::Print-URIs") == true)
+      if (_config->FindB("APT::Get::Print-URIs") ||
+          _config->FindB("APT::Get::Download-Only",false))
 	 return Open(false);
       else
 	 return Open(true);
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc
index 3ffb0be32..f31a31387 100644
--- a/apt-private/private-install.cc
+++ b/apt-private/private-install.cc
@@ -341,11 +341,6 @@ bool InstallPackages(CacheFile &Cache, APT::PackageVector &HeldBackPackages, boo
    if (!CheckAuth(Fetcher, true))
       return false;
 
-   /* Unlock the dpkg lock if we are not going to be doing an install
-      after. */
-   if (_config->FindB("APT::Get::Download-Only",false) == true)
-      _system->UnLock();
-
    // Run it
    bool Failed = false;
    while (1)

-- 
debian developer - deb.li/jak | jak-linux.org - free software dev
ubuntu core developer                              i speak de, en


Reply to: