Web lists-archives.com

Re: apt-cacher errors




Hi Greg,

Thank you for taking the time to point out all the shortcomings.


On 25/03/19 13:21, Greg Wooledge wrote:
On Mon, Mar 25, 2019 at 12:11:21PM +0000, Adam Weremczuk wrote:
I've found 30 entries referencing wheezy and removed them all:

sudo find /var/cache/apt-cacher/ -type f -name *wheezy* | xargs rm
sudo find /var/cache/apt-cacher -type f -name '*wheezy*' -delete

There are three mistakes in your command:

1) The glob must be quoted, or the shell will expand it based on the files
    in the current working directory, wherever that happens to be.
I would normally use \*wheezy\* but I new that wouldn't make any difference as I saw the list earlier.
Any practical difference between \*wheezy\* and '*wheezy*' in this case?
2) xargs without -0 is unsafe to use for filenames, because they may contain
    whitespace or single quotes or double quotes, all of which are special
    to xargs.
Again, I saw the list so didn't bother but a fair point indeed, it could easily fail or even turn disastrous.
3) You ran find with sudo privileges (probably not necessary), and failed
    to run the rm with sudo privileges.  All of the removals are therefore
    going to fail.
TBH I run it as root and added single sudo in front after pasting not to promote bad practices :)

You might argue that "apt-cacher never has any files with spaces!"
That may be true.  But it's still a good habit to develop.  Also, -delete
is more efficient than | xargs rm, albeit not portable to POSIX scripts.
Never used it with find, good to know.

If you want it to be portable as well as safe, then:

sudo find /var/cache/apt-cacher -type f -name '*wheezy*' -exec rm {} +

That's less efficient than -delete, but it's the best you can do if
POSIX portability is required.
Agree.

Thanks again,
Adam