16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
def _update_store_entry(obj, obj_id, branch, store_name, store):
20
"""This is just a meta-function, which handles both revision entries
21
and inventory entries.
23
from bzrlib.trace import mutter
24
import tempfile, os, errno
25
from osutils import rename
26
obj_tmp = tempfile.TemporaryFile()
27
obj.write_xml(obj_tmp)
30
tmpfd, tmp_path = tempfile.mkstemp(prefix=obj_id, suffix='.gz',
31
dir=branch.controlfilename(store_name))
34
orig_obj_path = branch.controlfilename([store_name, obj_id+'.gz'])
35
# Remove the old entry out of the way
36
rename(orig_obj_path, tmp_path)
38
# TODO: We may need to handle the case where the old
39
# entry was not compressed (and thus did not end with .gz)
41
store.add(obj_tmp, obj_id) # Add the new one
42
os.remove(tmp_path) # Remove the old name
43
mutter(' Updated %s entry {%s}' % (store_name, obj_id))
45
# On any exception, restore the old entry
46
rename(tmp_path, orig_obj_path)
49
if os.path.exists(tmp_path):
50
# Unfortunately, the next command might throw
51
# an exception, which will mask a previous exception.
55
def _update_revision_entry(rev, branch):
56
"""After updating the values in a revision, make sure to
57
write out the data, but try to do it in an atomic manner.
59
:param rev: The Revision object to store
60
:param branch: The Branch object where this Revision is to be stored.
62
_update_store_entry(rev, rev.revision_id, branch,
63
'revision-store', branch.revision_store)
65
def _update_inventory_entry(inv, inv_id, branch):
66
"""When an inventory has been modified (such as by adding a unique tree root)
67
this atomically re-generates the file.
69
:param inv: The Inventory
70
:param inv_id: The inventory id for this inventory
71
:param branch: The Branch where this entry will be stored.
73
_update_store_entry(inv, inv_id, branch,
74
'inventory-store', branch.inventory_store)
77
22
"""Run consistency checks on a branch.