php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77187 mkdir() fails to create dir after using some func-s on the parent dir
Submitted: 2018-11-22 23:37 UTC Modified: 2020-11-30 18:01 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: batonxleba at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Directory function related
PHP Version: 7.2.10 OS: gentoo
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: batonxleba at gmail dot com
New email:
PHP Version: OS:

 

 [2018-11-22 23:37 UTC] batonxleba at gmail dot com
Description:
------------
mkdir () does not create a subdirectory and generates an error when I try to create it in a directory that has the same name as the file that was deleted before this but any of the is_dir / file_exists / is_writable functions were applied to it.
if i comment line 5 in example below script will work fine.

my cli php
PHP 7.2.10 (cli) (built: Nov 10 2018 11:44:18) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10, Copyright (c) 1999-2018, by Zend Technologies


Test script:
---------------
#!/usr/bin/php
<?php
exec('> vpupkin');

if(is_dir('vpupkin'))print 'true'."\n";

exec('rm -f vpupkin');
mkdir('vpupkin',0700);
mkdir('vpupkin/'.date("d.m.Y"),0700);

?>

Actual result:
--------------
dev ~/testftp # rm -r vpupkin; ./t.php
PHP Warning:  mkdir(): No such file or directory in /root/testftp/t.php on line 9

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-23 10:39 UTC] a at b dot c dot de
Other observations from a Win10 build consistent with the above:
1) clearstatcache() doesn't affect behaviour
2) Being Windows, using "del" instead of an "rm" port doesn't fix things.
3) a single mkdir('vpupkin/'.date("d.m.Y"), 0700, true) call fails in the same way as the two consecutive mkdirs() (vpupkin is created but can't be found to create the subdirectory within it).
4) using unlink() instead of exec('rm') does allow the subdirectory to be created.
 [2018-11-24 14:43 UTC] batonxleba at gmail dot com
unlink() solved the problem for me, thanks a lot!
 [2018-11-24 14:45 UTC] batonxleba at gmail dot com
-PHP Version: 7.2.12 +PHP Version: 7.2.10
 [2018-11-24 14:45 UTC] batonxleba at gmail dot com
UPD: Using unlink() instead of exec('rm') solved the problem for me.
 [2020-11-30 18:01 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-11-30 18:01 UTC] cmb@php.net
The problem is that the realpathcache (the stat cache is
irrelevant here) is not aware of the external change.  Calling
clearstatcache(true) after executing exec('rm -f vpupkin') solves
that problem.

So this is expected behavior, which is also documented on the
clearstatcache() page[1].

[1] <https://www.php.net/clearstatcache>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 14:01:27 2024 UTC