You are not logged in.

#1 2004-12-06 15:47:35

Pajaro
Member
Registered: 2004-04-21
Posts: 884

pacman is not as clean as expected

I've seen that pacman -Sc only removes old packages from cache. It keeps in disk the ones that are uninstalled but up to date.

This script removes from cache the packages that are up to date and that are not installed.

It works for me, but remember, use it at your own risk!

#!/usr/bin/perl

open LLISTA, "ls /var/cache/pacman/pkg|";

$ii=0;

while (<LLISTA>) {
        @a=split(//,$_);
        $pack="";
        $i=0;
        while ($i<$#a-11){
                $pack.=$a[$i];
                $i++;
        }
        $packl[$ii]=$pack;
        $ii++;
}

foreach $pack (@packl) {
        print $pack."n";
        if (!(-e "/var/lib/pacman/local/$pack")) {
                $rml="rm /var/cache/pacman/pkg/$pack.pkg.tar.gz";
                print "33[1;33m- ".$rml."n33[0m";
                system($rml);
        }
}

Offline

#2 2004-12-06 16:17:21

Stanislav
Member
Registered: 2004-10-16
Posts: 82

Re: pacman is not as clean as expected

try

pacman -Scc

wink


[URL=http://imageshack.us][img]http://img360.imageshack.us/img360/481/imbulgarian6ph.gif[/img][/URL]

Offline

#3 2004-12-06 16:19:11

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pacman is not as clean as expected

thanks!

Offline

#4 2004-12-06 16:21:40

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pacman is not as clean as expected

not thanks...

Now I've lost all my cache!  :twisted:

How will I get it again?

Offline

#5 2004-12-06 16:30:49

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pacman is not as clean as expected

Please, Stanislav, try to explain things next time you post.

Not for me, I will not have this mistake again.

Explaining what your post consists in will help people know if you understand the question.

Why would have I wrote a script if I can just type "rm /var/cache/pacman/pkg/*"?

Offline

#6 2004-12-06 17:06:11

dp
Member
From: Zürich, Switzerland
Registered: 2003-05-27
Posts: 3,378
Website

Re: pacman is not as clean as expected

man pacman wrote:
SYNC OPTIONS
       -c, --clean
              Remove old packages from the cache.  When pacman downloads pack-
              ages, it saves them in /var/cache/pacman/pkg.  If  you  need  to
              free  up  diskspace,  you can remove these packages by using the
              --clean option.  Using one --clean  (or  -c)  switch  will  only
              remove  old  packages.  [b]Use it twice to remove all packages from
              the cache.[/b]

The impossible missions are the only ones which succeed.

Offline

#7 2004-12-07 02:52:32

segmental
Member
Registered: 2004-11-07
Posts: 51

Re: pacman is not as clean as expected

I have been using this script which writes out a report
of files in the cache and removes duplicates if run as root.
To be on the safe side, comment out the          "os.remove(lastorig)" line. It includes my very own "commify"
function.

#!/usr/bin/python
# removes/reports updated packages in the pacman cache

import glob, os, string, sys
from time import *

def commify(s):
    decs = new = ''
    if type(s) != 'str': s = str(s)
    pos = string.rfind(s, '.')
    if pos != -1: s, decs = s[:pos], s[pos:]
    while len(s) > 3:
        s, s1 = s[:-3], s[-3:]
        new = ',' + s1 + new
    return s + new + decs

files = []
log=open('cache-report', 'w')
cache='/var/cache/pacman/pkg'

log.write('Local pacman cache:  %snn' % asctime())

os.chdir(cache)
files = glob.glob('*pkg.tar.gz')
files.sort()
log.write("%-26s %-9s %2s %13sn" % ('Package', 'Version', 'Release', 'Size'))
log.write('-' * 58 + 'n')

lastver = lastpkg = lastorig = ''
cnt = total = 0

print
print 'Duplicate Versions Report'
print '-------------------------'
for f in files:
    cnt += 1
    size = os.stat(f)[6]
    total += size
    fullpkg = f[:-11] # removes .pkg.tar.gz
    flds = fullpkg.split('-')
    rel = flds[-1]
    ver = flds[-2]
    pkgname = flds[0:-2]
    if len(pkgname) > 1:
        pkg = string.join(pkgname, '-')
    else:
        pkg = pkgname[0]
    # package, version, release
    log.write("%-26s %-10s %3s %16sn" % (pkg, ver, rel, commify(size)))
    # reconstructs the original pkg name
    orig = pkg+'-'+ver+'-'+rel+'.pkg.tar.gz'
    # report duplicates, remove if root
    if lastpkg == pkg:
        print lastorig
        print orig
        if os.getuid() == 0: # i.e. root
            os.remove(lastorig)
            print '    removed', lastorig, 'n'
        else:
            print '    suggest removing', lastorig, 'n'
    lastorig = orig
    lastpkg = pkg
    lastver = ver
print

log.write('-' * 58 + 'n')
mb = commify("%0.1f" % (float(total) / (1024 * 1024)))
log.write("%18s %7s files, total = %16s (%s MB)n" % 
    (' ', commify(cnt), commify(total), mb))

Offline

Board footer

Powered by FluxBB