Re: Renaming and moving files
Re: Renaming and moving files
- Subject: Re: Renaming and moving files
- From: Chris Parker <email@hidden>
- Date: Fri, 8 Mar 2002 10:42:49 -0800
On Friday, March 8, 2002, at 06:39 AM, Ondra Cada wrote:
AS> Apparently not. I read all this (and other) list's archives a long
time
AS> ago (and again today) and all I saw suggested were NSFileManager's
AS> movePath:toPath: and the rename() function. I decided to go with
the
AS> Cocoa solution, despite the fact it necessitated an intermediate
step
AS> whe renaming a file with just a case change. Seemed to me to work
fine
AS> for the most part...
They differ. movePath:toPath: does always copy (actually I think it's a
grave bug, but there might be reasons which I've missed). rename though
works
as supposed. If it returned errno of EXDEV, you should use
movePath:toPath:
to copy/delete since the move goes across volumes.
movePath:toPath:handler: copies to allow graceful error recovery for
copies, basically. If something goes south, the original should be
present in its untouched form. In the error dictionary returned in the
fileManager:shouldProceedAfterError: method you can determine the error
in question and the path that the error occurred on, which may be deeper
than the original source path.
There is some performance work ongoing on NSFileManager at the moment,
but this behavior is unlikely to change.
AS> Fifteen minutes later when the errors stopped and the hard drive
calmed
AS> down, I was left with ONE app in the Applications folder named
AS> "del0661.72c" (it was System Prefs, and it actually ran fine). No
AS> "Applications two" folder at all. Everything gone.
This is strange indeed! I've never encountered this kind of bug in
OpenStep
(either the original path was unharmed, or the result path was
complete!),
This is the documented, correct behavior for movePath:toPath:handler:.
Andreas, if this is reproducible, would you please file a bug? Include
any permissions that may have changed on the directory, and anything
possibly unusual about your setup and I'll try to recreate it here.
Andreas Schwarz (AS) wrote at Thu, 7 Mar 2002 20:25:17 -0800:
AS> 1) Is there any way to move a file in a more sensible fashion (ie.
AS> without copying everything if the move is within the same volume)?
Yeah, as said above:
(i) try rename; if it worked, all right;
If this is on HFS+ this will work, but bear in mind the
probably-should-be standard "flat filesystem caveat." If you're moving
something with a resource fork or catalog info on a flat filesystem
rename() will lose the corresponding ._ file. rename will look like it
succeeded, but it didn't get everything.
(ii) if it returned EXDEV, use movePath:toPath: which in this case does
exactly what you want.
If you're crossing a mount point, yes.
.chris
--
Chris Parker <email@hidden>
Cocoa Frameworks Engineer
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.