Repository: borgbackup/borg

Issue:
get rid of InternalOSError in master branch



Discussion:

Resolving patch:
diff --git a/src/borg/helpers.py b/src/borg/helpers.py
--- a/src/borg/helpers.py
+++ b/src/borg/helpers.py
@@ -64,18 +64,6 @@ class ErrorWithTraceback(Error):
     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):
     """Data integrity error"""
 
diff --git a/src/borg/repository.py b/src/borg/repository.py
--- a/src/borg/repository.py
+++ b/src/borg/repository.py
@@ -17,7 +17,7 @@
 
 from .constants import *  # NOQA
 from .hashindex import NSIndex
-from .helpers import Error, ErrorWithTraceback, IntegrityError, InternalOSError
+from .helpers import Error, ErrorWithTraceback, IntegrityError
 from .helpers import Location
 from .helpers import ProgressIndicatorPercent
 from .helpers import bin_to_hex
@@ -258,18 +258,13 @@ def open_index(self, transaction_id, auto_recover=True):
         except RuntimeError as error:
             assert str(error) == 'hashindex_read failed'  # everything else means we're in *deep* trouble
             logger.warning('Repository index missing or corrupted, trying to recover')
-            try:
-                os.unlink(index_path)
-            except OSError as e:
-                raise InternalOSError(e) from None
+            os.unlink(index_path)
             if not auto_recover:
                 raise
             self.prepare_txn(self.get_transaction_id())
             # don't leave an open transaction around
             self.commit()
             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):
         self._active_txn = True
@@ -307,8 +302,6 @@ def prepare_txn(self, transaction_id, do_cleanup=True):
                 self.check_transaction()
                 self.prepare_txn(transaction_id)
                 return
-            except OSError as os_error:
-                raise InternalOSError(os_error) from None
             if hints[b'version'] == 1:
                 logger.debug('Upgrading from v1 hints.%d', transaction_id)
                 self.segments = hints[b'segments']
diff --git a/src/borg/testsuite/repository.py b/src/borg/testsuite/repository.py
--- a/src/borg/testsuite/repository.py
+++ b/src/borg/testsuite/repository.py
@@ -8,7 +8,7 @@
 
 from ..hashindex import NSIndex
 from ..helpers import Location
-from ..helpers import IntegrityError, InternalOSError
+from ..helpers import IntegrityError
 from ..locking import UpgradableLock, LockFailed
 from ..remote import RemoteRepository, InvalidRPCMethod, ConnectionClosedWithHint, handle_remote_line
 from ..repository import Repository, LoggedIO, MAGIC
@@ -303,7 +303,7 @@ def test_unreadable_hints(self):
         hints = os.path.join(self.repository.path, 'hints.1')
         os.unlink(hints)
         os.mkdir(hints)
-        with self.assert_raises(InternalOSError):
+        with self.assert_raises(OSError):
             self.do_commit()
 
     def test_index(self):
@@ -321,7 +321,7 @@ def test_unreadable_index(self):
         index = os.path.join(self.repository.path, 'index.1')
         os.unlink(index)
         os.mkdir(index)
-        with self.assert_raises(InternalOSError):
+        with self.assert_raises(OSError):
             self.do_commit()
 
 


Test patch: