Fix bug; added test for quarantined a hash dir that becomes a file
This commit is contained in:
parent
a68e5d883c
commit
dfd61697c1
@ -258,6 +258,12 @@ class DatabaseBroker(object):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
def possibly_quarantine(self, exc_type, exc_value, exc_traceback):
|
def possibly_quarantine(self, exc_type, exc_value, exc_traceback):
|
||||||
|
"""
|
||||||
|
Checks the exception info to see if it indicates a quarantine situation
|
||||||
|
(malformed or corrupted database). If not, the original exception will
|
||||||
|
be reraised. If so, the database will be quarantined and a new
|
||||||
|
sqlite3.DatabaseError will be raised indicating the action taken.
|
||||||
|
"""
|
||||||
if 'database disk image is malformed' in str(exc_value):
|
if 'database disk image is malformed' in str(exc_value):
|
||||||
exc_hint = 'malformed'
|
exc_hint = 'malformed'
|
||||||
elif 'file is encrypted or is not a database' in str(exc_value):
|
elif 'file is encrypted or is not a database' in str(exc_value):
|
||||||
|
@ -80,7 +80,7 @@ def hash_suffix(path, reclaim_age):
|
|||||||
try:
|
try:
|
||||||
files = os.listdir(hsh_path)
|
files = os.listdir(hsh_path)
|
||||||
except OSError, err:
|
except OSError, err:
|
||||||
if err.ernno == errno.ENOTDIR:
|
if err.errno == errno.ENOTDIR:
|
||||||
partition_path = dirname(path)
|
partition_path = dirname(path)
|
||||||
objects_path = dirname(partition_path)
|
objects_path = dirname(partition_path)
|
||||||
device_path = dirname(objects_path)
|
device_path = dirname(objects_path)
|
||||||
|
@ -205,6 +205,27 @@ class TestObjectReplicator(unittest.TestCase):
|
|||||||
self.assertEquals(hashed, 1)
|
self.assertEquals(hashed, 1)
|
||||||
self.assert_('a83' in hashes)
|
self.assert_('a83' in hashes)
|
||||||
|
|
||||||
|
def test_hash_suffix_hash_dir_is_file_quarantine(self):
|
||||||
|
df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
|
||||||
|
mkdirs(os.path.dirname(df.datadir))
|
||||||
|
open(df.datadir, 'wb').close()
|
||||||
|
ohash = hash_path('a', 'c', 'o')
|
||||||
|
data_dir = ohash[-3:]
|
||||||
|
whole_path_from = os.path.join(self.objects, '0', data_dir)
|
||||||
|
orig_quarantine_renamer = object_replicator.quarantine_renamer
|
||||||
|
called = [False]
|
||||||
|
|
||||||
|
def wrapped(*args, **kwargs):
|
||||||
|
called[0] = True
|
||||||
|
return orig_quarantine_renamer(*args, **kwargs)
|
||||||
|
|
||||||
|
try:
|
||||||
|
object_replicator.quarantine_renamer = wrapped
|
||||||
|
object_replicator.hash_suffix(whole_path_from, 101)
|
||||||
|
finally:
|
||||||
|
object_replicator.quarantine_renamer = orig_quarantine_renamer
|
||||||
|
self.assertTrue(called[0])
|
||||||
|
|
||||||
def test_hash_suffix_one_file(self):
|
def test_hash_suffix_one_file(self):
|
||||||
df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
|
df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
|
||||||
mkdirs(df.datadir)
|
mkdirs(df.datadir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user