swiftlang / swift-foundation

The Foundation project
Apache License 2.0
2.4k stars 159 forks source link

Fix 'var currentDirectoryPath: String' crash when the directory is removed #985

Open ypli-chn opened 3 weeks ago

ypli-chn commented 3 weeks ago

Forced unpacking caused a crash.

let dest = "/tmp/a/b/c"
let fm = FileManager.default
try fm.createDirectory(atPath: dest, withIntermediateDirectories: true, attributes: nil)
let _ = fm.changeCurrentDirectoryPath(dest)
let _ = fm.currentDirectoryPath // it's ok
try fm.removeItem(atPath: dest)
let _ = fm.currentDirectoryPath // will crash

The same code in the old version(<5.10) of swift will be empty string.

ypli-chn commented 3 weeks ago

@swift-ci please test

jmschonfeld commented 3 weeks ago

@swift-ci please test

jmschonfeld commented 3 weeks ago

@swift-ci please test