36: def run
37: @id = @repo.resolve_id(@rev, @id)
38: target = File.dirname(@repo.path)
39: originals = File.expand_path(@repo.originals_dir)
40:
41: if @id
42:
43: parent_id = @repo['Path'].pop
44:
45:
46:
47: if @repo['Path'].empty? or parent_id == @repo.find_parent_of(@id)
48:
49: cs_path, md = @repo.find_changeset(@id)
50: data_file = nil
51: journal_file = nil
52:
53: Dir.chdir cs_path do
54: md['Contents'].each do |info|
55: name, digest, purpose = info['Name'], info['Digest'], info['Purpose']
56: if digest != Digest::MD5.hexdigest(File.read(name))
57: UI.failure :security, "#{name} MD5 digest does not match. Aborting."
58: return
59: end
60:
61: if purpose == "data"
62:
63: data_file = name
64: elsif purpose == "journal"
65:
66: journal_file = name
67: end
68:
69:
70: if data_file and journal_file
71: break
72: end
73: end
74:
75:
76: UI.start_finish("Applying to main directory") do
77: journal_in = Zlib::GzipReader.new(File.open(journal_file))
78: data_in = Zlib::GzipReader.new(File.open(data_file))
79: ChangeSet.apply_changeset(journal_in, data_in, target, @test_run)
80: end
81:
82: if not File.exist? "undo.yaml" and not @test_run
83:
84: UI.start_finish("Creating 'undo' revision") do
85: changes = ChangeSet.make_changeset("undo", target, originals)
86: end
87: end
88:
89:
90: UI.start_finish("Applying to the repository originals directory") do
91: journal_in = Zlib::GzipReader.new(File.open(journal_file))
92: data_in = Zlib::GzipReader.new(File.open(data_file))
93: ChangeSet.apply_changeset(journal_in, data_in, @repo.originals_dir, @test_run)
94: end
95:
96:
97: @repo['Path'] = @repo['Path'] << @id unless @test_run
98: end
99: else
100: UI.failure :constraint, "Sorry, can't apply a revision unless it is a child of the current one."
101: end
102: else
103: UI.failure :search, "Could not find a matching revision"
104: end
105: end