With the default configuration, if a non-root user runs `apt-get update`, we emit errors like this:
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied) E: Unable to lock directory /var/lib/apt/lists/ The previous commit reduced the noise a bit, but we can also be more helpful in our reporting. If locking fails and we're not running as root, hint that this might be the cause of our problem. Of course, the problem could be something else entirely and trying to diagnose all possible causes for our problem is infeasible. But there's a fair chance this hint will cover most of the cases, and it could be particularly helpful to less experienced users. --- apt-pkg/acquire.cc | 8 +++++++- test/integration/test-apt-update-locking | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 541785b03..7b6e9a372 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -181,7 +181,13 @@ bool pkgAcquire::GetLock(std::string const &Lock) close(LockFD); LockFD = ::GetLock(flCombine(Lock, "lock")); if (LockFD == -1) - return _error->Error(_("Unable to lock directory %s"), Lock.c_str()); + { + _error->Error(_("Unable to lock directory %s"), Lock.c_str()); + if (getuid() != 0) + _error->Notice(_("You are not root; depending on your configuration, " + "that might explain why locking fails")); + return false; + } return true; } diff --git a/test/integration/test-apt-update-locking b/test/integration/test-apt-update-locking index e2e1e3649..a797cd077 100755 --- a/test/integration/test-apt-update-locking +++ b/test/integration/test-apt-update-locking @@ -16,3 +16,8 @@ cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "${TMPWORKINGDIRECTOR testsuccess grep "^E: Could not open lock file" "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure" testsuccess grep "^E: Unable to lock directory" "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure" testfailure grep "^W: " "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure" +if [ "$(id -u)" = '0' ]; then + testfailure grep "^N: You are not root" "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure" +else + testsuccess grep "^N: You are not root" "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure" +fi -- 2.21.0.rc2.5.gc65a2884ea