Re: Terminate File Copy
Re: Terminate File Copy
- Subject: Re: Terminate File Copy
- From: email@hidden (Kris Rambish)
- Date: Thu, 29 Jun 2006 03:07:02 +0000
>From what I have seen, if you want to stop in the middle of a file copy, you are going to have to open the file, read the data out yourself and write it to the new file location.
I assume that you would not want to go down that road. My recommendation would be to use FSCopyObject().
http://developer.apple.com/samplecode/FSCopyObject/index.html
Since you are already spinning off a thread for the sole purpose of file transfer I don't see a reason to make the Async call. While this won't help you with a single large file, if you are transferring an entire folder hierarchy, a callback function is called after each individual file. That way you can at least stop the transfer between individual files.
FYI - If you decide to use FSCopyObject there are different buffer settings you may want to tweak for performance (kDefaultCopyBufferSize).
Kris
-------------- Original message ----------------------
From: "Alan Smith" <email@hidden>
> Hmm. It isn't too obvious how to do this.
>
> I have been working a lot with NSFileManager recently. First, it
> would be a bad idea to stop a file copy. Because if the copy is, say,
> half way done and it is stopped there will be a partial file left on
> disk. Unless you delete that the disk will get fragmented quickly and
> the end-user won't like this.
>
> Why you would want to stop a file copy in mid stream is beyond me.
>
> In fact, what you want to do doesn't seem possible. You won't get
> control back until the copy of the current file is done. Thus, you
> won't know to stop the transfer. I know little of threads so don't
> quote me on this but perhaps you could put the copying of the current
> file in another thread from the checking of the cancel button. This
> way once the button is clicked you could terminate the copying thread,
> stopping it in midstream.
> If you do find a way to stop the transfer I *highly* recommend that
> you delete the last file because it won't be a complete file. You
> don't want to slow the OS because you stopped a file transfer.
>
> Good luck, Alan
>
> On 6/28/06, Aalok <email@hidden> wrote:
> > Hi,
> >
> > In my application, I transfer files from mac to windows(smb). I
> > dispatch a separate thread to the transfer and my UI runs on the main
> > thread.
> >
> > I have a Cancel functionality in the application. Now when a file is
> > under transfer
> > (using [fileManager copyPath:filePath toPath:destination handler:nil])
> > and I press cancel(I set a flag for that), the actual file transfer
> > doesn't stop for that file. The thread terminates after that file
> > transfer is complete. And it doesn't transfer anymore files.
> >
> > I want the functionality which, on Cancel, terminates ongoing file
> > transfer also.
> >
> > Is it possible? If there is some other approach to do that please advice.
> >
> > regards,
> >
> > aalok
> > _______________________________________________
> > Do not post admin requests to the list. They will be ignored.
> > Cocoa-dev mailing list (email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> >
> > This email sent to email@hidden
> >
>
>
> --
> // Quotes from yours truly -------------------------
> "You don't forget, you just don't remember."
> "Maturity resides in the mind."
> "Silence is the Universe's greatest gift."
> "Don't waste your life doing things others have already done."
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden