Skip to content

Commit 807a775

Browse files
committed
Implement remove method in local storage backend
Implement the new remove method of StorageBackendInterface in the FilesystemBackend with a simple os.remove() wrapper. Signed-off-by: Joshua Lock <[email protected]>
1 parent 1da1325 commit 807a775

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

securesystemslib/storage.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ def put(self, fileobj, filepath):
233233
"Can't write file %s" % filepath)
234234

235235

236+
def remove(self, filepath):
237+
try:
238+
os.remove(filepath)
239+
except (FileNotFoundError, PermissionError, OSError): # pragma: no cover
240+
raise securesystemslib.exceptions.StorageError(
241+
"Can't remove file %s" % filepath)
242+
243+
236244
def getsize(self, filepath):
237245
try:
238246
return os.path.getsize(filepath)

tests/test_storage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def test_files(self):
8181
with open(put_path, 'rb') as put_file:
8282
self.assertEqual(put_file.read(), self.fileobj.read())
8383

84+
self.assertTrue(os.path.exists(put_path))
85+
self.storage_backend.remove(put_path)
86+
self.assertFalse(os.path.exists(put_path))
87+
8488

8589
def test_folders(self):
8690
leaves = ['test1', 'test2', 'test3']

0 commit comments

Comments
 (0)