GNU bug report logs - #6138
mv while maintaining relative symbolic links

Previous Next

Package: coreutils;

Reported by: Peng Yu <pengyu.ut <at> gmail.com>

Date: Fri, 7 May 2010 21:02:02 UTC

Severity: wishlist

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 6138 in the body.
You can then email your comments to 6138 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Fri, 07 May 2010 21:02:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Peng Yu <pengyu.ut <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 07 May 2010 21:02:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Peng Yu <pengyu.ut <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: mv while maintaining relative symbolic links
Date: Fri, 7 May 2010 15:33:11 -0500
I'm wondering if there is any tool that can do almost exact the same
thing as mv, but it can maintain symbolic links.

mv doens't maintain relative symbolic links. For example, I have file
/tmp/A/file1.txt and a symbolic link /tmp/file1.txt that point to
A/file.txt (by the relative path). If I mv /tmp/A to /tmp/B, the link
/tmp/file1.txt will be broken.

Another example: I have file /tmp/file1.txt and symbolic link
/tmp/A/file1.txt that points to ../file1.txt (by relative path). If I
move /tmp/A to /tmp/B/A, the symbolic /tmp/A/file1.txt will be broken.

Could you please let me know if there is a tool that can maintain the
symbolic links?

-- 
Regards,
Peng





Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Fri, 07 May 2010 22:04:01 GMT) Full text and rfc822 format available.

Message #8 received at 6138 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Peng Yu <pengyu.ut <at> gmail.com>
Cc: 6138 <at> debbugs.gnu.org
Subject: Re: bug#6138: mv while maintaining relative symbolic links
Date: Fri, 7 May 2010 16:03:25 -0600
severity 6138 wishlist
thanks

Peng Yu wrote:
> I'm wondering if there is any tool that can do almost exact the same
> thing as mv, but it can maintain symbolic links.
> 
> mv doens't maintain relative symbolic links. For example, I have file
> /tmp/A/file1.txt and a symbolic link /tmp/file1.txt that point to
> A/file.txt (by the relative path). If I mv /tmp/A to /tmp/B, the link
> /tmp/file1.txt will be broken.

For clarification you said:

  file     /tmp/A/file1.txt
  symlink  /tmp/file1.txt -> A/file.txt

But I think you meant to say:

  file     /tmp/A/file1.txt
  symlink  /tmp/file1.txt -> A/file1.txt

 After moving /tmp/A to /tmp/B

  file     /tmp/B/file1.txt
  symlink  /tmp/file1.txt -> B/file1.txt (proposed)

This is not possible.  Symbolic links are simply files in the
filesystem.  Special files, of course, but otherwise just files.
The two files /tmp/file1.txt and /tmp/A/file1.txt are unrelated to
each other in any way other than by content of /tmp/file1.txt.

To do what you are asking would require that every move operation
consult the contents of every symlink on the filesystem and adjust
those other symlinks.  Worse this is not only on the current
filesystem but also on other filesystems.  Because symlinks are not
real file links but simply a run time name conversion a symlink may
exist on other filesystems.  Those other filesystems may be over NFS
or other network filesystem.  Other filesystems may not even be
powered up and online at the time!  Also other symlinks may point to
this file but only incidentally, in which case they would get changed
even though they are unrelated.

> Another example: I have file /tmp/file1.txt and symbolic link
> /tmp/A/file1.txt that points to ../file1.txt (by relative path). If I
> move /tmp/A to /tmp/B/A, the symbolic /tmp/A/file1.txt will be broken.

  file     /tmp/file1.txt
  symlink  /tmp/A/file1.txt -> ../file1.txt

 After moving to a different level of hiearchy:

  file     /tmp/file1.txt
  symlink  /tmp/A/B/file1.txt -> ../file1.txt

A tool is possible that reads the value of the link (readlink) and
then removes the old symlink and creates a new (unrelated) symlink in
the target location but with a new path calculated to the old
location.  That would not be a move operation.  That would be
something different that removed the old and created a new.

But if that is what you wanted then you probably wanted to convert the
symlink to an absolute path first and then you could move it.  Off the
top of my head here is a simple script that I haven't tested and may
or may not behave reasonably.  In particular error handling is poor.

  #!/bin/sh -e
  src=$1
  dst=$2
  path=$(readlink -f "$src")
  rm -f "$src"
  ln -s "$path" "$src"
  mv "$src" "$dst"

I am sure that there are related tools here but nothing immediately
comes to my mind.  I have always simply scripted the operation that I
required at the moment.

Bob




Severity set to 'wishlist' from 'normal' Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Fri, 07 May 2010 22:04:02 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Sat, 08 May 2010 14:03:02 GMT) Full text and rfc822 format available.

