You are not logged in.
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
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
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
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
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.
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
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)
() Registered Linux user #500376
/\ www.asciiribbon.org - against html e-mail
Offline
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!)
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
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?
() Registered Linux user #500376
/\ www.asciiribbon.org - against html e-mail
Offline
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
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!)
() Registered Linux user #500376
/\ www.asciiribbon.org - against html e-mail
Offline
One more thing (Sorrrrrrrryyyyyyyyy!!) the conflicts should be 'pkgtools-git' not 'pkgclean'
Last edited by sausageandeggs (2010-10-18 08:23:12)
() Registered Linux user #500376
/\ www.asciiribbon.org - against html e-mail
Offline
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
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
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!
() Registered Linux user #500376
/\ www.asciiribbon.org - against html e-mail
Offline
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
that's a good idea. i will issue a warning to stdout and exit.
Offline
Wow, it just freed 1GB of space on my HDD. This app rocks! Thanks, AugustePop!
Offline
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
There is also 'yaourt -Scc' if you have it installed.
Offline
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
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
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.
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
Maybe another idea: Why not echoing how much space/what packages did the script free after performing the operation?
Offline
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