File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ open class FileManager : NSObject {
150
150
var isDir : ObjCBool = false
151
151
if !fileExists( atPath: path, isDirectory: & isDir) {
152
152
let parent = path. _nsObject. deletingLastPathComponent
153
- if !fileExists( atPath: parent, isDirectory: & isDir) {
153
+ if !parent . isEmpty && ! fileExists( atPath: parent, isDirectory: & isDir) {
154
154
try createDirectory ( atPath: parent, withIntermediateDirectories: true , attributes: attributes)
155
155
}
156
156
if mkdir ( path, S_IRWXU | S_IRWXG | S_IRWXO) != 0 {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ class TestFileManager : XCTestCase {
33
33
( " test_copyItemAtPathToPath " , test_copyItemAtPathToPath) ,
34
34
( " test_homedirectoryForUser " , test_homedirectoryForUser) ,
35
35
( " test_temporaryDirectoryForUser " , test_temporaryDirectoryForUser) ,
36
+ ( " test_creatingDirectoryWithShortIntermediatePath " , test_creatingDirectoryWithShortIntermediatePath) ,
36
37
]
37
38
}
38
39
@@ -111,6 +112,20 @@ class TestFileManager : XCTestCase {
111
112
}
112
113
}
113
114
115
+ func test_creatingDirectoryWithShortIntermediatePath( ) {
116
+ let fileManager = FileManager . default
117
+ fileManager. changeCurrentDirectoryPath ( NSTemporaryDirectory ( ) )
118
+
119
+ let relativePath = NSUUID ( ) . uuidString
120
+
121
+ do {
122
+ try fileManager. createDirectory ( atPath: relativePath, withIntermediateDirectories: true , attributes: nil )
123
+ try fileManager. removeItem ( atPath: relativePath)
124
+ } catch {
125
+ XCTFail ( " Failed to create and clean up directory " )
126
+ }
127
+ }
128
+
114
129
func test_moveFile( ) {
115
130
let fm = FileManager . default
116
131
let path = NSTemporaryDirectory ( ) + " testfile \( NSUUID ( ) . uuidString) "
You can’t perform that action at this time.
0 commit comments