423,688 Members | 2,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,688 IT Pros & Developers. It's quick & easy.

Filename case-insensitivity on OS X

P: n/a
Afternoon all,

MacOS X seems to have some heretical ideas about the value of case in
paths - it seems to believe that it doesn't exist, more or less, so "touch
foo FOO" touches just one file, you can't have both 'makefile' and
'Makefile' in the same directory,
"os.path.exists(some_valid_path.upper())" returns True even when
"os.path.split(some_valid_path.upper())[1] in
os.listdir(os.path.split(some_valid_path)[0])" returns False, etc
(although, of course, "ls *.txt" doesn't mention any of those .TXT files
lying around).

Just to prove it, here's what unix (specifically, linux) does:

twic@urchin:~$ uname
Linux
twic@urchin:~$ python
Python 2.3.5 (#2, Sep 4 2005, 22:01:42)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import os
filenames = os.listdir(".")
first = filenames[0]
first in filenames True first.upper() in filenames False os.path.exists(os.path.join(".", first)) True os.path.exists(os.path.join(".", first.upper())) False
And here's what OS X does:

Hooke:~ tom$ uname
Darwin
Hooke:~ tom$ python
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information. import os
filenames = os.listdir(".")
first = filenames[0]
first in filenames True first.upper() in filenames False os.path.exists(os.path.join(".", first)) True os.path.exists(os.path.join(".", first.upper())) True


Sigh. Anyone got any bright ideas for working around this, specifically
for os.path.exists? I was hoping there was some os.path.actualpath, so i
could say:

def exists_dontignorecase(path):
return os.path.exists(path) and (path == os.path.actualpath(path))

Java has a java.io.File.getCanonicalPath method that does this, but i
can't find an equivalent in python - is there one?

I can emulate it like this:

def _canonicalise(s, l):
s = s.lower()
for t in l:
if s == t.lower():
return t
raise ValueError, ("could not canonicalise string", s)

def canonicalpath(path):
if (path in ("/", "")):
return path
parent, child = os.path.split(path)
cparent = canonicalpath(parent)
cchild = _canonicalise(child, os.listdir(cparent))
return os.path.join(cparent, cchild)

Or, more crudely, do something like this:

def exists_dontignorecase(path):
dir, f = os.path.split(path)
return f in os.listdir(dir)

But better solutions are welcome.

Thanks,
tom

--
Infantry err, infantry die. Artillery err, infantry die. -- IDF proverb
Jan 3 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Tom Anderson wrote:
Java has a java.io.File.getCanonicalPath method that does this, but i
can't find an equivalent in python - is there one?


What's wrong with: os.path.normcase(path) ?

--Scott David Daniels
sc***********@acm.org
Jan 3 '06 #2

P: n/a
In article <Pi*******************************@urchin.earth.li >,
Tom Anderson <tw**@urchin.earth.li> wrote:
Afternoon all,

MacOS X seems to have some heretical ideas about the value of case in
paths - it seems to believe that it doesn't exist, more or less, so "touch
foo FOO" touches just one file, you can't have both 'makefile' and
'Makefile' in the same directory,
"os.path.exists(some_valid_path.upper())" returns True even when
"os.path.split(some_valid_path.upper())[1] in
os.listdir(os.path.split(some_valid_path)[0])" returns False, etc
(although, of course, "ls *.txt" doesn't mention any of those .TXT files
lying around).

Strictly speaking, it's not OS X, but the HFS file system that is case
insensitive. You can use other file systems, such as "UNIX File
System". Use Disk Utility to create a disk image and then erase it
(again, using Disk Utility) and put UFS on it. You'll find that "touch
foo FOO" will create two files.

--
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.
Jan 3 '06 #3

P: n/a
On Tue, 03 Jan 2006 15:21:19 GMT,
Doug Schwarz <se*@sig.for.address.edu> wrote:
Strictly speaking, it's not OS X, but the HFS file system that is case
insensitive. You can use other file systems, such as "UNIX File
System". Use Disk Utility to create a disk image and then erase it
(again, using Disk Utility) and put UFS on it. You'll find that
"touch foo FOO" will create two files.


You may also find some native Mac OS X applications failing in strange
ways.

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jan 3 '06 #4

P: n/a
Tom Anderson wrote:
Java has a java.io.File.getCanonicalPath method that does this, but i
can't find an equivalent in python - is there one?

I can emulate it like this:


I think it could be implemented more efficiently with getattrlist(2),
looking for ATTR_CMN_NAME. Unfortunately, there appears to be no wrapper
for this function.

Alternatively, you might also find macos.GetFullPathname useful,
although I'm uncertain as to how precisely it is used.

Regards,
Martin
Jan 4 '06 #5

P: n/a
On Tue, 3 Jan 2006, Scott David Daniels wrote:
Tom Anderson wrote:
Java has a java.io.File.getCanonicalPath method that does this, but i can't
find an equivalent in python - is there one?


What's wrong with: os.path.normcase(path) ?


It doesn't work.

Hooke:~ tom$ uname
Darwin
Hooke:~ tom$ python
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import os
path=os.path.join(".", os.listdir(".")[0])
path './.appletviewer' os.path.normcase(path) './.appletviewer' os.path.normcase(path.upper()) './.APPLETVIEWER'


I'm not entirely sure what normcase is supposed to do - the documentation
says "Normalize case of pathname. Has no effect under Posix", which is
less than completely illuminating.

tom

--
It involves police, bailiffs, vampires and a portal to hell under a
tower block in Hackney.
Jan 4 '06 #6

P: n/a
On Tue, 3 Jan 2006, Dan Sommers wrote:
On Tue, 03 Jan 2006 15:21:19 GMT,
Doug Schwarz <se*@sig.for.address.edu> wrote:
Strictly speaking, it's not OS X, but the HFS file system that is case
insensitive.
Aaah, of course. Why on earth didn't Apple move to UFS/FFS/whatever with
the switch to OS X?
You can use other file systems, such as "UNIX File System". Use Disk
Utility to create a disk image and then erase it (again, using Disk
Utility) and put UFS on it. You'll find that "touch foo FOO" will
create two files.


You may also find some native Mac OS X applications failing in strange
ways.


Oh, that's why. :(

tom

--
It involves police, bailiffs, vampires and a portal to hell under a
tower block in Hackney.
Jan 4 '06 #7

P: n/a
>>>>> Doug Schwarz <se*@sig.for.address.edu> (DS) wrote:
DS> In article <Pi*******************************@urchin.earth.li >,
DS> Tom Anderson <tw**@urchin.earth.li> wrote:
Afternoon all,

MacOS X seems to have some heretical ideas about the value of case in
paths - it seems to believe that it doesn't exist, more or less, so "touch
foo FOO" touches just one file, you can't have both 'makefile' and
'Makefile' in the same directory,
"os.path.exists(some_valid_path.upper())" returns True even when
"os.path.split(some_valid_path.upper())[1] in
os.listdir(os.path.split(some_valid_path)[0])" returns False, etc
(although, of course, "ls *.txt" doesn't mention any of those .TXT files
lying around).


DS> Strictly speaking, it's not OS X, but the HFS file system that is case
DS> insensitive. You can use other file systems, such as "UNIX File
DS> System". Use Disk Utility to create a disk image and then erase it
DS> (again, using Disk Utility) and put UFS on it. You'll find that "touch
DS> foo FOO" will create two files.


It seems that with Tiger, HFS+ can be made case-sensitive. I haven't seen
it, only read about it.
--
Piet van Oostrum <pi**@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: pi**@vanoostrum.org
Jan 4 '06 #8

P: n/a
Piet van Oostrum wrote:
It seems that with Tiger, HFS+ can be made case-sensitive. I haven't seen
it, only read about it.


Yes, indeed, that is possible. I tried it, once. Right now I'm using
the case insensitive version again, which should tell you how well it
works - the canon utilities of my camera refused to work for me, as did
Audacity. I didn't encounter any other problems, but that was enough
for me.

As to UFS: it is apparently way slower than HFS+, and only recommended
in special cases, most of which are now advised to use Case-sensitive
HFS+, I believe.

Maarten

Jan 4 '06 #9

P: n/a

On 4 Jan 2006, at 02:50, Tom Anderson wrote:
On Tue, 3 Jan 2006, Dan Sommers wrote:
On Tue, 03 Jan 2006 15:21:19 GMT,
Doug Schwarz <se*@sig.for.address.edu> wrote:
Strictly speaking, it's not OS X, but the HFS file system that is
case
insensitive.


You can choose if HFS+ behaves in a case-preserving, case-insensitive
or case-sensitive manner. See man newfs_hfs. Case sensitive is not
supported on the 'System' volume, but I have several external disks
using it without a problem for do general unix-like development
projects.

hth

Michael
Jan 5 '06 #10

P: n/a

On Jan 4, 2006, at 4:32 AM, Michael Anthony Maibaum wrote:
You can choose if HFS+ behaves in a case-preserving, case-insensitive
or case-sensitive manner. See man newfs_hfs. Case sensitive is not
supported on the 'System' volume, but I have several external disks
using it without a problem for do general unix-like development
projects.


For people without an external disk sitting around, note that you can
also do this via a mountable disk image. Here's an example to create
a case-sensitive HFS+ image:

hdiutil create -size 10m -fs "Case-sensitive HFS+" -volname MyVolume
MyVolume.dmg

For more information, try "hdiutil create" or "man hdiutil".

-dan

--
There is nothing new in the world except the history you do not know.
-Harry Truman
Jan 5 '06 #11

P: n/a

On Jan 3, 2006, at 9:50 PM, Tom Anderson wrote:
On Tue, 3 Jan 2006, Dan Sommers wrote:
On Tue, 03 Jan 2006 15:21:19 GMT,
Doug Schwarz <se*@sig.for.address.edu> wrote:
Strictly speaking, it's not OS X, but the HFS file system that is
case
insensitive.
Aaah, of course. Why on earth didn't Apple move to UFS/FFS/whatever
with
the switch to OS X?
You can use other file systems, such as "UNIX File System". Use
Disk
Utility to create a disk image and then erase it (again, using Disk
Utility) and put UFS on it. You'll find that "touch foo FOO" will
create two files.


You may also find some native Mac OS X applications failing in
strange
ways.


Oh, that's why. :(


That's one reason, but here are two more:

1. It would have broken the expected behavior from the previous 15
years of Mac OS releases. Given Mac users' obsessive attention to
detail regarding the consistency of their environment, this would
*not* have gone over well at all.

2. Mac OS is designed primarily for non-technical users. A case-
sensitive filesystem would just be confusing for the main audience.
If I tried to explain to my mother that Dan.doc is not the same as
DAN.DOC, she would probably tell me I was out of my mind.

Think about it - how many things used by average people are case
sensitive? Passwords? That's about it. (And judging by most user
passwords I have seen, they're almost all lowercase anyway.) Email
addresses, URLs, the search box in Google, your AOL or Jabber buddy
list: all case-insensitive.

Aside from that, what is "right" is a matter of opinion. I prefer
case-insensitive filesystems, and I'm a system administrator who
works on Solaris systems all day. Others I work with refuse to
consider case-insensitive filesystems as anything but a "bug". Who's
right? I don't think there's one true answer...

I'm not trying to get into one of these case sensitivity religious
wars here, just offering an opinion.

-dan

--
For a list of all the ways technology has failed to improve the quality
of life, please press three. -Alice Kahn

Jan 6 '06 #12

P: n/a
Dan Lowe <da*@tangledhelix.com> writes:
Think about it - how many things used by average people are case
sensitive? Passwords? That's about it. (And judging by most user
passwords I have seen, they're almost all lowercase anyway.) Email
addresses, URLs, the search box in Google, your AOL or Jabber buddy
list: all case-insensitive.


Not all URLs. Compare, for example:

http://www.python.org/doc/Summary.html
http://www.python.org/doc/summary.html

--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
Those who can make you believe absurdities
can make you commit atrocities. - Voltaire
Jan 6 '06 #13

P: n/a

On Jan 6, 2006, at 1:13 PM, Mark Jackson wrote:
Dan Lowe <da*@tangledhelix.com> writes:
Think about it - how many things used by average people are case
sensitive? Passwords? That's about it. (And judging by most user
passwords I have seen, they're almost all lowercase anyway.) Email
addresses, URLs, the search box in Google, your AOL or Jabber buddy
list: all case-insensitive.


Not all URLs. Compare, for example:

http://www.python.org/doc/Summary.html
http://www.python.org/doc/summary.html


You are correct, of course. I was thinking of cases like this:

http://www.python.org
HTTP://WWW.PYTHON.ORG
hTtP://www.PyThOn.ORG

So I should have said "hostnames" instead of "URLs". In my
experience, most URLs that are actually typed in are like this...

http://yahoo.com
http://google.com
http://ebay.com
http://apple.com
http://amazon.com

And in that form, they are not case sensitive. They only become that
way when you start putting more on the end. But I'd guess that 90%+
of the time, URLs of that form are clicked on, not typed into the
browser.

-dan

--
You know you've achieved perfection in design, not when you have
nothing more
to add, but when you have nothing more to take away.
-Antoine de Saint-Exupery
Jan 6 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.