FileManager.copyItem(atPath:toPath:) not working since iOS / iPad OS 18.4

Hi there,

I have discovered that the behavior of file copying has changed starting from iOS 18.4.
When using FileManager.copyItem(atPath:toPath:) to copy a directory specified as an argument, whether or not there is a trailing slash ('/') affects whether the copy process works correctly.
The same process operates as expected in the iOS 18.3.1 Simulator.
Is this the correct behavior, or could it be a bug?

The application's build environment is Xcode 16.2.

Below is an example of the code. In practice, the file copying is performed within the application's folder.

// Both iOS 18.3.1 and iOS 18.4 successfully complete the copy process.
FileManager.default.copyItem(atPath: "/path/from/dirA", toPath: "/path/to/dirB")
FileManager.default.copyItem(atPath: "/path/from/dirA/", toPath: "/path/to/dirB/")

// iOS 18.3.1 successfully complete the copy process, but iOS 18.4 fails.
FileManager.default.copyItem(atPath: "/path/from/dirA/", toPath: "/path/to/dirB")

I hope this helps Apple engineers and other developers experiencing the same issue. Feedback or additional insights would be appreciated.

I have discovered that the behavior of file copying has changed starting from iOS 18.4. When using FileManager.copyItem(atPath:toPath:) to copy a directory specified as an argument, whether or not there is a trailing slash ('/') affects whether the copy process works correctly. The same process operates as expected in the iOS 18.3.1 Simulator. Is this the correct behavior, or could it be a bug?

I believe it's a bug (likely r.149778441) but, as always, you should file your own bug and then post the number back here.

Having said that, I don't think you'll have this issue with the URL variant, FileManager.copyItem(at:to:), which would match my longstanding advice to avoid string-based paths.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

FileManager.copyItem(atPath:toPath:) not working since iOS / iPad OS 18.4
 
 
Q