LoginSignup
3
3

More than 5 years have passed since last update.

Garbage-collecting BOINC (remove old version apps)

Posted at

Boinc applications are sometimes updated and old ones still remain in data directory.
Although the server might discard new ones later, usually old ones are just waste of the storage.
This Ruby script will garbage-collect the data directory.

boinc_gc.rb
#!/usr/bin/env ruby
#BOINC Garbage Collector (remove old files)

if ARGV.empty? or ARGV[0]!='--yes'
    dry=true
    puts 'Usage: boinc_gc.rb [--yes]'
    puts 'without --yes, it runs in dry-run mode.'
else
    dry=false
end

#http://wcg.wikia.com/wiki/Data_directory
DIR={
    win: 'C:/Documents and Settings/All Users/Application Data/BOINC/projects',
    #win: 'C:/ProgramData/BOINC/projects',
    osx: '/Library/Application Support/BOINC Data/projects',
    linux: '/var/lib/boinc-client/projects',
    freebsd: '/var/db/boinc/projects',
}

if RUBY_PLATFORM.include?('win32') || RUBY_PLATFORM.include?('mingw32')
    dir=DIR[:win]
elsif RUBY_PLATFORM.include?('linux')
    dir=DIR[:linux]
elsif RUBY_PLATFORM.include?('darwin')
    dir=DIR[:osx]
elsif RUBY_PLATFORM.include?('freebsd')
    dir=DIR[:freebsd]
else
    raise 'Unknown platform '+RUBY_PLATFORM
end

FILESIZE_THRESHOLD=1000000 #1MB
require 'find'
dict=Hash.new{|h,k|h[k]=[]}
Find.find(dir){|path|
    size=File.size(path)
    if size>=10**7
        base=path #File.basename(path)
        #x86_64 can exec x86 apps, so there might be mixture.
        base=base.gsub('i386','').gsub('i586','').gsub('i686','').gsub('x86_64','')
        if base=~/_([\d\.]+)_/
            base.sub!(/_([\d\.]+)_/,'')
            dict[base].push({ver:$1,size:size,name:path})
        end
    end
}
totalsize=0
dict.each_value{|v|
    a=v.sort_by{|e|e[:ver].split('.').map(&:to_i)}
    (a.size-1).times{|i|
        totalsize+=a[i][:size]
        puts 'Removing '+a[i][:name]
        File.unlink(a[i][:name]) unless dry
    }
}
puts 'Saved '+totalsize.to_s+' bytes.'

検索用:BOINCをガベージコレクションする(古いバージョンのアプリケーションを削除する)

3
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3