test-apt-get-clean 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'amd64'
  7. insertpackage 'testing' 'foo' 'all' '1'
  8. insertpackage 'unstable' 'foo' 'all' '2'
  9. insertpackage 'experimental' 'foo' 'all' '1:1'
  10. insertinstalledpackage 'foo' 'all' '3'
  11. setupaptarchive --no-update
  12. mkdir -p rootdir/var/lib/apt/lists/lost+found
  13. testsuccess apt update
  14. # nothing to do always works
  15. testsuccess aptget clean
  16. testsuccess aptget clean -s
  17. # generate some dirt and clean it up
  18. generatedirt() {
  19. touch rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
  20. mkdir -p rootdir/var/cache/apt/archives/lost+found
  21. touch rootdir/var/cache/apt/archives/foo_1_all.deb
  22. touch rootdir/var/cache/apt/archives/foo_1%3a1_all.deb
  23. touch rootdir/var/cache/apt/archives/foo_2%3a1_all.deb
  24. touch rootdir/var/cache/apt/archives/foo_2_all.deb
  25. touch rootdir/var/cache/apt/archives/foo_3_all.deb
  26. touch rootdir/var/cache/apt/archives/foo_4_all.deb
  27. }
  28. generatedirt
  29. testsuccess aptget autoclean
  30. testsuccess test -e rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
  31. testsuccess test -e rootdir/var/cache/apt/archives/foo_1_all.deb
  32. testsuccess test -e rootdir/var/cache/apt/archives/foo_1%3a1_all.deb
  33. testfailure test -e rootdir/var/cache/apt/archives/foo_2%3a1_all.deb
  34. testsuccess test -e rootdir/var/cache/apt/archives/foo_2_all.deb
  35. testfailure test -e rootdir/var/cache/apt/archives/foo_3_all.deb
  36. testfailure test -e rootdir/var/cache/apt/archives/foo_4_all.deb
  37. generatedirt
  38. testsuccess aptget clean
  39. testfailure test -e rootdir/var/lib/apt/lists/partial/http.debian.net_debian_dists_sid_main_i18n_Translation-en
  40. testfailure test -e rootdir/var/cache/apt/archives/foo_1_all.deb
  41. testfailure test -e rootdir/var/cache/apt/archives/foo_1%3a1_all.deb
  42. testfailure test -e rootdir/var/cache/apt/archives/foo_2%3a1_all.deb
  43. testfailure test -e rootdir/var/cache/apt/archives/foo_2_all.deb
  44. testfailure test -e rootdir/var/cache/apt/archives/foo_3_all.deb
  45. testfailure test -e rootdir/var/cache/apt/archives/foo_4_all.deb
  46. if [ "$(id -u)" != '0' ]; then
  47. msgmsg 'No clean if lock can not be acquired'
  48. touch rootdir/var/cache/apt/archives/foo_4_all.deb
  49. touch rootdir/var/cache/apt/archives/lock
  50. chmod 444 rootdir/var/cache/apt/archives/lock
  51. testfailure apt clean
  52. testsuccess test -e rootdir/var/cache/apt/archives/foo_4_all.deb
  53. chmod 644 rootdir/var/cache/apt/archives/lock
  54. fi
  55. directorygone() {
  56. rm -rf "$1"
  57. testsuccess apt autoclean
  58. testfailure test -d "$1"
  59. testsuccess apt clean
  60. # clean creates an empty partial directory via GetLock
  61. if [ "$(basename "$1")" = 'partial' ]; then
  62. testsuccess test -d "$1"
  63. else
  64. testfailure test -d "$1"
  65. fi
  66. }
  67. msgmsg 'Partial directory missing'
  68. directorygone 'rootdir/var/cache/apt/archives/partial'
  69. directorygone 'rootdir/var/lib/apt/lists/partial'
  70. msgmsg 'Archives directory missing'
  71. directorygone 'rootdir/var/cache/apt/archives'
  72. directorygone 'rootdir/var/lib/apt/lists'
  73. msgmsg 'apt directory missing'
  74. directorygone 'rootdir/var/cache/apt'
  75. directorygone 'rootdir/var/lib/apt'