You are not logged in.

#1 2010-10-18 05:39:54

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Simple Application to Clean pacman Cache

The original "pacman -Sc" command cleans everything but the installed packages; the AUR package cleancache retains a certain number of every package, whether it is currently installed or not.

This simple application i have written retains a certain number of every installed package, including 1 currently used. All other package caches are deleted.

The application is so simple so that nearly all error checking is omitted and the program is written in a very crude way.

Usage: pkgcacheclean [options] [number]

The default number is 2. That means, for all installed packages, the currently used version and the newest of the remaining cache is retained. All caches of not-installed packages are removed.
Currently, supported options only includes -v/--verbose, -q/--quiet, -n/--dry-run, -k/--all-as-installed.

Actually this post is mainly used to provide a url for my PKGBUILD file.

Changelog:
1.8.2
  fix a bug that occurs when -d receives an argument without a trailing slash.

1.8.1
  rename -k option to better the format help information.

1.8
  add option -k to treat uninstalled packages as installed.

1.7.1
    pacman 4.1 compatibility.
    remove redundant free of package list.
1.7
    add option to configure cachedir
1.6.1
    Fix some warning under x86_64. No functional change.
1.6
    Move to pacman 4
1.5
    Added -n/--dry-run option, thanks to ber_t.
1.4
    Support pacman 3.5
1.3
    Move uid check later to eliminate unnecessary password typing to see the usage.
    Add a little options.
1.2
    Major speed boost by getting cached package information from its filename.
1.1
    Early quit if called by normal user.
1.0
    First version.

Last edited by AugustePop (2014-11-02 14:20:33)

Offline

#2 2010-10-18 07:07:05

SanskritFritz
Member
From: Budapest, Hungary
Registered: 2009-01-08
Posts: 1,923
Website

Re: Simple Application to Clean pacman Cache

You probably didnt know about http://wiki.archlinux.org/index.php/CacheClean ?

UPDATE: Forget it, I'm stupid. Gotta learn to read more. Thanks for the package!

Last edited by SanskritFritz (2010-10-18 07:10:55)


zʇıɹɟʇıɹʞsuɐs AUR || Cycling in Budapest with a helmet camera || Revised log levels proposal: "FYI" "WTF" and "OMG" (John Barnette)

Offline

#3 2010-10-18 07:18:39

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

That's all right. I have tried CacheClean, and according to its behavior, I guessed that it did not check whether a package is actually installed or not.

Moreover, package versions are totally mess considering the number of packages in repository and AUR. My little tool uses the same version comparison routine as pacman does to eliminate possible misbehavior.

However, I am a lazy person with elementary programming skills. I am quite open for any critics about my code. Thank you.

Offline

#4 2010-10-18 07:34:47

lymphatik
Member
From: Somewhere else
Registered: 2009-03-07
Posts: 119

Re: Simple Application to Clean pacman Cache

Isn't Cleanmethod in pacman.conf doing it that already ?

       CleanMethod = KeepInstalled | KeepCurrent
           If set to KeepInstalled (the default), the -Sc operation will clean packages that are no longer installed (not present in the local database). If set to KeepCurrent, -Sc will clean outdated
           packages (not present in any sync database). The second behavior is useful when the package cache is shared among multiple machines, where the local databases are usually different, but the sync
           databases in use could be the same.

Offline

#5 2010-10-18 07:38:14

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

I think that's a switch. But I want to do both. Moreover, I want to have a backup version rather than the -Sc KeepInstalled behavior.

lymphatik wrote:

Isn't Cleanmethod in pacman.conf doing it that already ?

       CleanMethod = KeepInstalled | KeepCurrent
           If set to KeepInstalled (the default), the -Sc operation will clean packages that are no longer installed (not present in the local database). If set to KeepCurrent, -Sc will clean outdated
           packages (not present in any sync database). The second behavior is useful when the package cache is shared among multiple machines, where the local databases are usually different, but the sync
           databases in use could be the same.

