iOS11.2 NSFileManager API behivour is different than previous iOS versions

111 Views Asked by At

I am using below piece of code to calculate a checksum for files I added in a "temp" folder for app bundle. I am getting different checksum values in iOS11.2 compared to all lower iOS version. I was wondering what has changed among these versions? Is some changes in File system in iOS 11.2 is reason for the difference? Can somebody please throw light on the issue or faced similar issues? Below is the piece of code I used.

NSString* bundleRootDir;     
bundleRootDir = [[NSBundle mainBundle] bundlePath];

NSLog(@"bundleRootDir  %@ ",bundleRootDir );

NSString *tmpDir = [bundleRootDir stringByAppendingPathComponent:@"temp"];

NSLog(@"tmpDir  %@ ",tmpDir);

NSFileManager *fileManager1=[[NSFileManager alloc] init];

NSDirectoryEnumerator *dirEnum = [fileManager1 enumeratorAtPath:tmpDir];

// NSFileManager *fileManager1 = [NSFileManager defaultManager];
//NSArray *filePathsArray1 = [fileManager1 subpathsOfDirectoryAtPath:tmpDir  error:nil];

NSMutableData *allFilesData1 = [NSMutableData new];

uLong crc1 = crc32(0L, Z_NULL, 0);

NSInteger filecount1=0;

//for (NSString *file1 in filePathsArray1) {

NSString *file1;

while ((file1 = [dirEnum nextObject])) {

    NSString *fullPathToFile1 = [tmpDir stringByAppendingPathComponent:file1];

    BOOL isDirectory1;

    if ([fileManager1 fileExistsAtPath:fullPathToFile1 isDirectory:&isDirectory1] && isDirectory1 ) {

        // ignore directories...
        continue;
    }
   else {

        NSData *myData1 = [NSData dataWithContentsOfFile:fullPathToFile1];

        [allFilesData1 appendData:myData1];

        NSLog(@"Checksum files included %@ , %d",fullPathToFile1,filecount1);
    }
    filecount1++;
}

NSLog(@"Checksum cal : length of data %lu",[allFilesData1 length]);

NSString *strData = [[NSString alloc]initWithData:allFilesData1 encoding:NSUTF8StringEncoding];

NSLog(@"All Data for checksum %@",strData);

crc1 = crc32(crc, [allFilesData1 bytes], [allFilesData1 length]);

NSLog(@"WL_INIT_PACKAGE - testWebResourcesChecksum crc32 output %lu",crc1);

NSString *checksum1 = [NSString stringWithFormat:@"%lu", crc1];

NSLog(@"WL_INIT_PACKAGE - testWebResourcesChecksum crc32 output %@",checksum1);                           
0

There are 0 best solutions below