bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSFileManager -fileExistsAtPath: exception


From: Richard Frith-Macdonald
Subject: Re: NSFileManager -fileExistsAtPath: exception
Date: Wed, 8 May 2013 07:37:01 +0100

On 7 May 2013, at 21:15, Cameron Pulsford <cpulsfor@me.com> wrote:

> I am using debian wheezy with hand built gnustep 1.24 and the gcc 4.7.2 objc 
> runtime.
> 
> I am getting an exception from calling [[NSFileManager defaultManager] 
> fileExistsAtPath:] with the following two arguments and presumably others:
> 
> @"/home/user/GNUstep/Library/ApplicationSupport/Foo/mediaServer/Jeff Hamilton 
> Trio-NS/J.Hamilton/Beatles.png"
> @"/home/user/GNUstep/Library/ApplicationSupport/Foo/mediaServer/Brad White & 
> Pierre Grill-Winter’s Journey.png"
> 
> Here are those strings again converted with CFStringTransform to include the 
> unicode special character names:
> 
> @"/home/user/GNUstep/Library/ApplicationSupport/Foo/mediaServer/Jeff Hamilton 
> Trio-NS/J.Ham\N{FULLWIDTH LATIN SMALL LETTER I}lton/Beatles.png"
> @"/home/user/GNUstep/Library/ApplicationSupport/Foo/mediaServer/Brad White & 
> Pierre Grill-Winter\N{RIGHT SINGLE QUOTATION MARK}s Journey.png"
> 
> Internally, that method eventually calls [GSUnicodeString 
> cStringUsingEncoding:NSISOLatin1StringEncoding] which raises this exception: 
> <NSException: 0x83a29bc> NAME:NSCharacterConversionException REASON:Can't get 
> cString from Unicode string. INFO:(null)
> 
> I do not get this crash when running the same code on a mac. Is there any way 
> I should be sanitizing strings before I pass them to the -fileExistsAtPath: 
> method?

There should be no need ... the string is automatically converted to the file 
system encoding (the same thing as the default C-string encoding).
The problem here seems to be that your system is using the default encoding 
(latin1) and presumably your system is actually using a utf-8 based encoding.

Now, the default encoding should be automatically inferred from your operating 
system's nl_langinfo() function ... but may be set/overridden with the 
GNUSTEP_STRING_ENCODING environment variable.
So you could try setting the environment variable to the encoding you want to 
use.

Better still, you could run your code under gdb and set a breakpoint in the 
GSPrivateDefaultCStringEncoding() function (base/Source/Additions/Unicode.m) 
and step through and see if you can figure out why the automatic selection of 
encoding is not working (so we can improve that).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]