PDA

View Full Version : createDirectoryAtPath fails to copy the file




imranpundeer
Jun 28, 2009, 01:17 AM
Hello Friends,
I am using createDirectoryAtPath API of NSFileManager class to copy the a .xcodeProj file(Package File) at network location. I gave three attempts one by one to copy the package file.
1. Network device is connected, File copied successfully.
2. Now Network device disconnected, File doesn’t copied successfully. (that’s genuinely fine).
3. Now Network device again mounted to the system, File doesn’t copy it returns error #2, No such file or directory for the destination.
I am surprise why it’s happened for the same file and path if device is connected after disconnect the device.
Any idea or help would be appricated.

Regards,
Imran



Eraserhead
Jun 28, 2009, 04:30 AM
Are you doing this locally or on another machine?

larkost
Jun 28, 2009, 01:53 PM
First off, I assume you are using something other than createDirectoryAtPath. That does not copy any files, but just creates a directory. So either you are just creating a directory, or you are using a different method. In either case you really need to clarify this.

Second, are you sure that your network mount actually has the same path? If you tried it like you have documented you could have created folders at the mount point, and then the automounter would have put the mount at a different path.

imranpundeer
Jun 28, 2009, 11:26 PM
Thanks for the reply,
Yes, the location is network location.
Yes you are right, createDirectoryPath just create a directory, after creaing a complete path I am trying to copy the file at that created destination path. But copyPath( NSFileManager API) gives the same error only for packages file not for simple files like .c, .m, .h, .txt etc…
Here the sample code -

CopyFile("/Hello/MV_Project_10.3/CopyPathPlugin Source/CopyPathPlugin.xcodeproj", "/Volumes/nw_Fat/Test/CopyPathPlugin.xcodeproj");

usleep(10*1000*1000);



CopyFile("/Hello/MV_Project_10.3/CopyPathPlugin Source/CopyPathPlugin.xcodeproj",
"/Volumes/nw_Fat/Test/CopyPathPlugin.xcodeproj");

usleep(10*1000*1000);


CopyFile("/Hello/MV_Project_10.3/CopyPathPlugin Source/CopyPathPlugin.xcodeproj",
"/Volumes/nw_Fat/Test/CopyPathPlugin.xcodeproj");



void CopyFile(char* pcPath, char* pcDest)
{
BOOL bStat = YES;
int dwError =0;

NSFileManager *fileMgr = [NSFileManager defaultManager];

if (fileMgr)
{
if([fileMgr fileExistsAtPath:[NSString stringWithUTF8String: pcPath]])
{
bStat = [fileMgr copyPath:[NSString stringWithUTF8String: pcPath] toPath:[NSString stringWithUTF8String: pcDest] handler: NULL];
}
if (bStat == NO)
{
dwError =errno;

}
}

}

Network shared folder name is is nw_Fat and Test folder is already created.
copyFile attemp-
1. Device is mounted, copy success.
2. Device unmounted, copy fail( reasonable).
3. Device again mounted, copy still fails return No such file or directory.

So even i attempted on hard coded path it still fails on last copy file.


Thanks.

lloyddean
Jun 29, 2009, 01:13 PM
No experience with NSFileManager (long time C/C++ programmer) but
from reading the 'copyPath:toPath:handler' documentation:

"The file specified in source must exist, while destination must
not exist prior to the operation. When a file is being copied, the
destination path must end in a filename—there is no implicit
adoption of the source filename."

If I'm reading your code correctly you're attempting to copy the
same directory, "CopyPathPlugin.xcodeproj" (as packages are
directories), overtop an existing copy of the same directory.

imranpundeer
Jun 29, 2009, 10:41 PM
Hi,
Thanks for the reply.
I did test the above code while i was debugging.
So before attempt a copy in the second step i deleted the existing .xcodeproj file after that i tried for copy in 2 step and after sleep i again give a copy in third step as will see in my code.

Is it possible that there might be a bug in copyPath API while attempt a copy at Network device during mount and unmount of device for packages file?

Thanks,
Shadab