Skip to content

Commit

Permalink
fix looping unzip hug
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Mattiello <git@joemattiello.com>
  • Loading branch information
JoeMatt committed Dec 3, 2024
1 parent 20852d8 commit c6032d4
Showing 1 changed file with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,41 @@ public final class PVGameLibraryUpdatesController: ObservableObject {
let status = withObservationTracking {
directoryWatcher.extractionStatus
} onChange: {
let newStatus = self.directoryWatcher.extractionStatus
if newStatus != lastStatus {
DLOG("[\(streamID)] Status changed: \(newStatus)")
continuation.yield(newStatus)
lastStatus = newStatus
Task { @MainActor in
let newStatus = self.directoryWatcher.extractionStatus
if newStatus != lastStatus {
DLOG("[\(streamID)] Status changed to: \(newStatus)")
continuation.yield(newStatus)
lastStatus = newStatus

// If we reach completed or idle state, finish the stream
if case .completed = newStatus {
DLOG("[\(streamID)] Extraction completed, finishing stream")
continuation.finish()
} else if case .idle = newStatus {
DLOG("[\(streamID)] Extraction idle, finishing stream")
continuation.finish()
}
}
}
}

// Only yield initial status if different
if status != lastStatus {
DLOG("[\(streamID)] Initial status: \(status)")
continuation.yield(status)
lastStatus = status

// Check if we should finish the stream on initial status
if case .completed = status {
DLOG("[\(streamID)] Initial status completed, finishing stream")
continuation.finish()
break
} else if case .idle = status {
DLOG("[\(streamID)] Initial status idle, finishing stream")
continuation.finish()
break
}
}

try? await Task.sleep(for: .seconds(0.1))
Expand Down Expand Up @@ -481,11 +504,22 @@ extension PVGameLibraryUpdatesController: ConflictsController {
}

public func deleteConflict(path: URL) async {
DLOG("Deleting conflict file at: \(path.path)")

// First find and remove the item from the import queue
if let index = gameImporter.importQueue.firstIndex(where: { $0.url == path }) {
DLOG("Found matching item in import queue, removing at index \(index)")
gameImporter.removeImports(at: IndexSet(integer: index))
}

// Then delete the actual file
do {
try FileManager.default.removeItem(at: path)
DLOG("Successfully deleted file")
} catch {
ELOG("\(error.localizedDescription)")
ELOG("Failed to delete file: \(error.localizedDescription)")
}

await updateConflicts()
}

Expand Down

0 comments on commit c6032d4

Please sign in to comment.