[PATCH 0 of 1] avoid deleting symbolically linked directories on windows

Matt Mackall mpm at selenic.com
Mon May 11 12:58:27 CDT 2009


On Mon, May 11, 2009 at 07:02:11PM +0200, Henrik Stuart wrote:
> Matt Mackall skrev:
> > On Mon, May 11, 2009 at 04:01:41PM +0200, Henrik Stuart wrote:
> >> On Windows, it is possible to make symbolic linked directories or 
> >> junction points (hardlinks) - together reparse points - to an entire 
> >> hg repository including a working directory, e.g.:
> >>
> >>   foo/
> >>       .hg
> >>       [files]
> >>
> >>   bar/ [symlinkd:foo]
> >>
> >> If you do a hg up null or hg up {revision with removed files} then
> >> util.unlink will try to run os.removedirs(path), which will 
> >> recursively remove directories until it fails. We expect that bar/
> >> should not be deleted, but os.rmdir on a symlink or junction point
> >> succeeds without further issues. A following branch state write will
> >> then recreate the directory, as a directory rather than as a reparse
> >> point, and users will be very confused.
> > 
> > Confused. bar/ points to the root of a repository? Why do we ever
> > unlink the root of a repository? That seems like a bug?
> 
> util.unlink(f) basically does:
>   os.unlink(f)
>   os.removedirs(os.path.dirname(f))
> 
> removedirs recursively removes empty directories using os.rmdir until
> os.rmdir fails (e.g. due to non-empty directories).
> 
> Let's say that we are deleting "bar/baz/quux.py" and that's the only
> file in "bar/baz" then it will basically boil down to the following
> number of calls (where the indentation illustrates the actual calls
> being made in that function, in pseudo-code):
> 
> util.unlink('bar/baz/quux.py')
>   os.unlink('bar/baz/quux.py')
>   os.removedirs('bar/baz')
>     os.rmdir('bar/baz') succeeds
>     os.rmdir('bar') succeeds as it is symlink
> 
> Had we made this call in foo instead then the last call would have been
> os.rmdir('foo') which would fail since e.g. .hg is always in 'foo'
> (reparse points are handled a bit... strangely... on Windows).

Ok, makes perfect sense.

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial-devel mailing list