Skip to content

Commit

Permalink
Merge pull request #1096 from TortugaPower/fix-file-references
Browse files Browse the repository at this point in the history
Fix file references checks
  • Loading branch information
GianniCarlo authored Feb 12, 2024
2 parents 046a70f + 3c6fa47 commit bf8a95f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion BookPlayer/Coordinators/ItemListCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ItemListCoordinator: NSObject, Coordinator, AlertPresenter, BPLogger {
fatalError("ItemListCoordinator is an abstract class, override this function in the subclass")
}

@MainActor
func getMainCoordinator() -> MainCoordinator? {
return AppDelegate.shared?.activeSceneDelegate?.mainCoordinator
}
Expand Down Expand Up @@ -117,7 +118,9 @@ class ItemListCoordinator: NSObject, Coordinator, AlertPresenter, BPLogger {
}

func showMiniPlayer(flag: Bool) {
getMainCoordinator()?.showMiniPlayer(flag)
Task { @MainActor in
getMainCoordinator()?.showMiniPlayer(flag)
}
}

func syncList() {
Expand Down
1 change: 1 addition & 0 deletions BookPlayer/Coordinators/LibraryListCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class LibraryListCoordinator: ItemListCoordinator, UINavigationControllerDelegat
$0.lastPathComponent != DataManager.processedFolderName
&& $0.lastPathComponent != DataManager.inboxFolderName
&& $0.lastPathComponent != DataManager.backupFolderName
&& $0.lastPathComponent != DataManager.trashFolderName
}

let sharedURLs = (try? FileManager.default.contentsOfDirectory(
Expand Down
3 changes: 2 additions & 1 deletion BookPlayer/Import/ImportManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ final class ImportManager {
}

public func removeFile(_ item: URL, updateCollection: Bool = true) throws {
if FileManager.default.fileExists(atPath: item.path) {
if FileManager.default.fileExists(atPath: item.path),
FileManager.default.isDeletableFile(atPath: item.path) {
try FileManager.default.removeItem(at: item)
}

Expand Down
3 changes: 2 additions & 1 deletion BookPlayer/Import/Models/ImportOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,13 @@ public class ImportOperation: Operation {
// Add support for iCloud documents
let accessGranted = currentFile.startAccessingSecurityScopedResource()

defer { currentFile.stopAccessingSecurityScopedResource() }

let destinationURL = self.getNextAvailableURL(for: currentFile)

do {
if accessGranted {
try FileManager.default.copyItem(at: currentFile, to: destinationURL)
currentFile.stopAccessingSecurityScopedResource()
} else {
try FileManager.default.moveItem(at: currentFile, to: destinationURL)
}
Expand Down
1 change: 1 addition & 0 deletions Shared/CoreData/DataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class DataManager {
public static let backupFolderName = "BPBackup"
public static let inboxFolderName = "Inbox"
public static let sharedFolderName = "SharedBP"
public static let trashFolderName = ".Trash"
public static var loadingDataError: Error?
private let coreDataStack: CoreDataStack
private var pendingSaveContext: DispatchWorkItem?
Expand Down

0 comments on commit bf8a95f

Please sign in to comment.