Crash when renaming a directory

Bug #430672 reported by Stuart Bishop
This bug report is a duplicate of:  Bug #403322: IndexError on moving added file. Edit Remove
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Confirmed
High
Unassigned
2.0
Confirmed
High
Unassigned

Bug Description

I renamed a directory and attempted to rename it back, triggering a crash.

$ bzr st
added:
  lib/lp/services/memcached/
  lib/lp/services/memcached/__init__.py
  lib/lp/services/memcached/interfaces.py
modified:
  lib/canonical/launchpad/scripts/runlaunchpad.py

$ bzr mv lib/lp/services/memcached lib/lp/services/memcache
bzr: ERROR: exceptions.IndexError: list index out of range

*** Bazaar has encountered an internal error. This probably indicates a
    bug in Bazaar. You can help us fix it by filing a bug report at
        https://bugs.launchpad.net/bzr/+filebug
    attaching the crash file
        /home/stub/.cache/crash/bzr-20090916114005-29872.crash
    and including a description of the problem.

    The crash file is plain text and you can inspect or edit it to remove
    private information.

$ bzr --version
Bazaar (bzr) 2.0rc2
  Python interpreter: /usr/bin/python 2.6.2
  Python standard library: /usr/lib/python2.6
  Platform: Linux-2.6.28-15-generic-x86_64-with-Ubuntu-9.04-jaunty
  bzrlib: /usr/lib/python2.6/dist-packages/bzrlib
  Bazaar configuration: /home/stub/.bazaar
  Bazaar log file: /home/stub/.bzr.log

Copyright 2005, 2006, 2007, 2008, 2009 Canonical Ltd.
http://bazaar-vcs.org/

bzr comes with ABSOLUTELY NO WARRANTY. bzr is free software, and
you may use, modify and redistribute it under the terms of the GNU
General Public License version 2 or later.

Revision history for this message
Stuart Bishop (stub) wrote :
Revision history for this message
Stuart Bishop (stub) wrote :

The crash is a potential data loss case - the renamed directory had been forgotten about.

$ bzr st
modified:
  lib/canonical/launchpad/scripts/runlaunchpad.py
unknown:
  lib/lp/services/memcache/

Revision history for this message
Matthew Fuller (fullermd) wrote :

This isn't actually 'renaming it back', it's another ordering issue. Naming to a lexically earlier name is what fails.

Example reproduction script (tested on bzr.dev and 1.18):

#!/bin/sh -x
bzr="/usr/local/bin/bzr --no-plugins --no-aliases"

${bzr} init A
(
 # Setup
 cd A ;
 ${bzr} mkdir a ;
 ${bzr} ci -m '1' ;

 # Add it
 ${bzr} mkdir a/b ;

 # Both work
 ${bzr} mv a/b a/c ;
 ${bzr} mv a/c a/d ;

 # This fails
 ${bzr} mv a/d a/a ;

 # Show that we lost it.
 ${bzr} stat
)

Changed in bzr:
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Matthew Fuller (fullermd) wrote :

Note that this can also be made to fail by "mv a/d c" in that penultimate step.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Yes we can !

class TestFullerMd(script.TestCaseWithTransportAndScript):

    def test_bug_430672(self):
        self.run_script("""
$ bzr init A
# Setup
$ cd A
$ bzr mkdir a
$ bzr ci -m '1'

# Add it
$ bzr mkdir a/b

# Both work
$ bzr mv a/b a/c
$ bzr mv a/c a/d

# This fails
$ bzr mv a/d a/a

# Show that we lost it.
$ bzr stat
""")

Note that we don't support the ';' and that empty lines are ignored, which may lead to
subtle bugs if we want to match empty output lines...so we have to treat empty lines
as expected output and use either '$ ' or '#' lines to replace them.

Also, using that kind of test brings the added benefit that they can be re-run (unlike the shell version
which miss a leading 'rm -fr A') and the 'A' directory isn't needed anymore.

