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):
254
254
# Split 'filename' into head and tail, check if head exists.
255
255
directory = os .path .split (filename )[0 ]
256
256
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 )
258
261
259
262
260
263
def 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):
153
153
self .assertRaises (securesystemslib .exceptions .FormatError ,
154
154
securesystemslib .util .ensure_parent_dir , parent_dir )
155
155
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
+
156
163
157
164
158
165
def test_B5_file_in_confined_directories (self ):
You can’t perform that action at this time.
0 commit comments