Bug #46039 Wrong handling of symlinks for SELECT ... INTO OUTFILE
Submitted: 8 Jul 2009 12:52 Modified: 7 Aug 2009 17:26
Reporter: Øystein Grøvlen Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.1-bzr, mysql-azalea OS:Any
Assigned to: Paul DuBois CPU Architecture:Any

[8 Jul 2009 12:52] Øystein Grøvlen
Description:
Given the following tree of directories:

elsewhere
  three
    good
    place
  two
one
  three
    bad
    place
  two -> ../elsewhere/two

In Unix/Linux this will happen:
$ ls one/two/../three
good  place
$ ls one/three
bad  place

However, when executing 'SELECT * from t1 INTO OUTFILE 'one/two/../three/t1.out'
t1.out is created in one/three.

See also discussion in BUG#39408.

How to repeat:
Execute the following shell commands in the default directory for SELECT ... INTO OUTFILE:

> mkdir elsewhere one
> mkdir elsewhere/three elsewhere/two
> mkdir elsewhere/three/good elsewhere/three/place
> mkdir one/three
> mkdir one/three/bad one/three/place
> cd one
> ln -s ../elsewhere/two

Then, execute the following SQL commands:
use test
create table t (i integer);
insert into t values (1), (2);
select * from t into outfile 'one/two/../three/t1.out';
[8 Jul 2009 13:43] Valeriy Kravchuk
On Mac OS X I get:

mysql> select 1 into outfile 'one/two/../three/2.txt';
ERROR 1 (HY000): Can't create/write to file '/Users/openxs/dbs/azalea/var/one/three/2.txt' (Errcode: 2)

in this case with both azalea and 5.1 from bzr.
[8 Jul 2009 13:50] Øystein Grøvlen
Do you have a '/Users/openxs/dbs/azalea/var/one/three' directory?

Anyways, it proves my points since in my opinion the output should not go into one/three, but into elsewhere/three.
[8 Jul 2009 14:14] Valeriy Kravchuk
Sorry, created directory in the wrong place... 

Verified on azalea and 5.1-bzr:

valeriy-kravchuks-macbook-pro:azalea openxs$ cd var
valeriy-kravchuks-macbook-pro:var openxs$ mkdir elsewhere one
valeriy-kravchuks-macbook-pro:var openxs$ mkdir elsewhere/three elsewhere/two
valeriy-kravchuks-macbook-pro:var openxs$ mkdir elsewhere/three/good elsewhere/three/place
valeriy-kravchuks-macbook-pro:var openxs$ mkdir one/three
valeriy-kravchuks-macbook-pro:var openxs$ mkdir one/three/bad one/three/place
valeriy-kravchuks-macbook-pro:var openxs$ cd one
valeriy-kravchuks-macbook-pro:one openxs$ ln -s ../elsewhere/two
valeriy-kravchuks-macbook-pro:one openxs$ cd ..
valeriy-kravchuks-macbook-pro:var openxs$ ls one/three/
bad	place
valeriy-kravchuks-macbook-pro:var openxs$ cd ..
valeriy-kravchuks-macbook-pro:azalea openxs$ bin/mysql -uroot testReading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.4.4-alpha-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select 1 into outfile 'one/two/../three/2.txt';
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye
valeriy-kravchuks-macbook-pro:azalea openxs$ ls var/one/three/
2.txt	bad	place
[7 Aug 2009 17:26] Paul DuBois
There has been no indication of what specifically should be documented.

If the idea is that server operation is dependent on operating system differences, that is generally true and not specific to this issue.

Closing without action.