Skip to content

Commit

Permalink
Move tmp files to Documents folder
Browse files Browse the repository at this point in the history
  • Loading branch information
GianniCarlo committed Apr 26, 2024
1 parent b1a9eb6 commit 2db4aa8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 10 additions & 1 deletion BookPlayer/Coordinators/LibraryListCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,17 @@ class LibraryListCoordinator: ItemListCoordinator, UINavigationControllerDelegat
}

func processFiles(urls: [URL]) {
let temporaryDirectoryPath = FileManager.default.temporaryDirectory.absoluteString
let documentsFolder = DataManager.getDocumentsFolderURL()

for url in urls {
self.importManager.process(url)
/// At some point (iOS 17?), the OS stopped sending the picked files to the Documents/Inbox folder, instead
/// it's now sent to a temp folder that can't be relied on to keep the file existing until the import is finished
if url.absoluteString.contains(temporaryDirectoryPath) {
try! FileManager.default.moveItem(at: url, to: documentsFolder)
} else {
importManager.process(url)
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion BookPlayer/Library/ItemList Screen/ItemListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,20 @@ class ItemListViewModel: ViewModelProtocol {
// MARK: - Import related functions
extension ItemListViewModel {
func handleNewFiles(_ urls: [URL]) {
let temporaryDirectoryPath = FileManager.default.temporaryDirectory.absoluteString
let documentsFolder = DataManager.getDocumentsFolderURL()

for url in urls {
importManager.process(url)
/// At some point (iOS 17?), the OS stopped sending the picked files to the Documents/Inbox folder, instead
/// it's now sent to a temp folder that can't be relied on to keep the file existing until the import is finished
if url.absoluteString.contains(temporaryDirectoryPath) {
let destinationURL = documentsFolder.appendingPathComponent(url.lastPathComponent)
if !FileManager.default.fileExists(atPath: destinationURL.path) {
try! FileManager.default.copyItem(at: url, to: destinationURL)
}
} else {
importManager.process(url)
}
}
}

Expand Down

0 comments on commit 2db4aa8

Please sign in to comment.