Last edited by AugustePop (2010-10-18 07:39:08)

Offline

#6 2010-10-18 08:03:02

sausageandeggs
Member
Registered: 2009-12-05
Posts: 66

Re: Simple Application to Clean pacman Cache

Thanks for this, just one prob, it conflicts with pkgtools-git [1]  which also installs a /usr/bin/pkgclean with different functionality. I'll leave a new name up to you (if you want to that is!)

Edit: I've gone with pkgcache-clean

[1] http://aur.archlinux.org/packages.php?ID=24501

Last edited by sausageandeggs (2010-10-18 08:05:54)

Offline

#7 2010-10-18 08:06:25

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

sausageandeggs wrote:

Thanks for this, just one prob, it conflicts with pkgtools-git [1]  which also installs a /usr/bin/pkgclean with different functionality. I'll leave a new name up to you (if you want to that is!)

[1] http://aur.archlinux.org/packages.php?ID=24501

Thank you for pointing this out to me. I have no idea that it has conflicts. What about pkgcacheclean?

If that's all right, I will change the package. However, I have to figure out how to do this first...

Offline

#8 2010-10-18 08:12:32

sausageandeggs
Member
Registered: 2009-12-05
Posts: 66

Re: Simple Application to Clean pacman Cache

It's all good they'll both work, I just dont like long names so i hyphenate them.
What is it you need to figure out?

Offline

#9 2010-10-18 08:15:12

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

sausageandeggs wrote:

It's all good they'll both work, I just dont like long names so i hyphenate them.
What is it you need to figure out?

How to change the package name.

Anyway, I uploaded a new package and change the main entry of this a post. I will now modify the original package and send a remove request to the mailing list.

Offline

#10 2010-10-18 08:20:38

sausageandeggs
Member
Registered: 2009-12-05
Posts: 66

Re: Simple Application to Clean pacman Cache

Ah yeah theres no rename functionality in the AUR, have to reupload and remove via the mailing list. Once again thanks for this, much prefer it to cache-clean (no flame intended!)

Offline

#11 2010-10-18 08:22:52

sausageandeggs
Member
Registered: 2009-12-05
Posts: 66

Re: Simple Application to Clean pacman Cache

One more thing (Sorrrrrrrryyyyyyyyy!!) the conflicts should be 'pkgtools-git' not 'pkgclean'

Last edited by sausageandeggs (2010-10-18 08:23:12)

Offline

#12 2010-10-18 08:26:25

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

I know it's a pretty long name. I choose not to use a similar name to cacheclean because I think cacheclean is a pretty good script, and I don't want to create any confusions.

I added pkgclean, my previous package, to make the installation of it on my machine easier.

Offline

#13 2010-10-18 08:29:55

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

sausageandeggs wrote:

One more thing (Sorrrrrrrryyyyyyyyy!!) the conflicts should be 'pkgtools-git' not 'pkgclean'

The executable name is changed in the new package so there is no conflict to pkgtools or pkgtools-git now.

The old package is modified to reflect the conflict and marked as out of date and now waiting for the deletion.

Last edited by AugustePop (2010-10-18 08:30:12)

Offline

#14 2010-10-18 08:34:14

sausageandeggs
Member
Registered: 2009-12-05
Posts: 66

Re: Simple Application to Clean pacman Cache

Doh!! :facepalm!: Sorry about the above comment , now that you've renamed it there's no need for a conflicts line. Time for bed i think before i do something really stupid!

Offline

#15 2010-10-18 10:28:38

archman-cro
Member
From: Croatia
Registered: 2010-04-04
Posts: 943
Website

Re: Simple Application to Clean pacman Cache

Should pkgcacheclean put out a warning if I'm not using it as root, since the cache can't be removed with a normal user?
I ran the proggie with a normal user, and it did something (the disk was pretty active for 10 secs or so), but all cache was left intact (again, sure, no privs to remove).

