Re: Unicode filenames with Apple File System and UIManagedDocument
Re: Unicode filenames with Apple File System and UIManagedDocument
- Subject: Re: Unicode filenames with Apple File System and UIManagedDocument
- From: Charles Srstka <email@hidden>
- Date: Tue, 21 Mar 2017 09:58:44 -0500
> On Mar 21, 2017, at 9:13 AM, email@hidden wrote:
>
>>
>> On Mar 21, 2017, at 8:33 AM, Jean-Daniel <email@hidden <mailto:email@hidden>> wrote:
>>
>>
>>> Le 21 mars 2017 à 12:03, email@hidden a écrit :
>>>
>>>>
>>>> On Mar 21, 2017, at 1:06 AM, Jens Alfke <email@hidden> wrote:
>>>>
>>>>
>>>>> On Mar 20, 2017, at 2:23 PM, email@hidden wrote:
>>>>>
>>>>> NSURL *url = [[self courseDirectory] URLByAppendingPathComponent:name];
>>>>
>>>> There’s nothing wrong with that call; it’s the canonical way to add a path component to a URL, filesystem or not.
>>>>
>>>>> NSURL *url = [NSURL fileURLWithFileSystemRepresentation:[name fileSystemRepresentation] isDirectory:YES relativeToURL:[self courseDirectory]];
>>>>
>>>> This call doesn’t make sense. You’re converting to filesystem representation and then back again, for no reason.
>>>>
>>>> What Apple suggested is to Unicode-normalize the filename before adding it to the URL. Did you try doing that?
>>>>
>>>> —Jens
>>>
>>> Jens,
>>>
>>> I’m trying to find out what that means. Someone suggested off-list to me that I should be calling this:
>>>
>>> https://developer.apple.com/reference/foundation/nsstring/1409474-decomposedstringwithcanonicalmap?language=objc
>>>
>>> Is that correct?
>>>
>>> So based on that, I think it means I should do:
>>>
>>> NSURL *url = [[self courseDirectory] URLByAppendingPathComponent:name.decomposedStringWithCanonicalMapping];
>>>
>>> Thanks,
>>> Dave Reed
>>>
>>
>> This is what the reply suggest but that make no sens for me. If you are accessing the file using URL, that the work of the framework to convert the URL into the right file system representation.
>>
>> That said, if using name.decomposedStringWithCanonicalMapping fix your problem, so go with it.
>
> Unfortunately, I can't tell. One user told me he couldn't open his files (with Arabic names) after upgrading to iOS 10.3 public beta. He then changed the names to English names and was able to open the files. He sent me some sample files that I can open (but they were zipped by my app and then unzipped by me) so I honestly can't tell if any of these changes have different effects. With all the options I've tried, I can open the files on my 10.2 and my 10.3 developer device.
>
> If he creates files with Arabic names on 10.3 he can open them so something happened in the 10.2 to 10.3 (which is why I suspect APFS) upgrade that prevents files created with 10.2 from being opened with 10.3.
>
> My plan to test it is to take a file created with 10.2 using an Arabic name and see what happens when I upgrade my regular phone to 10.3 but obviously that's time consuming and I only plan to do that upgrade once since it's a pain to downgrade (and not certain it would be possible with the APFS change).
>
> That's why I keep emailing about this - I can't test it and can't find specific documentation from Apple that says exactly how to create a NSURL from a NSString that may contain Unicode characters.
>
> Thanks,
> Dave Reed
Maybe you could make a debug build and send it to him (can you do that on iOS?) with some code that logs the raw Unicode characters of the filenames in the directory, without the name getting changed/decomposed/recomposed/etc by the zip/unzip process, and have him send you the output. Something like:
void LogFilenames(NSURL *url) {
DIR *dir = opendir(url.fileSystemRepresentation);
struct dirent *file;
while ((file = readdir(dir))) {
NSData *nameData = [[NSData alloc] initWithBytes:file->d_name length:file->d_namlen];
NSLog(@"%@", nameData);
}
closedir(dir);
}
This’ll be in UTF-8 instead of the underlying UTF-16, of course, but it should still be useful in figuring out what’s going on.
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden