mirror of https://github.com/borgbackup/borg.git
commit
65475ea1aa
|
@ -64,18 +64,6 @@ class ErrorWithTraceback(Error):
|
||||||
traceback = True
|
traceback = True
|
||||||
|
|
||||||
|
|
||||||
class InternalOSError(Error):
|
|
||||||
"""Error while accessing repository: [Errno {}] {}: {}"""
|
|
||||||
|
|
||||||
def __init__(self, os_error):
|
|
||||||
self.errno = os_error.errno
|
|
||||||
self.strerror = os_error.strerror
|
|
||||||
self.filename = os_error.filename
|
|
||||||
|
|
||||||
def get_message(self):
|
|
||||||
return self.__doc__.format(self.errno, self.strerror, self.filename)
|
|
||||||
|
|
||||||
|
|
||||||
class IntegrityError(ErrorWithTraceback):
|
class IntegrityError(ErrorWithTraceback):
|
||||||
"""Data integrity error"""
|
"""Data integrity error"""
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
from .constants import * # NOQA
|
from .constants import * # NOQA
|
||||||
from .hashindex import NSIndex
|
from .hashindex import NSIndex
|
||||||
from .helpers import Error, ErrorWithTraceback, IntegrityError, InternalOSError
|
from .helpers import Error, ErrorWithTraceback, IntegrityError
|
||||||
from .helpers import Location
|
from .helpers import Location
|
||||||
from .helpers import ProgressIndicatorPercent
|
from .helpers import ProgressIndicatorPercent
|
||||||
from .helpers import bin_to_hex
|
from .helpers import bin_to_hex
|
||||||
|
@ -258,18 +258,13 @@ class Repository:
|
||||||
except RuntimeError as error:
|
except RuntimeError as error:
|
||||||
assert str(error) == 'hashindex_read failed' # everything else means we're in *deep* trouble
|
assert str(error) == 'hashindex_read failed' # everything else means we're in *deep* trouble
|
||||||
logger.warning('Repository index missing or corrupted, trying to recover')
|
logger.warning('Repository index missing or corrupted, trying to recover')
|
||||||
try:
|
os.unlink(index_path)
|
||||||
os.unlink(index_path)
|
|
||||||
except OSError as e:
|
|
||||||
raise InternalOSError(e) from None
|
|
||||||
if not auto_recover:
|
if not auto_recover:
|
||||||
raise
|
raise
|
||||||
self.prepare_txn(self.get_transaction_id())
|
self.prepare_txn(self.get_transaction_id())
|
||||||
# don't leave an open transaction around
|
# don't leave an open transaction around
|
||||||
self.commit()
|
self.commit()
|
||||||
return self.open_index(self.get_transaction_id())
|
return self.open_index(self.get_transaction_id())
|
||||||
except OSError as e:
|
|
||||||
raise InternalOSError(e) from None
|
|
||||||
|
|
||||||
def prepare_txn(self, transaction_id, do_cleanup=True):
|
def prepare_txn(self, transaction_id, do_cleanup=True):
|
||||||
self._active_txn = True
|
self._active_txn = True
|
||||||
|
@ -307,8 +302,6 @@ class Repository:
|
||||||
self.check_transaction()
|
self.check_transaction()
|
||||||
self.prepare_txn(transaction_id)
|
self.prepare_txn(transaction_id)
|
||||||
return
|
return
|
||||||
except OSError as os_error:
|
|
||||||
raise InternalOSError(os_error) from None
|
|
||||||
if hints[b'version'] == 1:
|
if hints[b'version'] == 1:
|
||||||
logger.debug('Upgrading from v1 hints.%d', transaction_id)
|
logger.debug('Upgrading from v1 hints.%d', transaction_id)
|
||||||
self.segments = hints[b'segments']
|
self.segments = hints[b'segments']
|
||||||
|
|
|
@ -8,7 +8,7 @@ from unittest.mock import patch
|
||||||
|
|
||||||
from ..hashindex import NSIndex
|
from ..hashindex import NSIndex
|
||||||
from ..helpers import Location
|
from ..helpers import Location
|
||||||
from ..helpers import IntegrityError, InternalOSError
|
from ..helpers import IntegrityError
|
||||||
from ..locking import UpgradableLock, LockFailed
|
from ..locking import UpgradableLock, LockFailed
|
||||||
from ..remote import RemoteRepository, InvalidRPCMethod, ConnectionClosedWithHint, handle_remote_line
|
from ..remote import RemoteRepository, InvalidRPCMethod, ConnectionClosedWithHint, handle_remote_line
|
||||||
from ..repository import Repository, LoggedIO, MAGIC
|
from ..repository import Repository, LoggedIO, MAGIC
|
||||||
|
@ -303,7 +303,7 @@ class RepositoryAuxiliaryCorruptionTestCase(RepositoryTestCaseBase):
|
||||||
hints = os.path.join(self.repository.path, 'hints.1')
|
hints = os.path.join(self.repository.path, 'hints.1')
|
||||||
os.unlink(hints)
|
os.unlink(hints)
|
||||||
os.mkdir(hints)
|
os.mkdir(hints)
|
||||||
with self.assert_raises(InternalOSError):
|
with self.assert_raises(OSError):
|
||||||
self.do_commit()
|
self.do_commit()
|
||||||
|
|
||||||
def test_index(self):
|
def test_index(self):
|
||||||
|
@ -321,7 +321,7 @@ class RepositoryAuxiliaryCorruptionTestCase(RepositoryTestCaseBase):
|
||||||
index = os.path.join(self.repository.path, 'index.1')
|
index = os.path.join(self.repository.path, 'index.1')
|
||||||
os.unlink(index)
|
os.unlink(index)
|
||||||
os.mkdir(index)
|
os.mkdir(index)
|
||||||
with self.assert_raises(InternalOSError):
|
with self.assert_raises(OSError):
|
||||||
self.do_commit()
|
self.do_commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue