Skip to content

Photos save races sendResource and can delete the movie mid-transfer #160

Description

@darioalessandro

RemoteCam/RecordingPipeline.swift:181-215 starts the peer transfer and the Photos save over the same file, concurrently:

private func saveMovieToPhotosAppAndRemotePeer(_ sendVideoToPeer: Bool) {
    let outputFileURL = movieUrl()
    if sendVideoToPeer {
        sendVideoAsResource(outputFileURL)          // fire-and-forget into the actor
    } ...
    PHPhotoLibrary.requestAuthorization { [weak self] status in
        if status == .authorized {
            PHPhotoLibrary.shared().performChanges({
                options.shouldMoveFile = true       // :197 — MOVES the file being transferred
                ...
            }, completionHandler: { success, error in
                cleanupFileAt(outputFileURL)        // :205 — DELETES it
            })
        } else {
            cleanupFileAt(outputFileURL)            // :212 — DELETES it on denial
        }
    }
}

movieUrl() is a single fixed temp path (RemoteCam/MediaProcessors.swift:13-15), so there is exactly one file and two owners.

If the Photos leg wins — denial fires :212 almost immediately — handleSendVideoResource's FileManager.default.attributesOfItem (SessionCoordinator.swift:1097) throws, producing VideoResourceTransferFailed. Which lands on the :936 case (see the sibling issue) and may be swallowed.

Fix direction: give each recording a unique temp path, and don't hand the file to Photos (shouldMoveFile) or delete it until the peer transfer has finished with it.

Not observed in the wild; found by inspection while diagnosing the Mac recording hang (PR #157).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions