views:

23

answers:

1

Hi all,

I have a file open on the iPhone that I am sending the data of across the network (Opened using "_open"). However I have the ability to delete files from the iphone's interface. This is done using NSFileManager's removeItemAtPath.

The odd thing is that removeItemAtPath is succeeding even though the file is currently open.

The file transfers perfectly across the network and removeItemAtPath succeeds before the transfer is complete. So does removeItemAtPath do a lazy delete? ie does it queue it for later if the file is in use? If so then no problems.

If not ... does anyone know how I can get NSFileManager to actually report the fact that it didn't do the delete?

Thanks!

+1  A: 

According to the documentation at

http://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/fileManager:shouldRemoveItemAtPath:

shouldRemoveItemAtPath returns YES if the operation should proceed, not necessarily that it already successfully deleted the item. It's also interesting that the documentation states:

Discussion Returning NO from this method causes NSFileManager to stop deleting the item. If the item is a directory, no children of that item are deleted either.

Reading that leads me to believe this is an asynchronous operation and that the return value of this method should not be used to determine if the file was successfully deleted. My guess is that it queues the object for deletion and will be deleted when the file is no longer in use.

Brazzle
Thats fine for a guess. I need to KNOW. I don't implement shouldRemoveItemAtPath btw. Equally there is nothing stopping that from remaining entirely synchronous. i don't see how this implies any level of asynchronicity ...
Goz
I think it's slightly more than a guess. This is the official Apple docs. If the return value was YES for a successful deletion or NO for an unsuccessful deletion then it would state that. All it tells us, though, is that the method's best guess is that the delete will continue.
Brazzle