directory bug on linux; workaround?

Discussion in 'Python' started by Russell E. Owen, Jan 13, 2005.

  1. 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
    Russell E. Owen, Jan 13, 2005
    #1
    1. Advertising

  2. Russell E. Owen

    Jeff Epler Guest

    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-----
    Jeff Epler, Jan 13, 2005
    #2
    1. Advertising

  3. Russell E. Owen

    John Lenton Guest

    On Thu, Jan 13, 2005 at 12:07:04PM -0800, Russell E. Owen wrote:
    > 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 () -- 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-----
    John Lenton, Jan 14, 2005
    #3
  4. Russell E. Owen wrote:
    > 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).

    --
    -- Ewald
    Ewald R. de Wit, Jan 17, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Miller

    Workaround for Bug: Q316495

    Mark Miller, Jul 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    420
    Mark Miller
    Jul 30, 2003
  2. Dave
    Replies:
    2
    Views:
    619
  3. Simmons, Stephen

    Suggestions for workaround in CSV bug

    Simmons, Stephen, Jan 23, 2006, in forum: Python
    Replies:
    1
    Views:
    820
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Jan 24, 2006
  4. Andy Fish

    workaround for FCN/directory delete bug

    Andy Fish, Aug 30, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    2,589
    Patrice
    Sep 11, 2007
  5. Martin DeMello
    Replies:
    2
    Views:
    152
    James Edward Gray II
    May 27, 2010
Loading...

Share This Page