Python creates "locked" temp dir

Discussion in 'Python' started by utabintarbo, Dec 7, 2010.

  1. utabintarbo

    utabintarbo Guest

    I am using tempfile.mkdtemp() to create a working directory on a
    remote *nix system through a Samba share. When I use this on a Windows
    box, it works, and I have full access to the created dir. When used on
    a Linux box (through the same Samba share), the created directory
    shows as "locked", and I am unable to access. Obviously, I need
    access. Any clues?

    Background/environment:
    Python 2.6.5 on Red Hat Enterprise Linux 5.3

    TIA
     
    utabintarbo, Dec 7, 2010
    #1
    1. Advertising

  2. utabintarbo

    Alex Willmer Guest

    On Dec 7, 9:03 pm, utabintarbo <> wrote:
    > I am using tempfile.mkdtemp() to create a working directory on a
    > remote *nix system through a Samba share. When I use this on a Windows
    > box, it works, and I have full access to the created dir. When used on
    > a Linux box (through the same Samba share), the created directory
    > shows as "locked", and I am unable to access. Obviously, I need
    > access. Any clues?


    You haven't provided enough details to go on.
    1. Please post the actual code, and the trace back (if any).
    2. When you say "I am unable to access". Do you mean another script/
    process is unable to access? If so, that is the point of mkdtemp() -
    to make a temporary directory that _only_ the creating process can
    access. If you want to share it then tempfile is not the right module
    for you.

    Regards, Alex
     
    Alex Willmer, Dec 8, 2010
    #2
    1. Advertising

  3. utabintarbo

    utabintarbo Guest

    Thanks for the reply.

    The relevant function (in a module) is as follows:

    def createWorkDir(pathdir="k:\\"):
    import tempfile, os

    if os.name == 'posix':
    pathdir = os.path.join(config.get('paths', 'MOUNTPOINT'),
    'subdir1')
    else:
    pathdir = os.path.normpath(r"\\windowsmount\subdir1")
    if not os.path.exists(os.path.join(pathdir,'tmp','program')):
    os.makedirs(os.path.join(pathdir,'tmp','program'))
    return os.path.normpath(tempfile.mkdtemp("", "",
    os.path.join(pathdir,'tmp','program')))

    The calling program calls the function as such:
    updateWorkDir = createWorkDir()

    I then attempt to copy a file (using shutil.move) into updateWorkDir
    and get an:

    IOError: [Errno 13] Permission denied: '/MOUNTPOINT/subdir1/tmp/
    program/y-Z0h3/file.ext'

    I also tried to create a similar dir under 'tmp' using os.mkdir and
    while the dir was not locked such that only the owner could do
    anything in it, it was not writeable by anything other than the owner,
    even when mode 0777 was specified explicitly.

    Thanks for the help.



    On Dec 8, 4:31 am, Alex Willmer <> wrote:
    > On Dec 7, 9:03 pm, utabintarbo <> wrote:
    >
    > > I am using tempfile.mkdtemp() to create a working directory on a
    > > remote *nix system through a Samba share. When I use this on a Windows
    > > box, it works, and I have full access to the created dir. When used on
    > > a Linux box (through the same Samba share), the created directory
    > > shows as "locked", and I am unable to access. Obviously, I need
    > > access. Any clues?

    >
    > You haven't provided enough details to go on.
    > 1. Please post the actual code, and the trace back (if any).
    > 2. When you say "I am unable to access". Do you mean another script/
    > process is unable to access? If so, that is the point of mkdtemp() -
    > to make a temporary directory that _only_ the creating process can
    > access. If you want to share it then tempfile is not the right module
    > for you.
    >
    > Regards, Alex
     
    utabintarbo, Dec 8, 2010
    #3
  4. utabintarbo

    astar Guest

    Hi,

    I recently got caught on tempfiles with respect to
    urllib.urlretrieve, which can create a tmpfile. Ah, but the file
    simply could not be found on the file system, even as root. But
    within the program that created the tmpfile, you could do useful
    things with the tmpfile. So the discussion in this thread is useful
    to me in understanding the rules. But having been given a clue by
    someone else, I never did find any python library documentation that
    was at all informative, even to the level of discourse in this
    thread.

    But here is a relevant question: I wonder if a child process is the
    *same* process as the parent for these purposes?

    Thanks.

    max
     
    astar, Dec 8, 2010
    #4
  5. utabintarbo

    Alex Willmer Guest

    On Dec 8, 6:26 pm, Christian Heimes <> wrote:
    > There isn't a way to limit access to a single process. mkdtemp creates
    > the directory with mode 0700 and thus limits it to the (effective) user
    > of the current process. Any process of the same user is able to access
    > the directory.
    >
    > Christian


    Quite right. My apologies for confusing temporary file creation, for
    which exclusive access is used and temporary directory creation for
    which there is no such mode.
     
    Alex Willmer, Dec 10, 2010
    #5
  6. utabintarbo

    utabintarbo Guest

    FWIW, I got around the issue with some samba mount options. They still
    show as 0700, but I, or anybody elsefor that matter, can still access
    them.

    Computers are weird. :p

    Thanks to all who responded. :)

    On Dec 10, 2:57 pm, Alex Willmer <> wrote:
    > On Dec 8, 6:26 pm, Christian Heimes <> wrote:
    >
    > > There isn't a way to limit access to a single process. mkdtemp creates
    > > the directory with mode 0700 and thus limits it to the (effective) user
    > > of the current process. Any process of the same user is able to access
    > > the directory.

    >
    > > Christian

    >
    > Quite right. My apologies for confusing temporary file creation, for
    > which exclusive access is used and temporary directory creation for
    > which there is no such mode.
     
    utabintarbo, Dec 16, 2010
    #6
    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. Replies:
    2
    Views:
    586
    Mark P
    May 9, 2005
  2. James_101
    Replies:
    10
    Views:
    288
    James_101
    Apr 10, 2005
  3. A. Farber
    Replies:
    3
    Views:
    286
    Ben Morrow
    Mar 3, 2004
  4. MoshiachNow
    Replies:
    0
    Views:
    137
    MoshiachNow
    Dec 4, 2006
  5. PerlFAQ Server
    Replies:
    0
    Views:
    278
    PerlFAQ Server
    Apr 26, 2011
Loading...

Share This Page