Skip to content

Commit

Permalink
Merge pull request #260 from MVrachev/fix-empty-directory
Browse files Browse the repository at this point in the history
Fix directory being empty in ensure_parent_dir
  • Loading branch information
joshuagl authored Aug 4, 2020
2 parents 5451477 + 247cf9b commit a7308f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion securesystemslib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ def ensure_parent_dir(filename, storage_backend=None):
# Split 'filename' into head and tail, check if head exists.
directory = os.path.split(filename)[0]

storage_backend.create_folder(directory)
# Check for cases where filename is without directory like 'file.txt'
# and as a result directory is an empty string
if directory:
storage_backend.create_folder(directory)


def file_in_confined_directories(filepath, confined_directories):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ def test_B4_ensure_parent_dir(self):
self.assertRaises(securesystemslib.exceptions.FormatError,
securesystemslib.util.ensure_parent_dir, parent_dir)

# When we call ensure_parent_dir with filepath arg like "a.txt",
# then the directory of that filepath will be an empty string.
# We want to make sure that securesyslib.storage.create_folder()
# won't be called with an empty string and thus raise an exception.
# If an exception is thrown the test will fail.
securesystemslib.util.ensure_parent_dir('a.txt')



def test_B5_file_in_confined_directories(self):
Expand Down

0 comments on commit a7308f0

Please sign in to comment.