We want to validate file paths, e.g. foo/bar
, which the user can enter. Is it possible to create files with leading or trailing space on OS X or Linux, e.g. foo/ bar /bazz
?
views:
34answers:
3
+1
A:
In most file system you can use on linux, you are not allowed to use "/" and the NULL character in your filename. That's all :)
Nicolas Viennot
2010-08-24 19:44:10
(To be pendantic,) actually some filesystems will even allow you to use `'/'` and `'\0'`, im fairly certain its the *kernel* that doesnt allow that. (Admittedly, most or all drivers for the filesystems that do allow this wont let you create or probably even interact with such files, but the actual layout the filesystem allows them.)
David X
2010-08-24 22:58:19
http://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits Indeed. HFS doesn't like ":" but is happy with "\0"
Nicolas Viennot
2010-08-25 06:09:15
+1
A:
Quick experiment on OS X using the standard Mac OS HFS+ filesystem (the one that will be the default on most users machines). It is possible top create and mount more traditional Unix filesystems.
ls > " foo "
ls > "foo "
ls > " foo"
ls > foo
24 Aug 23:32 foo
24 Aug 23:32 foo
24 Aug 23:32 foo
24 Aug 23:32 foo
ls > "foo/ "
-bash: foo/ : Not a directory
So - leading and trailing space - yes. This ensures compatibility with classic Mac OS files. Use of / - no.
Now try
ls > Foo
and we see that 'foo' is updated. HFS is case insensitive by default (it can be enabled, but if you need to, probably better to use a completely alternative FS)
24 Aug 23:40 foo
This can obviously cause problems translating some standard Unix code to OS X if your code expects Foo and foo to both exist.
JulesLt
2010-08-24 22:45:44