Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After using the filecopy function, trying to open any file by double clicking it in the Finder only shows an error #3346

Open
2 tasks done
nickasd opened this issue Feb 25, 2024 · 0 comments
Labels
type:bug Something isn't working

Comments

@nickasd
Copy link

nickasd commented Feb 25, 2024

Please agree to the following

Summary

After using the filecopy function, trying to open any file by double clicking it in the Finder only shows an error

What software is involved?

  • Operating System: macOS 14.3
  • Cryptomator: 1.12.0
  • FUSE-T: 1.0.35

Volume Type

FUSE-T

Steps to Reproduce

  1. Build an app with the following code:
import Cocoa

@main
class AppDelegate: NSObject, NSApplicationDelegate {
    
    private var textView: NSTextView!

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        let scrollView = NSScrollView(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
        textView = NSTextView()
        textView.autoresizingMask = [.width, .height]
        scrollView.documentView = textView
        let window = NSWindow(contentRect: scrollView.frame, styleMask: [.titled, .closable], backing: .buffered, defer: false)
        window.contentView = scrollView
        window.makeKeyAndOrderFront(nil)

        let openPanel = NSOpenPanel()
        openPanel.runModal()
        let source = openPanel.urls[0]
        openPanel.canChooseFiles = false
        openPanel.canChooseDirectories = true
        openPanel.runModal()
        let destination = openPanel.urls[0].appendingPathComponent(source.lastPathComponent)
        
        var fcError: NSError?
        var _error: Error?
        log("enter file coordinator")
        NSFileCoordinator(filePresenter: nil).coordinate(readingItemAt: source, options: .withoutChanges, writingItemAt: destination, options: .forReplacing, error: &fcError) { source, destination in
            do {
                try source.withUnsafeFileSystemRepresentation { sourcePath in
                    try destination.withUnsafeFileSystemRepresentation { destinationPath in
                        let state = copyfile_state_alloc()
                        defer {
                            copyfile_state_free(state)
                        }
                        var bsize = UInt32(16_777_216)
                        if copyfile_state_set(state, UInt32(COPYFILE_STATE_BSIZE), &bsize) != 0 {
                            throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno))
                        }
                        log("start copy")
                        if copyfile_state_set(state, UInt32(COPYFILE_STATE_STATUS_CB), unsafeBitCast(copyfileCallback, to: UnsafeRawPointer.self)) != 0 || copyfile_state_set(state, UInt32(COPYFILE_STATE_STATUS_CTX), unsafeBitCast(self, to: UnsafeRawPointer.self)) != 0 || copyfile(sourcePath, destinationPath, state, copyfile_flags_t(COPYFILE_ALL | COPYFILE_NOFOLLOW | COPYFILE_EXCL)) != 0 {
                            throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno))
                        }
                        log("end copy")
                    }
                }
            } catch {
                _error = error
            }
        }
        log("exit file coordinator")
        if let error = (fcError ?? _error) as NSError? {
            log(error.localizedDescription)
            log("\(error.domain) \(error.code)")
        }
    }
    
    private let copyfileCallback: copyfile_callback_t = { what, stage, state, src, dst, ctx in
        if what == COPYFILE_COPY_DATA {
            if stage == COPYFILE_ERR {
                return COPYFILE_QUIT
            }
            var size: off_t = 0
            copyfile_state_get(state, UInt32(COPYFILE_STATE_COPIED), &size)
            let delegate = unsafeBitCast(ctx, to: AppDelegate.self)
            if !delegate.setCopyFileProgress(Int64(size)) {
                return COPYFILE_QUIT
            }
        }
        return COPYFILE_CONTINUE
    }
    
    private func setCopyFileProgress(_ progress: Int64) -> Bool {
        log("copy callback with size \(progress)")
        return true
    }
    
    private func log(_ string: String) {
        textView.textStorage?.append(NSAttributedString(string: string + "\n", attributes: [.foregroundColor: NSColor.labelColor]))
    }
    
}
  1. When running the app, in the first open panel select a source file to be copied (e.g. from the Documents directory). In the second open panel, select a target directory in a Cryptomator vault where the source file should be copied into.
  2. After the copy process has completed, double click a file in the Finder inside the Cryptomator vault.

Expected Behavior

No error should happen.

Actual Behavior

An error dialog like the one below is shown. Translated from German: "The file [...] could not be opened."

Note: I cannot reproduce this issue myself. I was made aware of this issue by a user of one of my apps, and they confirmed that the issue still happens when running the code shown above.

PastedGraphic-2

Reproducibility

Always

Relevant Log Output

No response

Anything else?

No response

@nickasd nickasd added the type:bug Something isn't working label Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant