rename() function didn't work with /tmp dir

Bug #723330 reported by Djalma Oliveira
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
php
Unknown
Unknown
php5 (Ubuntu)
Triaged
Wishlist
Unassigned

Bug Description

Binary package hint: php5

I got a error message trying rename a dir from DOCUMENT_ROOT to /tmp/ dir.

Example:
     rename("myfolder/", "/tmp/myfolder/");

return this Fatal error message ( yes, it talk about copy() function but I called rename() ):

      "The first argument to copy() function cannot be a directory."

But,
     rename("myfolder/", "myNEWfolder/");

it works fine inside the same DOCUMENT_ROOT path.

My enviroment:
PHP Version 5.3.3-1ubuntu9.3
Linux rock 2.6.35-26-generic #46-Ubuntu SMP Sun Jan 30 08:10:51 UTC 2011 i686
Apache/2.2.16 (Ubuntu)
Suhosin Patch 0.9.9.1
safe_mode = off

ProblemType: Bug
DistroRelease: Ubuntu 10.10
Package: php5 5.3.3-1ubuntu9.3
ProcVersionSignature: Ubuntu 2.6.35-26.46-generic 2.6.35.10
Uname: Linux 2.6.35-26-generic i686
NonfreeKernelModules: wl
Architecture: i386
Date: Tue Feb 22 16:13:37 2011
PackageArchitecture: all
ProcEnviron:
 LANGUAGE=en_US:en
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: php5

Revision history for this message
Djalma Oliveira (djalmaoliveira) wrote :
Revision history for this message
Clint Byrum (clint-fewbar) wrote :

Hi Djalma! Thanks for taking the time to file this bug report and help us make Ubuntu better.

Indeed, the error message is confusing, because while you called rename, copy is complaining.

This happens because of this snippet of code:

    ret = VCWD_RENAME(url_from, url_to);

    if (ret == -1) {
#ifndef PHP_WIN32
# ifdef EXDEV
        if (errno == EXDEV) {
            struct stat sb;
            if (php_copy_file(url_from, url_to TSRMLS_CC) == SUCCESS) {
                if (VCWD_STAT(url_from, &sb) == 0) {

Basically since your /tmp is a different partition than your home dir, php must emulate the low level unix rename by copying the file. The copy is failing because the source is a dir, and copy doesn't accept directories.

This is a bug, with an unclear resolution. Either rename should copy recursively the whole directory to the new device, or it should describe the problem with its own error message rather than relying on copy to do it in a confusing way.

I've forwarded the issue upstream to PHP, so I'll mark the issue as Triaged. There's nothing broken, its just not doing what we'd like it to, so I'l set status to Wishlist.

Changed in php5 (Ubuntu):
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Richard Price (richpri) wrote :

This problem has apparently been outstanding for ~7 years!
I still got the same confusing error message when the problem occurred.
The Rename documentation at http://php.net/manual/en/function.rename.php
still does not warn of this issue. The importance of errors and faulty
documentation should not, in my opinion, ever be "Wishlist".

In my opinion, simply forwarding this issue upstream to PHP has proven
to be a singularly ineffective move! At the very least please forward
these comments upstream to PHP.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.