Bug #5650 'replace' does not follow symlinks.
Submitted: 19 Sep 2004 14:19 Modified: 16 Dec 2005 18:56
Reporter: Konstantin Osipov (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:all OS:UNIX
Assigned to: Georg Richter CPU Architecture:Any

[19 Sep 2004 14:19] Konstantin Osipov
Description:
'replace' command bundled along with MySQL does not follow symlinks:

kostja@dragonfly:~> echo "foo" > foo.txt
kostja@dragonfly:~> ln -s  foo.txt bar.txt
kostja@dragonfly:~> ls -al foo.txt bar.txt
lrwxrwxrwx  1 kostja users 7 2004-09-19 18:17 bar.txt -> foo.txt
-rw-r--r--  1 kostja users 4 2004-09-19 18:17 foo.txt
kostja@dragonfly:~> replace foo bar -- bar.txt
bar.txt converted
kostja@dragonfly:~> ls -al foo.txt bar.txt 
-rw-r--r--  1 kostja users 4 2004-09-19 18:12 bar.txt
-rw-r--r--  1 kostja users 4 2004-09-19 18:12 foo.txt
kostja@dragonfly:~> diff -u foo.txt bar.txt 
--- foo.txt     2004-09-19 18:12:28.877440832 +0400
+++ bar.txt     2004-09-19 18:12:56.696211736 +0400
@@ -1 +1 @@
-foo
+bar

How to repeat:
See above.

Suggested fix:
Check if the file is a symlink, and if it is, follow it.
[26 Jul 2005 5:43] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/27578
[29 Jul 2005 21:29] Patrick Galbraith
This patch looks good and works:

mysqldev@production:~/patg/mysql-5.0> echo "foo" > foo.txt
mysqldev@production:~/patg/mysql-5.0> ln -s foo.txt bar.txt
mysqldev@production:~/patg/mysql-5.0> ls -al foo.txt bar.txt 
lrwxrwxrwx  1 mysqldev users 7 Jul 29 23:25 bar.txt -> foo.txt
-rw-r--r--  1 mysqldev users 4 Jul 29 23:25 foo.txt
mysqldev@production:~/patg/mysql-5.0> ./extra/replace foo bar -- bar.txt 
bar.txt converted
mysqldev@production:~/patg/mysql-5.0> ls -l foo.txt bar.txt 
lrwxrwxrwx  1 mysqldev users 7 Jul 29 23:25 bar.txt -> foo.txt
-rw-r--r--  1 mysqldev users 4 Jul 29 23:26 foo.txt
mysqldev@production:~/patg/mysql-5.0> diff -u foo.txt bar.txt 
mysqldev@production:~/patg/mysql-5.0> vi bar.txt 
mysqldev@production:~/patg/mysql-5.0> cat bar.txt 
bar
mysqldev@production:~/patg/mysql-5.0> cat foo.txt 
bar
mysqldev@production:~/patg/mysql-5.0> 

(can't set my name in the bugs system as reviewer, Patrick Galbraith)
[16 Dec 2005 18:56] Jim Winstead
This was pushed some time ago. (Not sure what version, but I don't believe it really needs documentation.)