Bug #61002 [Com]: Windows symlink resolution differs between mkdir and file_put_contents

From: Date: Mon, 13 Feb 2012 20:26:43 +0000
Subject: Bug #61002 [Com]: Windows symlink resolution differs between mkdir and file_put_contents
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-167485@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61002&edit=1

 ID:                 61002
 Comment by:         mattficken@php.net
 Reported by:        feedbee at gmail dot com
 Summary:            Windows symlink resolution differs between mkdir and
                     file_put_contents
 Status:             Open
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Windows 7 SP1
 PHP Version:        5.3.10
 Block user comment: N
 Private report:     N

 New Comment:

I don't see any problem here. I get the output you expected.

I don't get a warning for file_put_contents(). On the 2nd+ runs I get a warning about directory
existing.

I run it using 5.3.10-nts-vc9 and I get:

C:\61002>c:\php-5.3.10-nts-Win32-VC9-x86\php repro.php
Is Dir exists? No
Create Dir
Is Dir exists NOW? Yes
OK
C:\61002>c:\php-5.3.10-nts-Win32-VC9-x86\php repro.php
Is Dir exists? Yes
Create Dir

Warning: mkdir(): File exists in C:\61002\repro.php on line 7
Is Dir exists NOW? Yes
OK
C:\61002>

'file' gets created in directory 'g:\new' (I modified your script (only) to use
g:\ instead of d:\ b/c on my machines d:\ is the CD-R drive).

I get the same results on both Win7sp1-x64 and Win7sp1-x86 (the 2 versions I tested).



That's all I did. Am I missing something you did to get a different result?


Previous Comments:
------------------------------------------------------------------------
[2012-02-07 11:00:19] feedbee at gmail dot com

Description:
------------
d:/link/ is a windows symlink to d:/a/b/c

mkdir('d:/link/../new') creates link in d:/ - that OK.

file_put_contents('d:/link/../new', 'OK'); tries to create file in d:/a/b
(because d:/link/ resolved to d:/a/b/c, and d:/a/b/c/../new now points to d:/a/b/new).

This difference between mkdir and file_put_contents was not expected.

Test script:
---------------
<?php

$dirname = 'd:/link/../new';
$realDirname = 'd:/new';

echo "Is Dir exists? ", is_dir($realDirname) ? 'Yes' : 'No', PHP_EOL,
'Create Dir', PHP_EOL;
mkdir($dirname);
echo "Is Dir exists NOW? ", is_dir($realDirname) ? 'Yes' : 'No',
PHP_EOL;
file_put_contents("$dirname/file", 'OK');
echo 'OK';

Expected result:
----------------
Is Dir exists? No
Create Dir
Is Dir exists NOW? Yes
OK

Actual result:
--------------
Is Dir exists? No
Create Dir
Is Dir exists NOW? Yes
<br />
<b>Warning</b>:  file_put_contents(d:/link/../new/file) [<a
href='function.file-put-contents'>function.file-put-contents</a>]: failed to open
stream: No such file or directory in <b>D:\test.php</b> on line
<b>10</b><br />
OK


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61002&edit=1


Thread (3 messages)

« previous php.bugs (#167485) next »