diff options
-rw-r--r-- | obnamlib/__init__.py | 1 | ||||
-rw-r--r-- | obnamlib/plugins/fsck_plugin.py | 51 | ||||
-rw-r--r-- | obnamlib/repo_dummy.py | 4 | ||||
-rw-r--r-- | obnamlib/repo_fmt_6.py | 34 | ||||
-rw-r--r-- | obnamlib/repo_interface.py | 16 | ||||
-rw-r--r-- | test-gpghome/random_seed | bin | 600 -> 600 bytes | |||
-rw-r--r-- | without-tests | 1 |
7 files changed, 51 insertions, 56 deletions
diff --git a/obnamlib/__init__.py b/obnamlib/__init__.py index 9b2d4bd8..0c62b3cf 100644 --- a/obnamlib/__init__.py +++ b/obnamlib/__init__.py @@ -90,6 +90,7 @@ from vfs import VirtualFileSystem, VfsFactory, VfsTests from vfs_local import LocalFS from metadata import (read_metadata, set_metadata, Metadata, metadata_fields, metadata_verify_fields, encode_metadata, decode_metadata) +from fsck_work_item import WorkItem from repo_factory import ( RepositoryFactory, UnknownRepositoryFormat, diff --git a/obnamlib/plugins/fsck_plugin.py b/obnamlib/plugins/fsck_plugin.py index bdcaf4ab..80b9b8ef 100644 --- a/obnamlib/plugins/fsck_plugin.py +++ b/obnamlib/plugins/fsck_plugin.py @@ -23,16 +23,7 @@ import sys import ttystatus import obnamlib - - -class WorkItem(larch.fsck.WorkItem): - - '''A work item for fsck. - - Whoever creates a WorkItem shall set the ``repo`` to the repository - being used. - - ''' +from obnamlib import WorkItem class CheckChunk(WorkItem): @@ -197,15 +188,6 @@ class CheckClientlist(WorkItem): def do(self): logging.debug('Checking clientlist') clients = self.repo.get_client_names() - if not self.settings['fsck-skip-per-client-b-trees']: - for client_name in clients: - if client_name not in self.settings['fsck-ignore-client']: - # FIXME: This can't be done using the public API of - # RepositoryInterface. The API needs improvement. - client_id = self.repo._client_list.get_client_id( - client_name) - client_dir = self.repo._get_client_dir(client_id) - yield CheckBTree(str(client_dir)) for client_name in clients: if client_name not in self.settings['fsck-ignore-client']: yield CheckClient(client_name) @@ -225,29 +207,6 @@ class CheckForExtraChunks(WorkItem): # self.error('chunk %s not used by anyone' % chunkid) -class CheckBTree(WorkItem): - - def __init__(self, dirname): - self.dirname = dirname - self.name = 'B-tree %s' % dirname - - def do(self): - if not self.repo.get_fs().exists(self.dirname): - logging.debug('B-tree %s does not exist, skipping' % self.dirname) - return - logging.debug('Checking B-tree %s' % self.dirname) - fix = self.settings['fsck-fix'] - # FIXME: The RepositoryInterface API does not have a way to expose - # the "hooked" filesystem, which is necessary for accessing - # the repository using encryption or compression or such. We - # kluge this for now. - forest = larch.open_forest(allow_writes=fix, dirname=self.dirname, - vfs=self.repo._fs) - fsck = larch.fsck.Fsck(forest, self.warning, self.error, fix) - for work in fsck.find_work(): - yield work - - class CheckRepository(WorkItem): def __init__(self): @@ -255,13 +214,9 @@ class CheckRepository(WorkItem): def do(self): logging.debug('Checking repository') - if not self.settings['fsck-skip-shared-b-trees']: - yield CheckBTree('clientlist') - yield CheckBTree('chunklist') - yield CheckBTree('chunksums') - yield CheckClientlist() - for work in self.repo.get_fsck_work_item(): + for work in self.repo.get_fsck_work_items(): yield work + yield CheckClientlist() class FsckPlugin(obnamlib.ObnamPlugin): diff --git a/obnamlib/repo_dummy.py b/obnamlib/repo_dummy.py index a6df73d8..4f2b9a78 100644 --- a/obnamlib/repo_dummy.py +++ b/obnamlib/repo_dummy.py @@ -671,5 +671,5 @@ class RepositoryFormatDummy(obnamlib.RepositoryInterface): def validate_chunk_content(self, chunk_id): return None - def get_fsck_work_item(self): - return 'this pretends to be a work item' + def get_fsck_work_items(self): + return [] diff --git a/obnamlib/repo_fmt_6.py b/obnamlib/repo_fmt_6.py index e6c75173..9bbcec39 100644 --- a/obnamlib/repo_fmt_6.py +++ b/obnamlib/repo_fmt_6.py @@ -822,5 +822,35 @@ class RepositoryFormat6(obnamlib.RepositoryInterface): # Fsck. - def get_fsck_work_item(self): - return [] + def get_fsck_work_items(self): # pragma: no cover + yield CheckBTree('clientlist', 'fsck-skip-shared-b-trees') + for client_name in self.get_client_names(): + client_id = self._get_client_id(client_name) + yield CheckBTree(str(client_id), 'fsck-skip-per-client-b-trees') + yield CheckBTree('chunklist', 'fsck-skip-shared-b-trees') + yield CheckBTree('chunksums', 'fsck-skip-shared-b-trees') + + +class CheckBTree(obnamlib.WorkItem): # pragma: no cover + + def __init__(self, dirname, skip_setting): + self.dirname = dirname + self.skip_setting = skip_setting + self.name = 'B-tree %s' % dirname + + def do(self): + if self.settings[self.skip_setting]: + return + + if not self.repo.get_fs().exists(self.dirname): + logging.debug('B-tree %s does not exist, skipping' % self.dirname) + return + + logging.debug('Checking B-tree %s' % self.dirname) + fix = self.settings['fsck-fix'] + + forest = larch.open_forest( + allow_writes=fix, dirname=self.dirname, vfs=self.repo._fs) + fsck = larch.fsck.Fsck(forest, self.warning, self.error, fix) + for work in fsck.find_work(): + yield work diff --git a/obnamlib/repo_interface.py b/obnamlib/repo_interface.py index f4ab7531..07cf14a5 100644 --- a/obnamlib/repo_interface.py +++ b/obnamlib/repo_interface.py @@ -757,10 +757,17 @@ class RepositoryInterface(object): # Fsck. - def get_fsck_work_item(self): - '''Return an fsck work item for checking this repository. + def get_fsck_work_items(self, settings): + '''Returns fsck work items for checking this repository. - The work item may spawn more items. + This may be a generator or may return an iterable data + structure. + + The returned work items are of type obnamlib.WorkItem. It may + return further work items. + + The settings argument is of type cliapp.Settings, and lets + the user affect what work gets done. ''' raise NotImplementedError() @@ -1848,4 +1855,5 @@ class RepositoryInterfaceTests(unittest.TestCase): # pragma: no cover # Fsck. def test_returns_fsck_work_item(self): - self.assertNotEqual(self.repo.get_fsck_work_item(), None) + for work in self.repo.get_fsck_work_items(): + self.assertNotEqual(work, None) diff --git a/test-gpghome/random_seed b/test-gpghome/random_seed Binary files differindex dc137c22..dd465b71 100644 --- a/test-gpghome/random_seed +++ b/test-gpghome/random_seed diff --git a/without-tests b/without-tests index 7263cb3e..8902448c 100644 --- a/without-tests +++ b/without-tests @@ -2,6 +2,7 @@ ./obnamlib/__init__.py ./obnamlib/app.py ./obnamlib/vfs.py +./obnamlib/fsck_work_item.py ./obnamlib/plugins/backup_plugin.py ./obnamlib/plugins/restore_plugin.py ./obnamlib/plugins/show_plugin.py |