summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2016-03-13 15:34:35 +0200
committerLars Wirzenius <liw@liw.fi>2016-03-13 15:52:23 +0200
commit57143bd0a370d2fcc1e2bf824bf6133691196acb (patch)
treeea6e00b2b75bf1b0c69aab88b8939f916e28637c
parentbfe84dcb5dd5a8d54c43a61602920d50df11e178 (diff)
downloadobnam-57143bd0a370d2fcc1e2bf824bf6133691196acb.tar.gz
Use well-known blob in chunk-indexes
-rw-r--r--obnamlib/fmt_ga/indexes.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/obnamlib/fmt_ga/indexes.py b/obnamlib/fmt_ga/indexes.py
index e765356e..ab36ff97 100644
--- a/obnamlib/fmt_ga/indexes.py
+++ b/obnamlib/fmt_ga/indexes.py
@@ -1,4 +1,4 @@
-# Copyright 2015 Lars Wirzenius
+# Copyright 2015-2016 Lars Wirzenius
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -26,6 +26,8 @@ import obnamlib
class GAChunkIndexes(object):
+ _well_known_blob = 'root'
+
def __init__(self):
self._fs = None
self.set_dirname('chunk-indexes')
@@ -50,17 +52,24 @@ class GAChunkIndexes(object):
def _save_data(self):
blob = obnamlib.serialise_object(self._data)
- filename = self._get_filename()
- self._fs.overwrite_file(filename, blob)
+
+ bag_store = obnamlib.BagStore()
+ bag_store.set_location(self._fs, self.get_dirname())
+
+ blob_store = obnamlib.BlobStore()
+ blob_store.set_bag_store(bag_store)
+ blob_store.put_well_known_blob(self._well_known_blob, blob)
def _load_data(self):
if not self._data_is_loaded:
- filename = self._get_filename()
- if self._fs.exists(filename):
- blob = self._fs.cat(filename)
- self._data = obnamlib.deserialise_object(blob)
- assert self._data is not None
- else:
+ bag_store = obnamlib.BagStore()
+ bag_store.set_location(self._fs, self.get_dirname())
+
+ blob_store = obnamlib.BlobStore()
+ blob_store.set_bag_store(bag_store)
+ blob = blob_store.get_well_known_blob(self._well_known_blob)
+
+ if blob is None:
self._data = {
'by_chunk_id': {
},
@@ -70,6 +79,10 @@ class GAChunkIndexes(object):
'used_by': {
},
}
+ else:
+ self._data = obnamlib.deserialise_object(blob)
+ assert self._data is not None
+
self._data_is_loaded = True
def _get_filename(self):