Hacker News new | ask | show | jobs
by jimsmart 2114 days ago
> Very costly, but the only way to give case-insensitivity.

That is very costly — but it's certainly not the only way to provide case-insensitivity, nor is it the recommended way, and I'd be surprised if any implementation of case-insensitivity actually did what you say.

Normally one would lowercase (or uppercase) both strings, and then do the comparison.

The complexity here usually comes when case-folding various tricky locales.

1 comments

You are incorrect. It is the only way for a user-space application to provide Windows-style case insensitivity.

Windows slient sends a name "foo" over SMB2+. Samba does a stat("foo", &st) call, gets ENOENT.

Now, does that name really not exist ? Or is it there in the requested directory under any of the names "FOO"/"FOo"/"Foo"/"fOo"/"fOO"/"FoO" etc. ?

The only way for an application to tell is to do:

opendir() fname = readdir().... check strlower(client_provided_name, fname); closedir().

If the file really doesn't exist you have ended up scanning the whole directory.

Because Linux doesn't provide directory leasing you have to do this for every missed lookup (another process might have created it in the meantime).

There is no POSIX API for "does this file exist under another cased name" ? If there were Samba would use it.

Ah, my bad: In the post I was replying to, I thought you were saying that all of the permutation were enumerated and tested for — which we can all agree is terrible.

I now understand you mean that the directory is in fact scanned (and filenames compared in a case insensitive manner) once a miss occurs. Which is what I was hinting at.

Apologies, I misunderstood your post — and my reply could have been clearer also.