Skip to content

Commit

Permalink
Fix permissions when importing a publication (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-menu authored Oct 10, 2023
1 parent f843069 commit 7c04a98
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
5 changes: 2 additions & 3 deletions TestApp/Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.2.2</string>
<string>2.6.0</string>
<key>CFBundleVersion</key>
<string>2.2.2</string>
<string>2.6.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
Expand All @@ -243,7 +243,6 @@
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>processing</string>
</array>
<key>UIFileSharingEnabled</key>
<true/>
Expand Down
15 changes: 8 additions & 7 deletions TestApp/Sources/Library/LibraryService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ final class LibraryService: Loggable {
/// document.
@discardableResult
func importPublication(from sourceURL: URL, sender: UIViewController, progress: @escaping (Double) -> Void = { _ in }) async throws -> Book {
// Necessary to read URL exported from the Files app, for example.
let shouldRelinquishAccess = sourceURL.startAccessingSecurityScopedResource()
defer {
if shouldRelinquishAccess {
sourceURL.stopAccessingSecurityScopedResource()
}
}

var url = try await downloadIfNeeded(sourceURL, progress: progress)
url = try await fulfillIfNeeded(url)
let (pub, mediaType) = try await openPublication(at: url, allowUserInteraction: false, sender: sender)
Expand Down Expand Up @@ -144,13 +152,6 @@ final class LibraryService: Loggable {
/// Moves the given `sourceURL` to the user Documents/ directory.
private func moveToDocuments(from source: URL, title: String, mediaType: MediaType) throws -> URL {
let destination = Paths.makeDocumentURL(title: title, mediaType: mediaType)
// Necessary to read URL exported from the Files app, for example.
let shouldRelinquishAccess = source.startAccessingSecurityScopedResource()
defer {
if shouldRelinquishAccess {
source.stopAccessingSecurityScopedResource()
}
}

do {
// If the source file is part of the app folder, we can move it. Otherwise we make a
Expand Down
4 changes: 0 additions & 4 deletions TestApp/Sources/Reader/Audiobook/AudiobookModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ final class AudiobookModule: ReaderFormatModule {
bookmarks: BookmarkRepository,
highlights: HighlightRepository
) async throws -> UIViewController {
guard publication.metadata.identifier != nil else {
throw ReaderError.epubNotValid
}

let viewController = AudiobookViewController(
publication: publication,
locator: locator,
Expand Down

0 comments on commit 7c04a98

Please sign in to comment.