Issue copying Folders with iOS 18.4

#137 · closed · 4 comments

View on GitHub ↗

jlajara-quadient

Hello, after updating to Xcode 16.3.0 and using the simulator with iOS 18.4 I have a strange behavior causing errors in my unit tests when copying folders. I think the issue comes from this method in Files extension Storage. ![Image](https://github.com/user-attachments/assets/17c857ed-1e15-409e-9696-329e225aab7d) when copying the "Config" folder produces this : <img width="258" alt="Image" src="https://github.com/user-attachments/assets/81f64d06-3d89-4a1c-a1ae-f2f6c30a94aa" /> instead of this : <img width="298" alt="Image" src="https://github.com/user-attachments/assets/ccbbeadb-5966-4eff-a11c-e06d9e5941c9" /> `copyItem(atPath srcPath: String, toPath dstPath: String)` is deprecated using `copyItem(at srcURL: URL, to dstURL: URL)` and converting the path string to URL with `URL(fileURLWithPath: path)` Gives the desired result.

Comments

c128128

Is this library dead? Is it no longer maintained?

jlajara-quadient

seems like it :(

CraigSiemens

There seems to have been a change of behaviour introduced the latest os releases when copying folders. A workaround would be for [Location.copy(to:)](https://github.com/JohnSundell/Files/blob/master/Sources/Files.swift#L173) to add a trailing slash to the path before passing it to `FileManager.copyItem(atPath:toPath:)`. ## Details (FB17323332 and https://github.com/swiftlang/swift-foundation/issues/1266) I can reproduce it on macOS 15.4.1 using only `FileManager` with the following script. ```bash mkdir -p a/b/c z touch a/b/foo.txt echo 'import Foundation; try FileManager.default.copyItem(atPath: "a/b/", toPath: "z/b")' | swift - ``` It will start with the following folder structure before preforming the copy ``` . ├── a │   └── b │   ├── c │   └── foo.txt └── z ``` After the copy, the resulting folder structure should be ``` . ├── a │   └── b │   ├── c │   └── foo.txt └── z └── b ├── c └── foo.txt ``` But it is actually, the following ``` . ├── a │   └── b │   ├── c │   └── foo.txt └── z ├── b ├── bc └── bfoo.txt ``` Adding a trailing slash to the `toPath` to become `”z/b/”` works around the issue.

bens4lsu

I've been having this same issue using the package on macOS. I ended up forking this repo and putting in a fix. It's at https://github.com/bens4lsu/Files. If anyone tries that in iOS, let me know if it fixes the issue. I'd love to see that change merged into this version, but I'm not sure if John is going to resume upkeep or not. He has resumed blog posts, so I'm hopeful.