import itertools
import os
import re
+import sqlite3
import tarfile
import tempfile
import thread
-from pysqlite2 import dbapi2 as sqlite3
import cumulus.store
import cumulus.store.file
(".gpg", "cumulus-filter-gpg --decrypt"),
(".gz", "gzip -dc"),
(".bz2", "bzip2 -dc"),
+ ("", None),
]
def uri_decode(s):
continue
raise cumulus.store.NotFoundError(basename)
+ def match(self, filename):
+ return self._regex.match(filename)
+
def list(self, backend):
success = False
for d in self.directories():
try:
for f in backend.list(d):
success = True
- m = self._regex.match(f)
+ m = self.match(f)
if m: yield (os.path.join(d, f), m)
except cumulus.store.NotFoundError:
pass
SearchPathEntry("", ".sha1sums")]),
"segments": SearchPath(
(r"^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"
- r"(\.\S+)?$"),
+ r"\.tar(\.\S+)?$"),
itertools.chain(
_build_segments_searchpath("segments0"),
_build_segments_searchpath("segments1"),
snapshot_file = self.backend.open_snapshot(snapshot)[0]
return snapshot_file.read().splitlines(True)
- def get_segment(self, segment):
- accessed_segments.add(segment)
-
- (segment_fp, path, filter_cmd) = self.backend.open_segment(segment)
+ @staticmethod
+ def filter_data(filehandle, filter_cmd):
if filter_cmd is None:
- return segment_fp
+ return filehandle
(input, output) = os.popen2(filter_cmd)
def copy_thread(src, dst):
BLOCK_SIZE = 4096
dst.write(block)
src.close()
dst.close()
- thread.start_new_thread(copy_thread, (segment_fp, input))
+ thread.start_new_thread(copy_thread, (filehandle, input))
return output
+ def get_segment(self, segment):
+ accessed_segments.add(segment)
+
+ (segment_fp, path, filter_cmd) = self.backend.open_segment(segment)
+ return self.filter_data(segment_fp, filter_cmd)
+
def load_segment(self, segment):
seg = tarfile.open(segment, 'r|', self.get_segment(segment))
for item in seg:
"""
cur = self.cursor()
- # Delete entries in the segments_used table which are for non-existent
- # snapshots.
- cur.execute("""delete from segments_used
+ # Delete entries in the segment_utilization table which are for
+ # non-existent snapshots.
+ cur.execute("""delete from segment_utilization
where snapshotid not in
(select snapshotid from snapshots)""")
- # Find segments which contain no objects used by any current snapshots,
- # and delete them from the segment table.
+ # Delete segments not referenced by any current snapshots.
cur.execute("""delete from segments where segmentid not in
- (select segmentid from segments_used)""")
+ (select segmentid from segment_utilization)""")
# Delete dangling objects in the block_index table.
cur.execute("""delete from block_index