bug-bash
[Top][All Lists]
Advanced

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

Re: mv to a non-existent path now renames instead of failing


From: Eric Blake
Subject: Re: mv to a non-existent path now renames instead of failing
Date: Thu, 17 Mar 2016 08:49:17 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0

On 03/17/2016 05:37 AM, adam@korath.teln.shikadi.net wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu' 
> -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
> -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  -D_FORTIFY_SOURCE=2 
> -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong 
> -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' 
> -DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash.bashrc' 
> -DSYS_BASH_LOGOUT='/etc/bash.bash_logout'
> uname output: Linux korath.teln.shikadi.net 4.5.0-1-drm-intel-nightly #1 SMP 
> PREEMPT Sun Mar 13 10:42:04 AEST 2016 x86_64 GNU/Linux
> Machine Type: x86_64-unknown-linux-gnu
> 
> Bash Version: 4.3
> Patch Level: 42
> Release Status: release
> 
> Description:
>       Moving a directory to a non-existent path will rename the directory 
> instead
>       of reporting that the destination directory does not exist.

This has nothing to do with bash, and would belong better on the
bug-coreutils mailing list, if it were a bug.  However,...

> 
> Repeat-By:
>       rmdir two 2> /dev/null
>       mkdir one
>       mv one two/

POSIX requires this to succeed, and renames 'one/' to 'two/'.

>       
>       This should (and did in earlier versions) return an error, since the 
> "two"
>       directory does not exist, so the "one" folder cannot be moved inside of 
> it.

You are NOT moving 'one' to 'two/one', but renaming 'one' to 'two'.
That is what POSIX requires, so no error is needed.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/mv.html

"This first synopsis form is assumed when the final operand does not
name an existing directory and is not a symbolic link referring to an
existing directory."

That sums up your situation ('two/' does not exist, so you are doing 'mv
source target_file', not 'mv source target_dir'), at which point steps 1
and 2 do not apply, and step 3 states you are doing
rename("one","two/"), which succeeds because "one" is a directory (if
"one" were not a directory, it would fail).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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