cryptomator / cryptomator/cryptomator
Images copied out of the Cryptomator vault have a slightly bigger size when using macOS filecopy function
- Dominant language
- Java
- Stars
- 16.1k
- Forks
- 1.5k
- Avg merge
- 2d 45m
- Merged PRs (30d)
- 1
Description
### Please agree to the following
- [x] I have searched [existing issues](https://github.com/cryptomator/cryptomator/issues?q=) for duplicates
- [X] I agree to follow this project's [Code of Conduct](https://github.com/cryptomator/cryptomator/blob/develop/.github/CODE_OF_CONDUCT.md)
### Summary
Images copied out of the Cryptomator vault have a slightly bigger size when using macOS filecopy function
### What software is involved?
- Operating System: macOS 13.2
- Cryptomator: 1.6.17
- Xcode 14.2
### Volume Type
WebDAV
### Steps to Reproduce
1. Run a basic Xcode project with the following code:
```
import Cocoa
@main
class AppDelegate: NSObject, NSApplicationDelegate {
var size = 0
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
var openPanel = NSOpenPanel()
openPanel.canChooseDirectories = true
openPanel.canChooseFiles = false
if openPanel.runModal() == .cancel {
return
}
let destination = openPanel.urls[0]
openPanel = NSOpenPanel()
openPanel.allowsMultipleSelection = true
if openPanel.runModal() == .cancel {
return
}
let sources = openPanel.urls
for source in sources {
print(source.path)
size = try! source.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? 0
source.withUnsafeFileSystemRepresentation { sourcePath in
destination.appendingPathComponent(source.lastPathComponent).withUnsafeFileSystemRepresentation { destinationPath in
do {
let state = copyfile_state_alloc()
defer {
copyfile_state_free(state)
}
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))
}
} catch {
print(error)
}
}
}
}
NSApp.terminate(nil)
}
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 operation = unsafeBitCast(ctx, to: AppDelegate.self)
if !operation.setAsyncCopyProgress(Int64(size)) {
return COPYFILE_QUIT
}
}
return COPYFILE_CONTINUE
}
func setAsyncCopyProgress(_ size: Int64) -> Bool {
print(size, self.size)
return true
}
}
```
2. In the first open panel, select a local destination directory on the Mac.
3. In the second open panel, select the source files in the Cryptomator vault in iCloud Drive. Those files will then be copied into the destination directory.
### Expected Behavior
All copied files should have an equal size to the respective source files.
### Actual Behavior
When copying a set of 128 JPG images, about 80 of them have slightly bigger sizes (e.g. 3.8 MB vs 4.2 MB). When opened in Preview, they appear to be equal.
### Reproducibility
Always
### Relevant Log Output
_No response_
### Anything else?
This seems to be a problem with the filecopy function. I couldn't reproduce the issue when copying the files in the Finder, or with the Terminal `cp` command. It happens only with a Cryptomator vault in iCloud Drive; it doesn't happen with a local vault or with a regular iCloud Drive folder (without Cryptomator).
Contributor guide
Research direction
Start by reproducing the issue with the provided Xcode Swift sample, copying JPG files from a Cryptomator WebDAV vault in iCloud Drive with macOS copyfile, then compare the results with Finder and cp. Investigate the copyfile path and verify that copied files have exactly the source sizes without changing the local-vault or regular iCloud Drive behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- macos, swift
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100