Re: Renaming a Directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/9/09 12:08 AM, "Paul M Foster" <paulf@xxxxxxxxxxxxxxxxx> wrote:

> On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote:
> 
>> How can I rename a directory with files in it?  The rename function
>> gives me a "directory not empty" error.  I know I could do it be
>> creating the directory, moving the files, and then deleting the old
>> one.  Is there an easier way?
> 
> It sounds like, underneath, rename() is creating a new directory and
> then attempting to delete the old one, ignoring the files in the
> original directory.

really?

the test below seems to show that php rename() is happy to rename
directories that are not empty. it even renames ones that contain files that
it neither owns nor has any permissions for. that suggests it is just
changing the name of the directory.

so the error message floyd reported is still a mystery to me, assuming
/bin/mv worked for the same old and new directories where php rename()
failed.

$ mkdir wwwdir
$ sudo chown www:www wwwdir
$ cd wwwdir
$ sudo -u www mkdir testdir
$ sudo -u www touch testdir/foo testdir/bar
$ sudo -u www php -r "echo rename('testdir','dirtest');"
1$ ls -la dirtest
total 0
drwxr-xr-x  4 _www  _www  136 Sep  9 09:57 .
drwxr-xr-x  3 _www  _www  102 Sep  9 09:57 ..
-rw-r--r--  1 _www  _www    0 Sep  9 09:57 bar
-rw-r--r--  1 _www  _www    0 Sep  9 09:57 foo
$ sudo -u www chmod 000 dirtest/foo
$ sudo -u www php -r "echo rename('dirtest','testdir');"
1$ ls -la testdir
total 0
drwxr-xr-x  4 _www  _www  136 Sep  9 09:57 .
drwxr-xr-x  3 _www  _www  102 Sep  9 09:57 ..
-rw-r--r--  1 _www  _www    0 Sep  9 09:57 bar
----------  1 _www  _www    0 Sep  9 09:57 foo
$ sudo chown root:wheel testdir/foo
$ sudo -u www -u www php -r "echo rename('testdir','dirtest');"
1$ ls -la dirtest
total 0
drwxr-xr-x  4 _www  _www   136 Sep  9 09:57 .
drwxr-xr-x  3 _www  _www   102 Sep  9 09:57 ..
-rw-r--r--  1 _www  _www     0 Sep  9 09:57 bar
----------  1 root  wheel    0 Sep  9 09:57 foo
$ php -v
PHP 5.2.8 (cli) (built: Feb  5 2009 21:21:13)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
$ uname -v
Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009;
root:xnu-1228.15.4~1/RELEASE_I386
$ 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux