As mentioned in this thread:
isSymbolicLink
on macOS will use the NSFileManager destinationOfSymbolicLinkAtPath
to determine whether a juce::File
is a symbolic link. In the comment for the function it mentions “or alias” but this isn’t the case, as an alias will simply return nil
Since OSX 10.10 there is a better solution that correctly works with aliases and symbolic links:
static NSString* getFileLink (const String& path)
{
NSURL* ns = [NSURL URLByResolvingAliasFileAtURL: createNSURLFromFile (path)
options: NSURLBookmarkResolutionWithoutUI
error: nil];
if ([ns.path compare:juceStringToNS (path)] != NSOrderedSame)
return ns.path;
return nil;
}
The NSURL function will return a valid NSURL for a valid path, regardless of whether it is normal file, symbolic link or alias, hence the comparison with the original file path, with the conclusion being -if they are the same, then the file isn’t a link of any kind
This works well for this function, but it doesn’t help with any other juce::File
function, as doing stat
through the alias path won’t work. The juce::File
functions could be retrofit to use the getLinkedTarget
function throughout, which would work around that, but it will cause other issues. Such as:
juce::File (aliasPath).getChildFile ("childfile")
Does that return the resolved alias path?
I’m inclined to create a wrapper to avoid changing JUCE code too much, but I was wondering if there was a better solution