Python creates "locked" temp dir

U

utabintarbo

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
 
A

Alex Willmer

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
 
U

utabintarbo

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.
 
A

astar

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
 
A

Alex Willmer

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.
 
U

utabintarbo

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. :)
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top