File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -254,7 +254,10 @@ def ensure_parent_dir(filename, storage_backend=None):
254254 # Split 'filename' into head and tail, check if head exists.
255255 directory = os .path .split (filename )[0 ]
256256
257- storage_backend .create_folder (directory )
257+ # Check for cases where filename is without directory like 'file.txt'
258+ # and as a result directory is an empty string
259+ if directory :
260+ storage_backend .create_folder (directory )
258261
259262
260263def file_in_confined_directories (filepath , confined_directories ):
Original file line number Diff line number Diff line change @@ -153,6 +153,13 @@ def test_B4_ensure_parent_dir(self):
153153 self .assertRaises (securesystemslib .exceptions .FormatError ,
154154 securesystemslib .util .ensure_parent_dir , parent_dir )
155155
156+ # When we call ensure_parent_dir with filepath arg like "a.txt",
157+ # then the directory of that filepath will be an empty string.
158+ # We want to make sure that securesyslib.storage.create_folder()
159+ # won't be called with an empty string and thus raise an exception.
160+ # If an exception is thrown the test will fail.
161+ securesystemslib .util .ensure_parent_dir ('a.txt' )
162+
156163
157164
158165 def test_B5_file_in_confined_directories (self ):
You can’t perform that action at this time.
0 commit comments