Serhiy Storchaka added the comment:
Should I use os.path.realpath?
I don't see other way.
But there is other issue. Following code works now, but will fail with the
patch:
import os, tempfile
os.mkdir('parent')
os.chdir('parent')
t = tempfile.TemporaryDirectory(dir=.)
os.rename('../parent',
Antony Lee added the comment:
The change would be backwards-incompatible but also mimics the behavior of
NamedTemporaryFile (which also fails to delete the file if the containing
folder has been renamed -- this is easy to verify manually).
I guess the other option would be to use fd-based
Serhiy Storchaka added the comment:
Note that abspath() can return incorrect result in case of symbolic links to
directories and pardir components. I.e. abspath('symlink/..').
--
___
Python tracker rep...@bugs.python.org
Changes by Serhiy Storchaka storch...@gmail.com:
--
nosy: +pitrou
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20267
___
___
Python-bugs-list
Yury Selivanov added the comment:
Note that abspath() can return incorrect result in case of symbolic links to
directories and pardir components. I.e. abspath('symlink/..').
Good catch.. Should I use os.path.realpath?
--
___
Python tracker
Yury Selivanov added the comment:
A second version of the patch (tempfile_02), fixing more tempfile functions to
properly support relative paths. Please review.
--
nosy: +serhiy.storchaka
Added file: http://bugs.python.org/file36740/tempfile_02.patch
Antony Lee added the comment:
This looks reasonable. Note that the output of gettempdir is always passed as
first argument to os.path.join (possibly via _mkstemp_inner), so perhaps you
should rather define something like
def _absolute_child_of_parent_or_tmpdir(parent, *args):
Return the
Yury Selivanov added the comment:
Antony, I agree regarding the poor naming of '_sanitize_dir()' helper. As for
your other suggestion, I think such a refactoring will actually make code
harder to follow (+ it's more invasive). Generally, I'm in favour of
transforming parameters like 'dir'
Antony Lee added the comment:
I don't feel strongly about this, so either way is fine.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20267
___
Antony Lee added the comment:
Thanks for the fix. The same fix seems should also work for mkstemp and mktemp
-- is it really worth creating a new issue for them?
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20267
Yury Selivanov added the comment:
Thanks for the fix. The same fix seems should also work for mkstemp and
mktemp -- is it really worth creating a new issue for them?
No, no new issue is necessary. I think I'll update the patch and merge it in
3.5, as it's too late for 3.4
--
Changes by Yury Selivanov yseliva...@gmail.com:
--
nosy: +georg.brandl, ncoghlan
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20267
___
___
Yury Selivanov added the comment:
This looks like a bug to me (or we should complain if a relative 'dir' was
passed).
I'm attaching a patch that fixes this, although I'm not sure if the unittest I
wrote will work on windows.
Moreover, 'mkstemp' and 'mktemp' have the same bug (separate issue
Yury Selivanov added the comment:
The patch is ok for windows.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20267
___
___
Python-bugs-list
New submission from Antony Lee:
Essentially, the following fails:
t = tempfile.TemporaryDirectory(dir=.)
os.chdir(some_other_dir)
t.cleanup()
because t.name is a relative path. Resolving the dir argument when the
directory is created should(?) fix the issue.
--
components: Library
15 matches
Mail list logo