Download_cache bug


(Richard - DiscourseHosting.com) #1

I was investigating a large download_cache directory and I came across this snippet:

This code removes the first CACHE_MAXIMUM_SIZE files, instead of “anything but the last CACHE_MAXIMUM_SIZE files”. It should be head -n -#{CACHE_MAXIMUM_SIZE}

NAME
       head - output the first part of files

SYNOPSIS
       head [OPTION]... [FILE]...

DESCRIPTION
       Print the first 10 lines of each FILE to standard output.  With more than one FILE, precede each with a header giving the file name.  With no FILE, or when FILE is -, read standard input.

       Mandatory arguments to long options are mandatory for short options too.

       -c, --bytes=[-]K
              print the first K bytes of each file; with the leading `-', print all but the last K bytes of each file

       -n, --lines=[-]K
              print the first K lines instead of the first 10; with the leading `-', print all but the last K lines of each file

So why didn’t anyone notice? Well, it seems the backtick command is not working at all for some reason.

2.3.0 :010 > `ls #{CACHE_DIR}|wc -l`
 => "2222\n" 
2.3.0 :012 > `ls -tr #{CACHE_DIR} | head -n -#{CACHE_MAXIMUM_SIZE} | xargs rm -f`
 => "" 
2.3.0 :013 > `ls #{CACHE_DIR}|wc -l`
 => "2222\n" 
2.3.0 :014 > ^C
2.3.0 :014 > 
root@basic001:/var/www/discourse/tmp/download_cache# ls -tr /var/www/discourse/tmp/download_cache/|head -n -500|xargs rm -f
root@basic001:/var/www/discourse/tmp/download_cache# ls |wc -l
500

Download_cache directory taking up a lot of space. Can I delete it?
(Jeff Atwood) #2

Can we validate this @zogstrip?


(Régis Hanol) #4

Thanks @RGJ for reporting this issue :+1:


(Régis Hanol) #5

This topic was automatically closed after 59 minutes. New replies are no longer allowed.