This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Patch for bug 1438185: os.renames deletes junction points
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: loewis Nosy List: brian.curtin, christian.heimes, collinwinter, georg.brandl, loewis, logistix, tim.golden
Priority: normal Keywords: patch

Created on 2006-02-26 23:21 by logistix, last changed 2022-04-11 14:56 by admin.

Files
File name Uploaded Description Edit
removedirs_fix.diff logistix, 2006-02-26 23:21 Patch for remove dirs review
Messages (6)
msg49605 - (view) Author: Grant Olson (logistix) Date: 2006-02-26 23:21
os.removedirs assumes that the os will throw an
exception if you try to rmdir an non-empty directory. 
Although this is a bit of a grey area, windows junction
points will be delete themselves even if the junction
point's destination has files.  os.renames() relied on
this behaviour and caused the failure.

This patch runs an explicit os.listdir() check when
calling os.removeddirs() to verify that a target
directory is really empty before deleting.

After this patch, manually running os.rmdir() against a
junction point will still just remove the junction
point like I would expect.
msg49606 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-08 18:25
Thanks for your patch!

I realize testing this kind of OS-specific behaviour is tricky, but could you work up some regression tests for this patch?

Also, you should send an email to python-dev (http://mail.python.org/mailman/listinfo/python-dev) about this; someone more knowledgeable about NTFS than I am should take a look at this patch.
msg49607 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-08 18:42
I don't think you could create NTFS junction points from Python without resorting to ctypes hackery.
Or is there some tool shipped with Windows to manipulate them?
msg59357 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-06 12:06
Martin, you are the Windows expert. Does it sound right to you?
msg59401 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-01-06 18:41
I'm skeptical. If you consider junction points similar to symlinks on
POSIX, then it would be semantically correct to leave the junction point
in place, independent of whether their target directory is empty or not
- on Unix, rmdir fails if the target is a symlink.

Given the documentation, I think the removedirs function does exactly do
what the documentation specifies as the algorithm (i.e. recursively
rmdir until an error occurs). The promise ("remove all empty
intermediate directories") is not held: on POSIX, it would stop at a
symlink even if that symlink was the only entry in the directory, and on
Windows, the junction point is removed even if the target directory is
not empty. I would rather fix this in the documentation than change
something in the implementation.

If the behavior is to be changed, the documentation needs to be updated.
The patch does introduce a significant behavior change: if the last
directory is not empty, it now silently returns; previously, it would
raise OSError.
msg115007 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-26 16:42
@Brian, Tim, any views on this?
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42950
2014-02-03 19:12:40BreamoreBoysetnosy: - BreamoreBoy
2012-05-09 08:20:32ezio.melottisetversions: + Python 3.3, - Python 3.1
2010-08-26 16:42:38BreamoreBoysetversions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6, Python 3.0
nosy: + tim.golden, brian.curtin, BreamoreBoy

messages: + msg115007

components: + Library (Lib), - None
2009-04-05 14:10:08ocean-citylinkissue1438185 superseder
2009-03-21 00:36:33ajaksu2setstage: test needed
type: behavior
versions: + Python 3.0, - Python 2.5
2008-01-06 18:41:45loewissetmessages: + msg59401
2008-01-06 12:06:41christian.heimessetassignee: loewis
versions: + Python 2.6, Python 2.5
messages: + msg59357
nosy: + loewis, christian.heimes
2006-02-26 23:21:13logistixcreate