directory bug on linux; workaround?

R

Russell E. Owen

I stumbled across a really strange bug involving directories on linux.

os.path.exists(path) can return 0 even after os.path.mkdir(path)
succeeds (well after; this isn't a timing issue).

For the first file, the directory did not exist, so my code created the
directory (successfully) using os.path.mkdir(path). The next file
failed because os.path.exists(path) returned false, so my code tried to
create the directory again, which failed with "directory exists".

It seems that the path was to a "fat" file partition and included a
directory name that was all uppercase. The directory was created, but
using lowercase. I'm not yet sure the version of python.

The workaround for now is to not use fat file partitions. But I was
wondering if anyone had a better option?

-- Russell
 
J

Jeff Epler

Python is at the whim of the services the OS provides. Maybe you should
ask in a linux-related newsgroup or mailing list, they might know more
about the specifics of both detecting and working around "weird"
filesystems like "fat".

To find the type of a filesystem, Linux provides the statfs(2) function,
but no built-in Python module includes access to that function. Writing
the wrapper would be an easy first exercise in extending Python, or using
Pyrex or ctypes. The filesystem "magic numbers" also aren't available
in Python. A partial list can be found by "grep _SUPER_MAGIC
/usr/include/linux/*"

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFB5wrnJd01MZaTXX0RAmaEAJ0c7Tp8L5+khdAlyuCu9ALe3P1OvwCggsf5
bWo4NJE5ldXwuwaRWvbXZo0=
=J97L
-----END PGP SIGNATURE-----
 
J

John Lenton

I stumbled across a really strange bug involving directories on linux.

os.path.exists(path) can return 0 even after os.path.mkdir(path)
succeeds (well after; this isn't a timing issue).

For the first file, the directory did not exist, so my code created the
directory (successfully) using os.path.mkdir(path). The next file
failed because os.path.exists(path) returned false, so my code tried to
create the directory again, which failed with "directory exists".

It seems that the path was to a "fat" file partition and included a
directory name that was all uppercase. The directory was created, but
using lowercase. I'm not yet sure the version of python.

The workaround for now is to not use fat file partitions. But I was
wondering if anyone had a better option?

the bug is because os.path is assuming posix semantics, which fat
doesn't have.

Not using fat sounds like the best idea to me, but I'm probably
strongly biased against that piece of crap.

--
John Lenton ([email protected]) -- Random fortune:
A fox is a wolf who sends flowers.
-- Ruth Weston

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFB5w0DgPqu395ykGsRAuFVAKCCmMOT2r6zR2IFhTff5Ae752YwwwCghyGe
60sGR4ZED1Y9QXbaHCwC4bg=
=fM1K
-----END PGP SIGNATURE-----
 
E

Ewald R. de Wit

Russell said:
It seems that the path was to a "fat" file partition and included a
directory name that was all uppercase. The directory was created, but
using lowercase. I'm not yet sure the version of python.

The workaround for now is to not use fat file partitions. But I was
wondering if anyone had a better option?

You can mount the FAT partition with the 'shortname' argument, i.e.
put something like

/dev/sda1 /usbkey auto umask=0,user,iocharset=iso8859-1,sync,kudzu,codepage=850,noauto,exec,users,shortname=winnt,check=s 0 0

in your /etc/fstab

Btw, this is a general Linux problem and is not really related to
Python (it also happens when working with shells or filemanagers).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top