[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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', '../parent2') t.cleanup() -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 semantics? (but it'd be preferable if the behavior was kept the same between TemporaryDirectory and NamedTemporaryFile). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
Changes by Serhiy Storchaka storch...@gmail.com: -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 absolute child of parent, or gettempdir() if parent is None, given by *args. if parent is None: parent = _sanitize_dir # inline the code here return _os.path.join(parent, *args) and use that function instead. This factorizes the code a little bit more and makes intent clearer (I don't think _sanitize_dir is a very clear name). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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' closer to the beginning of the method's code, so that it's immediately obvious what's going on, and is also easier to put debug code [like 'print(mkdtemp call for: , dir)']. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 -- versions: +Python 3.5 -Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
Changes by Yury Selivanov yseliva...@gmail.com: -- nosy: +georg.brandl, ncoghlan ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 for them?) -- keywords: +patch nosy: +yselivanov Added file: http://bugs.python.org/file33570/tempfile_01.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue20267] TemporaryDirectory does not resolve path when created using a relative path
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 (Lib) messages: 208141 nosy: Antony.Lee priority: normal severity: normal status: open title: TemporaryDirectory does not resolve path when created using a relative path versions: Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20267 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com