readium / r2-testapp-swift

BSD 3-Clause "New" or "Revised" License
146 stars 38 forks source link

Move importing file out of tmp folder immediately #184

Closed iaomw closed 6 years ago

iaomw commented 6 years ago

Fix a problem #181 when importing LCP books.

When importing files from other apps or importing from iCloud picker, the temp file will be located in AppData/tmp/org.readium.r2reader-Inbox. This folder is managed by the system. The content will be deleted when iOS system think you don’t need it anymore.

https://stackoverflow.com/questions/37109130/uidocumentpickerviewcontroller-returns-url-to-a-file-that-does-not-exist?rq=1

That will be a problem in LCP process, because the LCP file may already been deleted when the app need embed it into the downloaded epub. But in the current code, the LCP file is not copied to any safer folder, the only move (cut-past) operation happens after book download finished.

This problem didn’t apply to Airdrop, because Airdrop will copy the file to AppData/Documents/Inbox. This is a safe folder, iOS will not trying to delete anything in this folder automatically. https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW28