bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature request, mv


From: Eric Blake
Subject: Re: Feature request, mv
Date: Wed, 10 May 2006 03:54:50 +0000

> In some cases, it is desirable to rename something on top of a
> symbolic link to a directory:
> 
> $ mkdir www1.0
> $ (cd www1.0 && tar -zxf /tmp/www.new.tgz)
> $ ln -s www1.0 www
> 
> (some time later)
> 
> $ mkdir www1.1
> $ (cd www1.1 && tar -zxf /tmp/www.updated.tgz)
> $ ln -s www1.0 tmp
> $ mv tmp www
> 
> The desired behavour is the instantous replacement of the www dir with
> no time that the site is down (mv is atomic, ln -fs is not).

Sorry, but mv(1) is not necessarily atomic (use strace to find out what
is going on under the hood).  rename(2) is atomic when successful, but
in the case of replacing an existing symlink with a directory, mv must
first call unlink(2), so in that case, there is going to be a window (however
small) where there is neither the symlink nor a directory.  Furthermore,
rename(2) usually fails when crossing device boundaries (systems are
allowed to let that succeed, but I don't know of any popular OS that
supports that usage); in which case mv(1) will still succeed, but by
doing a full-blown copy, which is certainly not atomic (although the
old version of the file exists untouched up until the new version
has been completely copied).

> 
> However, this sequence of operations moves tmp inside www.
> Perhaps an option that is "just execute the system call!" would help, along
> the lines of "ln -d" and "rm -d", for which I take -d as meaning the same 
> thing.
> For sanity reasons, you might want to ensure that there is only *one* source.

That said, you should look at the -T option in coreutils' rm.  I think it
does exactly what you want (although it is not portable to other
rm implementations):

$ mkdir www1 www2
$ ln -s www1 www
$ ln -s tmp www2
$ mv -f -T -v tmp www
`tmp' -> `www'
$ readlink www
www2

-- 
Eric Blake




reply via email to

[Prev in Thread] Current Thread [Next in Thread]