Thursday, September 21, 2023
HomeiOS Developmentios - Technique copyItemAtPath fails to seek out present supply file

ios – Technique copyItemAtPath fails to seek out present supply file

[ad_1]

Since few days, I have Xamarin.UITest based tests failing on simulator (did not try device yet), in the following code of my app ( LogConfig() is executed ).

        NSString * configurationCachePath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent: @"config.json"];
        NSString * configurationBundlePath = [[NSBundle mainBundle] pathForResource: @"config" ofType: @"json"];
      
        NSError * error = NULL;
        NSFileManager * defaultFileManager = [NSFileManager defaultManager];
        if (![defaultFileManager fileExistsAtPath: configurationCachePath])
        {
            if (!configurationBundlePath || ![defaultFileManager copyItemAtPath: configurationBundlePath toPath: configurationCachePath error: &error])
            {
                LogConfig(@"Could not copy configuration file from path : %@ to path : %@ - error : %@", configurationBundlePath, configurationCachePath, error);
            }
        }

The output log displayed by the console app is :

Could not copy configuration file from path :
/Users/…/Library/Developer/CoreSimulator/Devices/715BF192-68F3-4120-9224-C2EF4488A3FC/data/Containers/Bundle/Application/20FF49AC-6429-49B3-B6AE-95CD078859AE/App-Calabash.app/config.json
to path :
/Users/…/Library/Developer/CoreSimulator/Devices/715BF192-68F3-4120-9224-C2EF4488A3FC/data/Containers/Data/Application/D8196BA7-E3AE-47B7-8EDA-50513130D719/Library/Caches/config.json

  • error : Error Domain=NSCocoaErrorDomain Code=4 “The file “config.json” doesn’t exist.”
    UserInfo={NSSourceFilePathErrorKey=/Users/…/Library/Developer/CoreSimulator/Devices/715BF192-68F3-4120-9224-C2EF4488A3FC/data/Containers/Bundle/Application/20FF49AC-6429-49B3-B6AE-95CD078859AE/App-Calabash.app/config.json,
    NSUserStringVariant=(
    Copy ), NSDestinationFilePath=/Users/…/Library/Developer/CoreSimulator/Devices/715BF192-68F3-4120-9224-C2EF4488A3FC/data/Containers/Data/Application/D8196BA7-E3AE-47B7-8EDA-50513130D719/Library/Caches/config.json,
    NSFilePath=/Users/…/Library/Deve…

The file seems to exist, and I never had issues with that before :

$ cat /Users/.../Library/Developer/CoreSimulator/Devices/715BF192-68F3-4120-9224-C2EF4488A3FC/data/Containers/Bundle/Application/20FF49AC-6429-49B3-B6AE-95CD078859AE/App-Calabash.app/config.json
{
    ... 
}
Mac-Pro:s $ ls -la /Users/.../Library/Developer/CoreSimulator/Devices/715BF192-68F3-4120-9224-C2EF4488A3FC/data/Containers/Data/Application/D8196BA7-E3AE-47B7-8EDA-50513130D719/Library/Caches/
ls: /Users/.../Library/Developer/CoreSimulator/Devices/715BF192-68F3-4120-9224-C2EF4488A3FC/data/Containers/Data/Application/D8196BA7-E3AE-47B7-8EDA-50513130D719/Library/Caches/: No such file or directory
Mac-Pro:s $ ls -la /Users/.../Library/Developer/CoreSimulator/Devices/715BF192-68F3-4120-9224-C2EF4488A3FC/data/Containers/Data/Application/D8196BA7-E3AE-47B7-8EDA-50513130D719/Library

Any idea on what’s happening ? Is it because the Caches folder does not exists ? Error message says it’s the source file that is missing, but it is there… ?

Could reproduce this issue on Xcode 12.4 or 13 and with iPhone 11 iOS 15 / 14.4 simulators on 2 different mac.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments