[PATCH 4 of 5] workingctx: unlink files while wlock held

Adrian Buehlmann adrian at cadifra.com
Mon May 23 14:40:05 CDT 2011


On 2011-05-23 16:56, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Adrian Buehlmann <adrian at cadifra.com>
> # Date 1306157454 -7200
> # Node ID d9fb24393d26600a9146192fdd231160997fbc4a
> # Parent  ff576ed31f699e1db227c7cd23f0f32659da9bae
> workingctx: unlink files while wlock held
> 
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -841,17 +841,17 @@
>              yield changectx(self._repo, a)
>  
>      def remove(self, list, unlink=False, unlinkadded=True):
> -        if unlink:
> -            for f in list:
> -                if not unlinkadded and self._repo.dirstate[f] == 'a':
> -                    continue
> -                try:
> -                    util.unlinkpath(self._repo.wjoin(f))
> -                except OSError, inst:
> -                    if inst.errno != errno.ENOENT:
> -                        raise
>          wlock = self._repo.wlock()
>          try:
> +            if unlink:
> +                for f in list:
> +                    if not unlinkadded and self._repo.dirstate[f] == 'a':
> +                        continue
> +                    try:
> +                        util.unlinkpath(self._repo.wjoin(f))
> +                    except OSError, inst:
> +                        if inst.errno != errno.ENOENT:
> +                            raise
>              for f in list:
>                  if self._repo.dirstate[f] == 'a':
>                      self._repo.dirstate.forget(f)

I believe we shouldn't modify the working directory without holding the
lock.

So I moved the unlinking into the wlock block.

Is this bad?

The code as it was before unlinked the files before acquiring the wlock.

After the patch, it acquires the lock first, and then unlinks the files.

(same pattern as in applyupdates).


More information about the Mercurial-devel mailing list