tags:

views:

98

answers:

1

A tester said that he got this message only once, and I can't seem to reproduce it or figure out how this message appeared. In a nut shell, my application starts a background thread and grabs data from our server. Once we are done downloading the data we store it in an xml file, so we can grab the data from this file incase we shutdown durning the parsing of the xml. Once I am done parsing the xml I delete the file. Here is my code for deleting.

-(void)deleteSavedXmlServerData
{
    AppDelegate_Shared* appDelegate = (AppDelegate_Shared*)[[UIApplication sharedApplication] delegate];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *fileToLoad = [NSString stringWithFormat:@"%@/%@/upload.xml", [paths objectAtIndex:0], appDelegate.userId];

   if([[NSFileManager defaultManager] fileExistsAtPath:fileToLoad] == YES)
   {

        NSError *error = nil;
        [[NSFileManager defaultManager] removeItemAtPath:fileToLoad error:&error];
        if(error != nil)
        {

             eNSLog(@"%s Error Parsing old data: %@ info: %@", __PRETTY_FUNCTION__, error, [error userInfo]);

             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Problem With Syncing" 
                                                        message:@"Problem reading in old data." 
                                                       delegate:nil 
                                              cancelButtonTitle:@"ok" 
                                              otherButtonTitles:nil];
             [alert show];
             [alert release];
        }
    }
}

Everything seems to work perfectly, and it is not a big deal if this file does not get deleted. But I am confused why I would have an issue with deleting this file.

When I checked what the error message was this is what I got this.

 -[ServerSync deleteSavedXmlServerData] Error Parsing old data: Error Domain=NSCocoaErrorDomain Code=4 UserInfo=0x11f3ed60 "Operation could not be completed. (Cocoa error 4.)" info: {
    NSFilePath = "/var/mobile/Applications/CD181518-512F-4A0E-82ED-C438886E4A1D/Documents/71BD9A11-A604-6001-549C-DF6582F60124/upload.xml";
    NSUserStringVariant = Remove;
} 

If anyone know why if my file exist and I created it, why I cannot delete it?

Update

The question that confused me the most, is why does the first if statement say the file exist, but the error message that I get from trying to remove the file says that my file does not exist?

A: 

It looks like the document directory path is /.../71BD9A11-A604-6001-549C-DF6582F60124CD181518-512F-4A0E-82ED-C438886E4A1D/Documents/71BD9A11-A604-6001-549C-DF6582F60124. It should end in /Documents.

Googling for NSCocoaErrorDomain gives NSFileNoSuchFileError = 4.

tc.
Opps, I posted the wrong fileToLoad. I edited the post to the correct one. As to the NSCocoaErrorDomain code, that is the part of my confused. My first if statement checks to see if the file exist, and it does. Why does the remove statement says that it does not exist?
evanchri
You're using threads. Is it possible that another thread accesses it?
tc.
That is a possibility, but this file is only created and deleted on the same thread. It should not be accessed of different threads, unless fileManger does everything on the main thread. I will give this another check.
evanchri
Is it possible that you're starting two threads by accident?
tc.