Skip to content

Commit

Permalink
Delete dumps in indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
gdb committed Mar 29, 2012
1 parent d70af9c commit 610fb56
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions bin/index-packfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'

require File.join(File.dirname(__FILE__), '../lib/anygit')

module Anygit
class IndexPackfile
TMPDIR_BASE = File.join(File.dirname(__FILE__), '../tmp')

def initialize(repo, path)
def initialize(repo, path, opts)
@repo = repo
@path = path
@opts = opts

@create ||= {}
@tmpdir = File.join(TMPDIR_BASE, "#{repo.id}-#{Time.now.to_i}-#{rand}")
Expand All @@ -22,6 +24,7 @@ module Anygit
build_dumps
close_files
load_dumps
delete_dumps unless @opts[:dont_delete_dumps]
end

def build_dumps
Expand Down Expand Up @@ -69,6 +72,11 @@ module Anygit
end
end

def delete_dumps
Anygit.log.info("Deleting tmpdir (#{@tmpdir})")
FileUtils.rm_r(@tmpdir)
end

private

def store_object(type, sha1)
Expand Down Expand Up @@ -247,6 +255,10 @@ def main
opts.on('-c', '--create-repo', 'Create repo by url if it does not exist') do
options[:create_repo] = true
end

opts.on('-d', '--dont-delete-dumps', 'Leave dumps lying around') do
options[:dont_delete_dumps] = true
end
end
optparse.parse!

Expand All @@ -266,7 +278,7 @@ def main
repo = Anygit::Model::Repo.get!(:url => url)
end

runner = Anygit::IndexPackfile.new(repo, path)
runner = Anygit::IndexPackfile.new(repo, path, :dont_delete_dumps => options[:dont_delete_dumps])
runner.run
return 0
end
Expand Down

0 comments on commit 610fb56

Please sign in to comment.