TreeTransform assumes whole tree is on one filesystem; gives "invalid cross-device link"

Bug #411068 reported by Denis Golovan
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Bazaar
Confirmed
Low
Unassigned
Nominated for 1.18 by Denis Golovan
Breezy
Triaged
Low
Unassigned

Bug Description

Following error occurs when .bzr directory resides on different partition compared to versioned files.

den-notebook usr # LANG=C bzr revert /usr/src/linux-2.6.30-git/.config
+N usr/src/linux-2.6.30-git/.config
bzr: ERROR: [Errno 18] Invalid cross-device link

In my case I store all my Linux system settings in bazaar. So I have .bzr directory at the root of root file system and /usr/src/linux-2.6.30-git directory on another partition. .bzr directory at root is just a symlink pointing to /var/... directory. /var directory partition is other than /usr partition.

Further strace usage showed:
) = 126###########- ] Revert phase:Apply phase 2/3
gettimeofday({1249831587, 880447}, NULL) = 0
) = 126###########\ ] Revert phase:Apply phase:adding file 0/1
rename("/.bzr/checkout/limbo/new-1", "/usr/src/linux-2.6.30-git/.config") = -1 EXDEV (Invalid cross-device link)
lstat64("/.bzr/checkout/limbo/new-1", {st_mode=S_IFREG|0644, st_size=59952, ...}) = 0
unlink("/.bzr/checkout/limbo/new-1") = 0
lstat64("/.bzr/checkout/limbo", {st_mode=S_IFDIR|S_ISGID|0755, st_size=48, ...}) = 0
rmdir("/.bzr/checkout/limbo") = 0

I think it means that bzr tries to simply rename file instead of moving across different partitions.
Please fix.

P.S. Tested on bzr 1.17

Revision history for this message
Martin Pool (mbp) wrote :

I have a feeling this is a dupe but I can't find it.

As you identified the problem is that bzr assumes it can directly move files from the limbo directory in .bzr into the tree.

As a cheap but slow workaround we could just change the rename to a copy. It would probably be a cheap fix if you'd like to try.

Doing so would somewhat defeat the purpose of writing things into limbo first, and perhaps it would be better to identify a directory next to the source files where they should be written. Doing that would need to take into account that in extreme cases people's actual working tree may span filesystems.

summary: - "Invalid cross-device link" error on revert
+ TreeTransform assumes whole tree is on one filesystem; gives "invalid
+ cross-device link"
Changed in bzr:
status: New → Confirmed
importance: Undecided → Low
Revision history for this message
Denis Golovan (denisgolovan) wrote :

>As a cheap but slow workaround we could just change the rename to a copy. It would probably be a cheap fix if you'd like to try.

Yes. I'd like to have some patch. Is it possible?
I'm now in the middle of update operation which gives just the same error.

About the rest - yes, you caught the idea right. Moving .bzr to /usr partition solves the problem in my example.

Revision history for this message
Martin Pool (mbp) wrote : Re: [Bug 411068] Re: TreeTransform assumes whole tree is on one filesystem; gives "invalid cross-device link"

2009/8/10 Denis Golovan <email address hidden>:
>>As a cheap but slow workaround we could just change the rename to a
> copy. It would probably be a cheap fix if you'd like to try.
>
> Yes. I'd like to have some patch. Is it possible?

you should probably look at adding (or calling) code in osutils to
move the file and do a copy if necessary.
--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
Denis Golovan (denisgolovan) wrote :
Revision history for this message
Martin Pool (mbp) wrote :

2009/9/24 Denis Golovan <email address hidden>:
>
> ** Attachment added: "Patch for 1.17/1.18"
>   http://launchpadlibrarian.net/32330771/cross-partition.patch

Hi, thanks for the patch. Please push up a branch and propose a merge.

--
Martin <http://launchpad.net/~mbp/>

Revision history for this message
John A Meinel (jameinel) wrote : Re: [Bug 411068] Re: TreeTransform assumes whole tree is on one filesystem; gives "invalid cross-device link"

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
> 2009/9/24 Denis Golovan <email address hidden>:
>> ** Attachment added: "Patch for 1.17/1.18"
>> http://launchpadlibrarian.net/32330771/cross-partition.patch
>
> Hi, thanks for the patch. Please push up a branch and propose a merge.
>
>

I'll just do a quick comment.

Using 'shutil.move' seems nice, except instead of failing if the target
is a directory, it will move into a subdirectory.

This is the shutil code:
    real_dst = dst
    if os.path.isdir(dst):
        real_dst = os.path.join(dst, _basename(src))
        if os.path.exists(real_dst):
            raise Error, "Destination path '%s' already exists" % real_dst

^- we don't want this

v- we do what this

    try:
        os.rename(src, real_dst)
    except OSError:
        if os.path.isdir(src):
            if destinsrc(src, dst):
                raise Error, "Cannot move a directory '%s' into itself
'%s'." % (src, dst)
            copytree(src, real_dst, symlinks=True)
            rmtree(src)
        else:
            copy2(src, real_dst)
            os.unlink(src)

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkq7nfAACgkQJdeBCYSNAAPb7ACeNvXpaqyJVB0K82pGjW2E34ff
SOEAoI8YFmkTReSWUbpr4hWXi+/02970
=khPk
-----END PGP SIGNATURE-----

Revision history for this message
James Westby (james-w) wrote : Re: [Bug 411068] Re: TreeTransform assumes whole tree is on one filesystem; gives "invalid cross-device link"

On Thu Sep 24 16:27:28 UTC 2009 John A Meinel wrote:
> Using 'shutil.move' seems nice, except instead of failing if the target
> is a directory, it will move into a subdirectory.

I also think this behaviour may even vary by python version.

Thanks,

James

Revision history for this message
Rahul Nabar (rpnabar) wrote :

For now, would it be more user-friendly to throw the error right at the start when a "bzr commit" or a "bzr add" is made on a file that resides on another filesystem?

The behavior currently is that the error is only thrown during a "bzr revert".

Revision history for this message
Martin Pool (mbp) wrote :

I would rather just fix it than fail early.

Revision history for this message
John A Meinel (jameinel) wrote : Re: [Bug 411068] Re: TreeTransform assumes whole tree is on one filesystem; gives "invalid cross-device link"

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8/21/2010 9:02 AM, Rahul Nabar wrote:
> For now, would it be more user-friendly to throw the error right at the
> start when a "bzr commit" or a "bzr add" is made on a file that resides
> on another filesystem?
>
> The behavior currently is that the error is only thrown during a "bzr
> revert".
>

I'll note that it will also fail during 'bzr up' or 'bzr pull' or 'bzr
merge', basically any command that generates new file content. 'bzr
commit' works because it only reads from the disk.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxylPwACgkQJdeBCYSNAAOjggCeMhQLUroiTZe8FkWACqxW+zOy
NDUAnR0wukjhTZ0pmR7TQFVw+ugyRN+D
=njno
-----END PGP SIGNATURE-----

Jelmer Vernooij (jelmer)
tags: added: check-for-breezy
Jelmer Vernooij (jelmer)
Changed in brz:
status: New → Triaged
importance: Undecided → Low
tags: added: treetransform
removed: check-for-breezy
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.