php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54097 rename() of dirs accross devices produces confusing copy error
Submitted: 2011-02-25 02:10 UTC Modified: 2011-02-25 02:12 UTC
Votes:52
Avg. Score:4.2 ± 0.9
Reproduced:51 of 52 (98.1%)
Same Version:8 (15.7%)
Same OS:25 (49.0%)
From: clint at ubuntu dot com Assigned:
Status: Open Package: Filesystem function related
PHP Version: 5.3.6RC1 OS: Linux (Ubuntu)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
20 - 4 = ?
Subscribe to this entry?

 
 [2011-02-25 02:10 UTC] clint at ubuntu dot com
Description:
------------
When a user tries to rename a directory accross filesystems, they are presented 
with this warning:


PHP Warning:  rename(): The first argument to copy() function cannot be a 
directory in Command line code on line 1
PHP Warning:  rename(t2,/var/run/test/t2): Invalid cross-device link in Command 
line code on line 1

To contrast this, running 'mv t2 /var/run/test/t2' works without any problems.


Test script:
---------------
$ sudo mkdir /var/run/test && sudo chown `whoami` /var/run/test
$ mkdir t2
$ touch t2/a.file
$ php -r "rename('t2','/var/run/test/t2');"


Expected result:
----------------
I would expect the directory to be copied with its contents in their entirety to 
the new destination, *OR* at the very least, an error message that specifies that 
one cannot rename directories, as its confusing that it mentions copy during a 
rename.

Actual result:
--------------
PHP Warning:  rename(): The first argument to copy() function cannot be a 
directory in Command line code on line 1
PHP Warning:  rename(t2,/var/run/test/t2): Invalid cross-device link in Command 
line code on line 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-25 02:12 UTC] clint at ubuntu dot com
I forgot to mention, this was reported in Ubuntu here:

https://launchpad.net/bugs/723330
 [2012-11-01 18:45 UTC] tyler dot bannister at remote-learner dot net
This bug also affects PHP 5.3.3 on RHEL 5.8.
 [2013-12-19 22:42 UTC] php at mike2k dot com
Still an issue in 5.4.x:

$ uname -a
Linux foo 3.8.0-34-generic #49~precise1-Ubuntu SMP Wed Nov 13 18:05:00 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.3 LTS
Release:        12.04
Codename:       precise

$ php -v
PHP 5.4.23-1+sury.org~precise+1

Would really appreciate another flag to rename(), or change the behavior as described in the Ubuntu bug. Something should be done.
 [2013-12-19 23:00 UTC] php at mike2k dot com
The ticket isn't as descriptive as it should be, but it does cover 3 different pieces:

a) the warning is confusing, but the copy() I assume is copy() in C, not PHP's copy()
b) the documentation says rename() works across filesystems/devices in Linux (4.3.3+) and Windows (5.3.1+) - however, it does for FILES, but not DIRECTORIES.
c) the expected behavior is still a cross-device or cross-filesystem move, when using the function.

So there is (a) a confusing warning message, (b) documentation that needs a little bit of additional information, and (c) a possible bug or feature-ish change requested for rename()
 [2015-07-07 18:24 UTC] oxygenus at gmail dot com
Workaround:

exec("mv ".escapeshellarg($strOldPath)." ".escapeshellarg($strNewPath));
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC