Re: renaming a file with special/reserved characters in name
Re: renaming a file with special/reserved characters in name
- Subject: Re: renaming a file with special/reserved characters in name
- From: Mike Abdullah <email@hidden>
- Date: Thu, 26 Feb 2009 17:52:41 +0000
Except it doesn't, because each filesystem is different. The above
is
true for HFS+, it is NOT true for FAT32, which has a whole bunch of
other characters which are illegal.
This is the bad news: there is NO way to tell what those
characters are.
It seems totally crazy that there isn't an API for this, Cocoa or
not. Oh
well, obviously one must code to handle a failure in the rename
operation,
so this actually simplifies my task. I still have to hardcode the
magic
conversion of slashes to colons- a shame.
There *can't* be an API for it. Take the case of NFS. NFS has no
character set restrictions beyond the basics that apply to all UNIXen.
But the underlying filesystem that the NFS server is writing things to
may well have more restrictions. You could have an NFS server that
serves files off a FAT32 drive, for example. Or a special NFS server
that requires every third byte of a filename to be an even number.
There is simply no way to communicate this back to the client.
In addition to mapping / to :, I also recommend explicitly stripping
NULs. This may sound useless, but it's not. A user can get a NUL into
a string by copy/pasting from a program which generates them. This
isn't as impossible as it may seem. Once a NUL has found its way into
your program, on the Cocoa side of things it's simply a do-nothing
character that just doesn't take up any space or draw anything. But
when it goes off to the POSIX side of things it will truncate the
string! For example, this string:
@"Hello\x00World"
Will look like this:
@"HelloWorld"
But it will write to this file:
@"Hello"
I've had it happen and it was foolishly annoying to track down.
Definitely worth removing even if it almost never appears.
This sounds a very interesting thing to watch out for. Do you know how
NSString's -fileSystemRepresentation method handles NUL characters?
I'm thinking ideally it should strip them for you. Is there a good way
to reproduce this from the GUI, or is it best to test with hardcoded
strings fed into the system like your example?
Mike.
_______________________________________________
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