Skip to content

Commit

Permalink
Merge 807a775 into 01a0c95
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagl committed May 12, 2020
2 parents 01a0c95 + 807a775 commit f5f041a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions securesystemslib/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ def put(self, fileobj, filepath):
raise NotImplementedError # pragma: no cover


@abc.abstractmethod
def remove(self, filepath):
"""
<Purpose>
Remove the file at 'filepath' from the storage.
<Arguments>
filepath:
The full path to the file.
<Exceptions>
securesystemslib.exceptions.StorageError, if the file can not be removed.
<Returns>
None
"""
raise NotImplementedError # pragma: no cover


@abc.abstractmethod
def getsize(self, filepath):
"""
Expand Down Expand Up @@ -214,6 +233,14 @@ def put(self, fileobj, filepath):
"Can't write file %s" % filepath)


def remove(self, filepath):
try:
os.remove(filepath)
except (FileNotFoundError, PermissionError, OSError): # pragma: no cover
raise securesystemslib.exceptions.StorageError(
"Can't remove file %s" % filepath)


def getsize(self, filepath):
try:
return os.path.getsize(filepath)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def test_files(self):
with open(put_path, 'rb') as put_file:
self.assertEqual(put_file.read(), self.fileobj.read())

self.assertTrue(os.path.exists(put_path))
self.storage_backend.remove(put_path)
self.assertFalse(os.path.exists(put_path))


def test_folders(self):
leaves = ['test1', 'test2', 'test3']
Expand Down

0 comments on commit f5f041a

Please sign in to comment.