2

I've a client-server application on Mac. Client uploads a file and server downloads the file. Sever reads a specific size of bytes from the client and write into the file. But in the middle user can delete the file using Finder context menu or from terminal. I want to stop any write/execution operation on this file from any other application till the download runs. It can be easily done using FILE_SHARE_READ while creating the file on Windows. But how we can achieve the same functionality on Mac?

I've tried advisory locks on Mac but no luck. If process A uses advisory locks on the file then process B can't access it but i can always delete the file using Finder context menu.

1 Answer 1

0

Are you sure you need to do this? So long as you've got an open file handle, it doesn't matter if the file is deleted, you can still read from it until you close the file handle. If the user deletes the file mid-transmission, it won't stop you from sending the full file.

5
  • It's a multithreaded program. It opens the file in append mode when data available and write into the file and then close file handle. User can upload multiple files at a time.
    – Prince
    Mar 8, 2012 at 15:11
  • When the user chooses to upload a file, you open the file, don't you? You'll be able to read from that file until you close it, regardless of whether or not the user deletes it.
    – Jim
    Mar 8, 2012 at 15:13
  • Yes, we can read the file, no problem. Let me clear the case. I mount a file system using Macfuse and user uploads files to this file system. When the upload finishes user should see the files in the file system but if user deletes the file in the middle of upload then when download finishes, my app can't show it to the file system because it is already been into trash.
    – Prince
    Mar 8, 2012 at 15:24
  • Ah, so it's not a local filesystem and the uploading/downloading is done through the filesystem. Understood.
    – Jim
    Mar 8, 2012 at 15:32
  • Even if i download it to local file system and if i move the file into trash in the middle of download how can i see the file in the local file system when download finishes. On windows while i create the file with FILE_SHARE_READ then if one tries to delete the file in the middle of download explore shows some busy message and stop deleting. Is there any way to do that on Mac?
    – Prince
    Mar 9, 2012 at 4:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.