Message #13 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Peng Yu <pengyu.ut <at> gmail.com>
To: Bob Proulx <bob <at> proulx.com>
Cc: 6138 <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
Subject: Re: bug#6138: mv while maintaining relative symbolic links
Date: Sat, 8 May 2010 08:59:31 -0500
On Fri, May 7, 2010 at 5:03 PM, Bob Proulx <bob <at> proulx.com> wrote:
> severity 6138 wishlist
> thanks
>
> Peng Yu wrote:
>> I'm wondering if there is any tool that can do almost exact the same
>> thing as mv, but it can maintain symbolic links.
>>
>> mv doens't maintain relative symbolic links. For example, I have file
>> /tmp/A/file1.txt and a symbolic link /tmp/file1.txt that point to
>> A/file.txt (by the relative path). If I mv /tmp/A to /tmp/B, the link
>> /tmp/file1.txt will be broken.
>
> For clarification you said:
>
>  file     /tmp/A/file1.txt
>  symlink  /tmp/file1.txt -> A/file.txt
>
> But I think you meant to say:

You are right. It is a typo.

>  file     /tmp/A/file1.txt
>  symlink  /tmp/file1.txt -> A/file1.txt
>
>  After moving /tmp/A to /tmp/B
>
>  file     /tmp/B/file1.txt
>  symlink  /tmp/file1.txt -> B/file1.txt (proposed)
>
> This is not possible.  Symbolic links are simply files in the
> filesystem.  Special files, of course, but otherwise just files.
> The two files /tmp/file1.txt and /tmp/A/file1.txt are unrelated to
> each other in any way other than by content of /tmp/file1.txt.
>
> To do what you are asking would require that every move operation
> consult the contents of every symlink on the filesystem and adjust
> those other symlinks.  Worse this is not only on the current
> filesystem but also on other filesystems.  Because symlinks are not
> real file links but simply a run time name conversion a symlink may
> exist on other filesystems.  Those other filesystems may be over NFS
> or other network filesystem.  Other filesystems may not even be
> powered up and online at the time!  Also other symlinks may point to
> this file but only incidentally, in which case they would get changed
> even though they are unrelated.

I agree with you that this is may not be possible for whole file
system. But under the assumptions that symbolic links and their
targets are always in a number of directories (user configurable) on
the same file system, then it is doable. This is practically what I
need.

>> Another example: I have file /tmp/file1.txt and symbolic link
>> /tmp/A/file1.txt that points to ../file1.txt (by relative path). If I
>> move /tmp/A to /tmp/B/A, the symbolic /tmp/A/file1.txt will be broken.
>
>  file     /tmp/file1.txt
>  symlink  /tmp/A/file1.txt -> ../file1.txt
>
>  After moving to a different level of hiearchy:
>
>  file     /tmp/file1.txt
>  symlink  /tmp/A/B/file1.txt -> ../file1.txt
>
> A tool is possible that reads the value of the link (readlink) and
> then removes the old symlink and creates a new (unrelated) symlink in
> the target location but with a new path calculated to the old
> location.  That would not be a move operation.  That would be
> something different that removed the old and created a new.
>
> But if that is what you wanted then you probably wanted to convert the
> symlink to an absolute path first and then you could move it.  Off the
> top of my head here is a simple script that I haven't tested and may
> or may not behave reasonably.  In particular error handling is poor.

Error handling is important as, otherwise, it might mess up with the
files and could be a disaster.

>  #!/bin/sh -e
>  src=$1
>  dst=$2
>  path=$(readlink -f "$src")
>  rm -f "$src"
>  ln -s "$path" "$src"
>  mv "$src" "$dst"
>
> I am sure that there are related tools here but nothing immediately
> comes to my mind.  I have always simply scripted the operation that I
> required at the moment.

If anybody else knows some related tools for refined requirement (see
above clarification), please let me know.

-- 
Regards,
Peng





Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Sat, 08 May 2010 14:03:03 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Mon, 10 May 2010 09:39:01 GMT) Full text and rfc822 format available.

Message #19 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Voelker, Bernhard" <bernhard.voelker <at> siemens-enterprise.com>
To: Peng Yu <pengyu.ut <at> gmail.com>,
    Bob Proulx <bob <at> proulx.com>
Cc: "6138 <at> debbugs.gnu.org" <6138 <at> debbugs.gnu.org>,
	"bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>
Subject: RE: bug#6138: mv while maintaining relative symbolic links
Date: Mon, 10 May 2010 11:37:07 +0200
Peng Yu wrote:

> I agree with you that this is may not be possible for whole file
> system. But under the assumptions that symbolic links and their
> targets are always in a number of directories (user configurable) on
> the same file system, then it is doable. This is practically what I
> need.

you need a reference to the actual inode, don't you?
So what a about using hardlinks?

Have a nice day,
Berny





Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Mon, 10 May 2010 09:39:02 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Mon, 10 May 2010 13:18:02 GMT) Full text and rfc822 format available.

