cp: odd behaviour; does not preserve symlink

Cristian Ionescu-Idbohrn cristian.ionescu-idbohrn at axis.com
Tue Jun 9 09:12:52 UTC 2009


this is what the gnu-tools do:

	$ mkdir abc
	$ cd abc

create a dangling symlink:

	$ ln -sf /tmp/foo
	$ ls -l
	lrwxrwxrwx 1 me users 8 Jun  9 10:35 foo -> /tmp/foo
	$ ls -l /tmp/foo
	ls: cannot access /tmp/foo: No such file or directory

	$ cp /etc/resolv.conf foo
	cp: not writing through dangling symlink `foo'
	$ touch foo
	$ ls -l /tmp/foo
	-rw-r--r-- 1 me users 0 Jun  9 10:44 /tmp/foo

/etc/resolv.conf is written through the symlink:

	$ cp /etc/resolv.conf foo
	$ ls -l /tmp/foo
	-rw-r--r-- 1 me users 125 Jun  9 10:46 /tmp/foo
	$ ls -l
	lrwxrwxrwx 1 me users 8 Jun  9 10:35 foo -> /tmp/foo

--- busybox ----------------------------------------

BusyBox v1.14.1 (2009-06-08 17:34:46 CEST) multi-call binary

	$ mkdir abc
	$ cd abc
	# ln -sf /tmp/foo
	# ls -l
	lrwxrwxrwx    1 root     root            8 Jun  9 08:50 foo -> /tmp/foo
	# ls -l /tmp/foo
	ls: /tmp/foo: No such file or directory

'cp' does not refuse to write through dangling symlink; overwrites the
symlink with a file:

	# cp /etc/resolv.conf foo
	# echo $?
	0
	# ls -l
	-rw-r--r--    1 root     root           71 Jun  9 08:54 foo


'cp' does not preserve the symlink eve if it's _not_ a dangling
symlink:

	# rm foo
	# touch /tmp/foo
	# ls -l /tmp/foo
	-rw-r--r--    1 root     root            0 Jun  9 08:58 /tmp/foo
	# ln -s /tmp/foo
	# ls -l
	lrwxrwxrwx    1 root     root            8 Jun  9 08:58 foo -> /tmp/foo
	# cp /etc/resolv.conf foo
	# echo $?
	0
	# ls -l
	-rw-r--r--    1 root     root           71 Jun  9 08:58 foo

Anyone else seeing this?


Cheers,

-- 
Cristian


More information about the busybox mailing list