Offline

#16 2010-10-18 10:55:13

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

that's a good idea. i will issue a warning to stdout and exit.

Offline

#17 2010-10-18 11:06:50

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Simple Application to Clean pacman Cache

Your isfile filter doesn't need to be so noisy. Each dirent has a d_type attribute which can be compared to DT_REG to determine if its a file.

Offline

#18 2010-10-18 11:18:25

archman-cro
Member
From: Croatia
Registered: 2010-04-04
Posts: 943
Website

Re: Simple Application to Clean pacman Cache

Wow, it just freed 1GB of space on my HDD. This app rocks! Thanks, AugustePop! smile

Offline

#19 2010-10-18 12:07:43

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

falconindy wrote:

Your isfile filter doesn't need to be so noisy. Each dirent has a d_type attribute which can be compared to DT_REG to determine if its a file.

Thank you for your information. According to GNU C Library Documentation[1], d_type "is a BSD extension. The symbol _DIRENT_HAVE_D_TYPE is defined if this member is available." However, my system sets d_type of all struct dirent as DT_UNKNOWN.

Anyway, the code has been changed and I no longer use this technique to filter out unwanted directory sentinels.

[1] http://www.gnu.org/software/libc/manual … tries.html

Last edited by AugustePop (2010-10-18 15:54:19)

Offline

#20 2010-10-18 20:33:36

slytux
Member
From: New York
Registered: 2010-09-25
Posts: 129

Re: Simple Application to Clean pacman Cache

There is also 'yaourt -Scc' if you have it installed.

Offline

#21 2010-10-19 00:43:20

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

slytux wrote:

There is also 'yaourt -Scc' if you have it installed.

I have not tried this. man yaourt or man yaourtrc give me no explanation of the Scc command, not even Sc.

Offline

#22 2010-11-15 16:20:44

archman-cro
Member
From: Croatia
Registered: 2010-04-04
Posts: 943
Website

Re: Simple Application to Clean pacman Cache

Maybe a little suggestion if I can tell it. Wouldn't it be better to show the warning "please run as root." and the help afterwards (the info we get with "sudo pkgcacheclean --help") if the user runs the script with no privs?

Offline

#23 2010-11-15 16:32:12

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

That's a good idea, I will change it when I have time. Seems decent argument parsing is necessary now. Thank you for your suggestion.

EDIT: package updated.

archman-cro wrote:

Maybe a little suggestion if I can tell it. Wouldn't it be better to show the warning "please run as root." and the help afterwards (the info we get with "sudo pkgcacheclean --help") if the user runs the script with no privs?

Last edited by AugustePop (2010-11-16 05:31:46)

Offline

#24 2011-02-22 11:11:14

archman-cro
Member
From: Croatia
Registered: 2010-04-04
Posts: 943
Website

Re: Simple Application to Clean pacman Cache

Maybe another idea: Why not echoing how much space/what packages did the script free after performing the operation?

Offline

#25 2011-02-22 11:22:50

AugustePop
Member
Registered: 2010-04-27
Posts: 95

Re: Simple Application to Clean pacman Cache

archman-cro wrote:

Maybe another idea: Why not echoing how much space/what packages did the script free after performing the operation?

I have already done it, although not so accurately. Use the -v or --verbose option.

I am using yaourt and configured it to copy the final package into system package cache directory and save a --allsource source package in SRCPKGDEST in .makepkg.conf, so here comes an easy use of the -v option.

#!/bin/bash
eval dest=$(sed -n 's/^SRCPKGDEST=\(.*\)$/\1/p' $HOME/.makepkg.conf)
sudo pkgcacheclean -v | tee >(sed -n 's/^remove: \(.*\)$/\1/p' | sed "s:^\(.*\)-[^-]*$:$dest/\1.src.tar.gz:" | xargs rm -f)

This little script clears the system package cache and the cached source packages as well.

Offline

Board footer

Powered by FluxBB