Quellcode durchsuchen

ensure we got a lock in clean operation

We try to acquired the locks, but we didn't stop if we failed to get it…

Closes: 808561
David Kalnischkies vor 10 Jahren
Ursprung
Commit
8d968cc2d1
2 geänderte Dateien mit 14 neuen und 4 gelöschten Zeilen
  1. 4 4
      apt-private/private-download.cc
  2. 10 0
      test/integration/test-apt-get-clean

+ 4 - 4
apt-private/private-download.cc

@@ -309,16 +309,16 @@ bool DoClean(CommandLine &)
    }
 
    pkgAcquire Fetcher;
-   if (archivedir.empty() == false && FileExists(archivedir) == true)
+   if (archivedir.empty() == false && FileExists(archivedir) == true &&
+	 Fetcher.GetLock(archivedir) == true)
    {
-      Fetcher.GetLock(archivedir);
       Fetcher.Clean(archivedir);
       Fetcher.Clean(archivedir + "partial/");
    }
 
-   if (listsdir.empty() == false && FileExists(listsdir) == true)
+   if (listsdir.empty() == false && FileExists(listsdir) == true &&
+	 Fetcher.GetLock(listsdir) == true)
    {
-      Fetcher.GetLock(listsdir);
       Fetcher.Clean(listsdir + "partial/");
    }
 

+ 10 - 0
test/integration/test-apt-get-clean

@@ -36,6 +36,16 @@ testfailure test -e rootdir/var/cache/apt/archives/foo_2_all.deb
 testfailure test -e rootdir/var/cache/apt/archives/foo_3_all.deb
 testfailure test -e rootdir/var/cache/apt/archives/foo_4_all.deb
 
+if [ "$(id -u)" != '0' ]; then
+	msgmsg 'No clean if lock can not be acquired'
+	touch rootdir/var/cache/apt/archives/foo_4_all.deb
+	touch rootdir/var/cache/apt/archives/lock
+	chmod 444 rootdir/var/cache/apt/archives/lock
+	testfailure apt clean
+	testsuccess test -e rootdir/var/cache/apt/archives/foo_4_all.deb
+	chmod 644 rootdir/var/cache/apt/archives/lock
+fi
+
 directorygone() {
 	rm -rf "$1"
 	testsuccess apt autoclean