iOS 14.4 creation of symbolic link failing

I am having trouble on iOS 14.4 creating a symbolic link. This is prompted by the fact that I cannot get a image pointing to a file with spaces in its name to work even if I urlencode the path. I will post about that in a separate request. My work around for the above is to create a symbolic link to a file in the application support directory that is added dynamically as part of normal app function. I tried the URL and the path version of createSymbolicLinkAt<URL,PATH>

path=/var/mobile/Containers/Data/Application/6AFD230E-EC7A-4E50-80A5-38E0DB0B1F07/Library/Application Support/1612401575.M10168/Iridium Portal Icons-Address Book.png

symlinkPath=/var/mobile/Containers/Data/Application/6AFD230E-EC7A-4E50-80A5-38E0DB0B1F07/Library/Application Support/1612401575.M10168/Iridium-Portal-Icons-Address-Book.png

Code Block
NSFileManager* fm = NSFileManager.defaultManager;
NSString* path = [NSString stringWithFormat:@"%@/%@", dir, filename];
NSString *symlinkPath;
NSError *simError;
NSError *urlsimError;
symlinkPath=[path stringByReplacingOccurrencesOfString:@" " withString:@"-"];
[fm createSymbolicLinkAtPath:symlinkPath toPath:path error:&simError];
[fm createSymbolicLinkAtURL:[NSURL fileURLWithPath:symlinkPath] withDestinationURL:[NSURL fileURLWithPath:path] error:&urlsimError];
NSLog(@"%@ %@",@"path = ",path);
NSLog(@"%@ %@",@"symlink path = ",symlinkPath);
NSLog(@"%@ %@",@"by path error = ",simError);
NSLog(@"%@ %@",@"by url error = ",urlsimError);


This is the output of my log message.
Code Block
2021-02-03 21:06:18.968374-0500 APP[1873:455544] path = /var/mobile/Containers/Data/Application/0B4CC298-CEE8-4114-95D0-16F9F526207C/Library/Application Support/1612404374.M43687/Iridium Portal Icons-Address Book.png
2021-02-03 21:06:18.968570-0500 APP[1873:455544] symlink path = /var/mobile/Containers/Data/Application/0B4CC298-CEE8-4114-95D0-16F9F526207C/Library/Application-Support/1612404374.M43687/Iridium-Portal-Icons-Address-Book.png
2021-02-03 21:06:18.977731-0500 APP[1873:455544] by path error = Error Domain=NSCocoaErrorDomain Code=260 "The file “Iridium-Portal-Icons-Address-Book.png” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/0B4CC298-CEE8-4114-95D0-16F9F526207C/Library/Application-Support/1612404374.M43687/Iridium-Portal-Icons-Address-Book.png, NSUnderlyingError=0x282fbb3f0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2021-02-03 21:06:18.980470-0500 APP[1873:455544] by url error = Error Domain=NSCocoaErrorDomain Code=4 "The file “Iridium-Portal-Icons-Address-Book.png” doesn’t exist." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/0B4CC298-CEE8-4114-95D0-16F9F526207C/Library/Application-Support/1612404374.M43687/Iridium-Portal-Icons-Address-Book.png, NSUnderlyingError=0x282fbb420 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}


I do not understand why I am receiving this message. Obviously the file does not exist to be opened at the symbolic link path. That is what I am trying to create so I do not expect it to exist.

Any help is appreciated here.

Accepted Reply

Cocoa’s error handling rules are that:
  • You must check the function result to see whether the operation succeeded or not

  • Then, if the operation failed, you may look at the error returned via an NSError ** parameter

You’re not doing that, so there’s no way to tell whether the -createSymbolicLinkAtPath:… operation actually failed or not.

Tweak your code to check the function result and let us known what you see.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

Replies

This is prompted by the fact that I cannot get a image pointing to a
file with spaces in its name to work even if I urlencode the path. I
will post about that in a separate request.

I’d rather solve that problem than help with a workaround that’s probably unnecessary. Can you post a link to the thread that covers that issue?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Hello,

I solved the primary issue but in the process of exploring I discovered an oddity with symbolic link creation that warrants explanation.
I am trying to create a symbolic link to a file in a subdirectory of the Application Support Directory. When I try to create a symbolic link by path it throws an error. When I repeat the same thing but with URL I do not get an error. I have revised my code above to correct an error that I discovered. For a sanity check I downloaded the app container and inspected the directory and I do not see the symbolic link. what am I missing.

Code Block
NSFileManager* fm = NSFileManager.defaultManager;
NSString* path = [NSString stringWithFormat:@"%@/%@", dir, filename];
NSString *symlinkPath;
NSError *simError;
NSError *urlsimError;
NSString *symlinkFile = [filename stringByReplacingOccurrencesOfString:@" " withString:@"-"]
symlinkPath=[NSString stringWithFormat:@"%@/%@",dir,symlinkFile];
[fm createSymbolicLinkAtPath:symlinkPath toPath:path error:&simError];
[fm createSymbolicLinkAtURL:[NSURL fileURLWithPath:symlinkPath] withDestinationURL:[NSURL fileURLWithPath:path] error:&urlsimError];
NSLog(@"%@ %@",@"path = ",path);
NSLog(@"%@ %@",@"symlink path = ",symlinkPath);
NSLog(@"%@ %@",@"by path error = ",simError);
NSLog(@"%@ %@",@"by url error = ",urlsimError);

And here are the logs.

Code Block
2021-02-04 10:15:46.771684-0500 APP[328:6974] path = /var/mobile/Containers/Data/Application/7741DFF7-5725-464E-B868-67DC2263968C/Library/Application Support/1612451733.M489341/Iridium Portal Icons-Address Book.png
2021-02-04 10:15:46.775637-0500 APP[328:6974] symlink path = /var/mobile/Containers/Data/Application/7741DFF7-5725-464E-B868-67DC2263968C/Library/Application Support/1612451733.M489341/Iridium-Portal-Icons-Address-Book.png
2021-02-04 10:15:46.816424-0500 APP[328:6974] by path error = Error Domain=NSCocoaErrorDomain Code=260 "The file “Iridium-Portal-Icons-Address-Book.png” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/var/mobile/Containers/Data/Application/7741DFF7-5725-464E-B868-67DC2263968C/Library/Application Support/1612451733.M489341/Iridium-Portal-Icons-Address-Book.png, NSUnderlyingError=0x2829e86f0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2021-02-04 10:15:46.816960-0500 APP[328:6974] by url error = (null)

Cocoa’s error handling rules are that:
  • You must check the function result to see whether the operation succeeded or not

  • Then, if the operation failed, you may look at the error returned via an NSError ** parameter

You’re not doing that, so there’s no way to tell whether the -createSymbolicLinkAtPath:… operation actually failed or not.

Tweak your code to check the function result and let us known what you see.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Hello,

Thank you for you engagement. You can close this. I resolved my issue. This engagement has been most helpful.
The functions createSymbolicLinkAtPath and createSymbolicLinkAtURL do work correctly.