And don't get me wrong, that's a very similar shell script that started me to write such shell scripts to reproduce
bugs (in particular the ability to reuse them with various versions of bzr) and gave me the clearer idea
that the above could be implemented (so take credit :).

Revision history for this message
John A Meinel (jameinel) wrote :

So it isn't entirely 'we lost it', the rename of the directory on disk succeeded but the rename in the dirstate failed.
If you 'mv a/a a/d' then it will show back up.
$ mv a/a/ a/d
$ bzr st
added:
  a/d/

If we didn't have implicit removals for 'missing' entries then 'bzr commit' would probably block on this.

Anyway, I agree it is a serious thing which should be fixed. It certainly is present in both bzr.dev and the 2.0 series.

Revision history for this message
John A Meinel (jameinel) wrote :

Note that it doesn't matter if there are other files /dirs in the directory, but it only triggers on a newly added directory. If you do:

bzr mkdir a/a
bzr mv a/a/ a/d
bzr commit -m 2
bzr mv a/d a/a

it works just fine.

So it is a bug in how we handle entries that are 'added' and renaming them to an earlier path.

Revision history for this message
Andrew Svetlov (andrew-svetlov) wrote : Re: [Bug 430672] Re: Crash when renaming a directory

I will try your way on workstartion Monday.
It's not big bug for me but if my report can help to make bazaar
better - why not.

On Fri, Sep 25, 2009 at 6:07 PM, John A Meinel <email address hidden> wrote:
> Note that it doesn't matter if there are other files /dirs in the
> directory, but it only triggers on a newly added directory. If you do:
>
> bzr mkdir a/a
> bzr mv a/a/ a/d
> bzr commit -m 2
> bzr mv a/d a/a
>
> it works just fine.
>
> So it is a bug in how we handle entries that are 'added' and renaming
> them to an earlier path.
>
> --
> Crash when renaming a directory
> https://bugs.launchpad.net/bugs/430672
> You received this bug notification because you are a direct subscriber
> of a duplicate bug.
>
> Status in Bazaar Version Control System: Confirmed
> Status in Bazaar 2.0 series: Confirmed
>
> Bug description:
> I renamed a directory and attempted to rename it back, triggering a crash.
>
> $ bzr st
> added:
>  lib/lp/services/memcached/
>  lib/lp/services/memcached/__init__.py
>  lib/lp/services/memcached/interfaces.py
> modified:
>  lib/canonical/launchpad/scripts/runlaunchpad.py
>
> $ bzr mv lib/lp/services/memcached lib/lp/services/memcache
> bzr: ERROR: exceptions.IndexError: list index out of range
>
> *** Bazaar has encountered an internal error.  This probably indicates a
>    bug in Bazaar.  You can help us fix it by filing a bug report at
>        https://bugs.launchpad.net/bzr/+filebug
>    attaching the crash file
>        /home/stub/.cache/crash/bzr-20090916114005-29872.crash
>    and including a description of the problem.
>
>    The crash file is plain text and you can inspect or edit it to remove
>    private information.
>
> $ bzr --version
> Bazaar (bzr) 2.0rc2
>  Python interpreter: /usr/bin/python 2.6.2
>  Python standard library: /usr/lib/python2.6
>  Platform: Linux-2.6.28-15-generic-x86_64-with-Ubuntu-9.04-jaunty
>  bzrlib: /usr/lib/python2.6/dist-packages/bzrlib
>  Bazaar configuration: /home/stub/.bazaar
>  Bazaar log file: /home/stub/.bzr.log
>
> Copyright 2005, 2006, 2007, 2008, 2009 Canonical Ltd.
> http://bazaar-vcs.org/
>
> bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and
> you may use, modify and redistribute it under the terms of the GNU
> General Public License version 2 or later.
>

Revision history for this message
Robert Collins (lifeless) wrote :

I get
Created a standalone tree (format: 2a)
added a
Committing to: /tmp/foo/A/
added a
Committed revision 1.
added a/b
a/b => a/c
a/c => a/d
a/d => a/a
added:
  a/a/

with bug bug 403322 branch. Is that what you're expecting fullermd ?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.