Message #25 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Peng Yu <pengyu.ut <at> gmail.com>
To: "Voelker, Bernhard" <bernhard.voelker <at> siemens-enterprise.com>
Cc: "6138 <at> debbugs.gnu.org" <6138 <at> debbugs.gnu.org>,
	"bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>,
	Bob Proulx <bob <at> proulx.com>
Subject: Re: bug#6138: mv while maintaining relative symbolic links
Date: Mon, 10 May 2010 08:13:30 -0500
On Mon, May 10, 2010 at 4:37 AM, Voelker, Bernhard
<bernhard.voelker <at> siemens-enterprise.com> wrote:
> Peng Yu wrote:
>
>> I agree with you that this is may not be possible for whole file
>> system. But under the assumptions that symbolic links and their
>> targets are always in a number of directories (user configurable) on
>> the same file system, then it is doable. This is practically what I
>> need.
>
> you need a reference to the actual inode, don't you?
> So what a about using hardlinks?

Harlinks do not work across filesystems. I think that it is better
stick with symbolic links.

-- 
Regards,
Peng





Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Mon, 10 May 2010 13:18:02 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Mon, 10 May 2010 14:12:02 GMT) Full text and rfc822 format available.

Message #31 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Voelker, Bernhard" <bernhard.voelker <at> siemens-enterprise.com>
To: Peng Yu <pengyu.ut <at> gmail.com>
Cc: "6138 <at> debbugs.gnu.org" <6138 <at> debbugs.gnu.org>,
	"bug-coreutils <at> gnu.org" <bug-coreutils <at> gnu.org>,
	Bob Proulx <bob <at> proulx.com>
Subject: RE: bug#6138: mv while maintaining relative symbolic links
Date: Mon, 10 May 2010 15:45:35 +0200
Peng Yu wrote:
> On Mon, May 10, 2010 at 4:37 AM, Voelker, Bernhard wrote:
>> you need a reference to the actual inode, don't you?
>> So what a about using hardlinks?
>
> Harlinks do not work across filesystems. I think that it is better
> stick with symbolic links.

you are right, of course.
You'll have to decide what you need:
either you want to have a stable filename (then you use symlinks),
or you want a stable inode reference (then you use hardlinks,
unless you're on a different filesystem) ... or like Bob wrote:
write your own shell script for that situation.

Have a nice day,
Berny





Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Mon, 10 May 2010 14:12:02 GMT) Full text and rfc822 format available.

Information forwarded to owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org:
bug#6138; Package coreutils. (Mon, 07 Jun 2010 23:23:01 GMT) Full text and rfc822 format available.

Message #37 received at 6138 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Peng Yu <pengyu.ut <at> gmail.com>
Cc: 6138 <at> debbugs.gnu.org
Subject: Re: bug#6138: mv while maintaining relative symbolic links
Date: Mon, 7 Jun 2010 17:22:32 -0600
Peng Yu wrote:
> Bob Proulx wrote:
> > To do what you are asking would require that every move operation
> > consult the contents of every symlink on the filesystem and adjust
> > those other symlinks.  Worse this is not only on the current
> > filesystem but also on other filesystems.  ...
> 
> I agree with you that this is may not be possible for whole file
> system. But under the assumptions that symbolic links and their
> targets are always in a number of directories (user configurable) on
> the same file system, then it is doable. This is practically what I
> need.

Is there any new information on this issue?  Have you made any
progress on your own solution?

> If anybody else knows some related tools for refined requirement (see
> above clarification), please let me know.

I am not aware of anything that already exists to do what you are asking.

Bob




Reply sent to Bob Proulx <bob <at> proulx.com>:
You have taken responsibility. (Mon, 07 Jun 2010 23:45:02 GMT) Full text and rfc822 format available.

Notification sent to Peng Yu <pengyu.ut <at> gmail.com>:
bug acknowledged by developer. (Mon, 07 Jun 2010 23:45:02 GMT) Full text and rfc822 format available.

Message #42 received at 6138-done <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Peng Yu <pengyu.ut <at> gmail.com>
Cc: 6138-done <at> debbugs.gnu.org
Subject: Re: bug#6138: mv while maintaining relative symbolic links
Date: Mon, 7 Jun 2010 17:44:37 -0600
Peng Yu wrote:
> Bob Proulx wrote:
> > Is there any new information on this issue?  Have you made any
> > progress on your own solution?
> 
> No. I don't find any tool either.

I think it is unlikely (I haven't read any enthusiasm for it from the
group) for adding this type of functionality to mv.  I think it might
be possible to implement but if so then it should be in a different
standalone program.  It wouldn't be trivial.  It would be complicated
enough that if written it might only work acceptably for three people
in the universe.  So I don't know.

I am therefore inclined to mark this bug ticket closed in the bug
tracking system.  That doesn't mean an end to discussion on the
mailing list.  Please feel free to follow up.  The bug tracker will
keep track of the discussion and the issue can be awakened if needed.

Bob




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 06 Jul 2010 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 14 years and 354 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.