php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45228 unlink() & rmdir() do not work well with URL (file://)
Submitted: 2008-06-10 15:56 UTC Modified: 2009-05-06 20:21 UTC
Votes:11
Avg. Score:4.4 ± 1.1
Reproduced:10 of 10 (100.0%)
Same Version:7 (70.0%)
Same OS:7 (70.0%)
From: nanawel at eyeos dot org Assigned: pajoye (profile)
Status: Wont fix Package: Filesystem function related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
 [2008-06-10 15:56 UTC] nanawel at eyeos dot org
Description:
------------
The unlink() function does not work with full Windows URL, whereas fopen() for example works perfectly.

If you provide a path like this: file:///C:/my/path
(triple slashes) it won't work and you will get this warning:
Warning: unlink(/C:/my/path) [function.unlink]: Invalid argument in...

But if you provide this path: file://C:/my/path
(so just a slash less) unlink will work.

Reproduce code:
---------------
//For the example, we consider that PHP has full permissions on config.sys, which is not the case normally)

$path1 = 'file:///C:/config.sys';
$path2 = 'file://C:/config.sys';

$fp = fopen($path1, 'r');  //OK
@fclose($fp);
unlink($path1);            //ERROR

$fp = fopen($path2, 'r');  //OK
@fclose($fp);
unlink($path2);            //OK

Expected result:
----------------
unlink() should work with the same standards URL as fopen().
In my example, $path1 should be correct for both functions.

Actual result:
--------------
Windows absolute URL like file:///C:/... work with fopen(), rename() but _not_ with unlink() (+ Warning raised)

Windows non-standard URL like file://C:/... work with fopen(), rename() and unlink()

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-10 16:03 UTC] nanawel at eyeos dot org
Additionnally, unlink() doesn't work either on URL like: file://localhost/C:/my/path
and this is particularly _not_ normal.
 [2008-06-10 16:46 UTC] nanawel at eyeos dot org
A new set of problems:

- mkdir() only works with file://C:/my/path
  and fails on            file:///C:/my/path
  or                      file://localhost/C:/my/path

- rmdir() DOES NOT WORK with file://C:/my/path
  or                         file:///C:/my/path
  or                         file://localhost/C:/my/path
 [2008-07-14 20:08 UTC] nanawel at eyeos dot org
Another great one:
rmdir() DOES NOT WORK with the file:// scheme, AT ALL.
Tested on Windows and Ubuntu 8.04 (both on PHP 5.2.6).
 [2009-01-07 13:58 UTC] nanawel at eyeos dot org
Just changed the OS concerned by the issue.
 [2009-01-07 14:18 UTC] pajoye@php.net
Confusing comments. 

Does unlink work on linux?
Does unlink work on Windows?
Does rmdir work on Windows?
Does rmdir work on Windows?
 [2009-01-07 14:27 UTC] nanawel at eyeos dot org
Except for the rmdir() function which fails on both Windows AND Linux platforms, all the paths provided in the previous comments are explicite Windows paths.
You cannot use "C:\" or "C:/" or "file://C:/" or something else under Linux.

That's why I've just changed the OS concerned by the issue
from: * (all)
to: Windows

Thanks for your time.
 [2009-01-07 14:35 UTC] pajoye@php.net
as the report is about both rmdir and unlink, the issue is not windows specific. Will take care of it.
 [2009-01-07 14:58 UTC] nanawel at eyeos dot org
Ok, to sum up:

- mkdir()
    works with   file://C:/my/path            under Windows
    FAILS with   file:///C:/my/path           under Windows
    FAILS with   file://localhost/C:/my/path  under Windows

- rmdir()
    FAILS with   ALL file:// schemes          under Windows and Linux

- unlink()
    works with   file://C:/my/path            under Windows
    FAILS with   file:///C:/my/path           under Windows
    FAILS with   file://localhost/C:/my/path  under Windows

I think I didn't forget anything, hope this helps.
 [2009-03-02 16:07 UTC] pajoye@php.net
Some notes:

- mkdir()
    works with   file://C:/my/path            under Windows
expected.

    FAILS with   file:///C:/my/path           under Windows
expected (/c:/my/path is not a valid path)

    FAILS with   file://localhost/C:/my/path  under Windows
expected,localhost/C:/my/path is not a valid path (same for linux, fails as well)

However, the touch() funciton seems to have issue with file://, maybe other as well but I did not test them all yet.

- rmdir()
    FAILS with   ALL file:// schemes          under Windows and Linux

 [2009-05-06 18:55 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

This most likely duplicate of bug #45040
 [2009-05-06 19:29 UTC] pajoye@php.net
It is actually by design. I discussed with Rasmus and forgot to close it.
 [2009-05-06 20:19 UTC] nanawel at eyeos dot org
What do you mean "by design"?
Is it "designed" to fail on such a case? Why??

Why mixing functions that work with fully qualified URL for local files (like fopen) and some which don't??
Either all functions understand and work with URL, or none does.

At least, is the rmdir() case going to be fixed? (or is it already?)

Thanks in advance.
 [2009-05-06 20:21 UTC] pajoye@php.net
Only less than a handful protocols support the creation or deletion of directories.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 23:01:36 2024 UTC