|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30388 rename across filesystems loses ownership and permission info
Submitted: 2004-10-11 04:00 UTC Modified: 2004-10-27 14:06 UTC
From: drachma60 at ml1 dot net Assigned: tony2001 (profile)
Status: Closed Package: Filesystem function related
PHP Version: 4.3.8 OS: FreeBSD
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 !
Your email address:
Solve the problem:
48 - 1 = ?
Subscribe to this entry?

 [2004-10-11 04:00 UTC] drachma60 at ml1 dot net
When renaming a file (via the "rename" function) across filesystems, owner, group and permission information will be lost if (a) we are running as root and (b) the file is not owned by root.

Additionally, I suspect that permission information can be lost even if (a) we are not running as root and (b) we are running as the user who owns the file.

Reproduce code:

// I am running as root
touch ("/tmp/testfile");
passthru ("ls -l /tmp/testfile");

chown ("/tmp/testfile", "nobody");
chgrp ("/tmp/testfile", "nobody");
chmod ("/tmp/testfile", 0);
passthru ("ls -l /tmp/testfile");

rename ("/tmp/testfile", "/tmp/testfile2");
passthru ("ls -l /tmp/testfile2");

rename ("/tmp/testfile2", "/home/testfile2");
passthru ("ls -l /home/testfile2");


Expected result:
-rw-r--r--  1 root  wheel  0 Oct 10 18:53 /tmp/testfile
----------  1 nobody  nobody  0 Oct 10 18:53 /tmp/testfile
----------  1 nobody  nobody  0 Oct 10 18:53 /tmp/testfile2
----------  1 nobody  nobody  0 Oct 10 18:53 /home/testfile2

Actual result:
-rw-r--r--  1 root  wheel  0 Oct 10 18:53 /tmp/testfile
----------  1 nobody  nobody  0 Oct 10 18:53 /tmp/testfile
----------  1 nobody  nobody  0 Oct 10 18:53 /tmp/testfile2
-rw-r--r--  1 root  wheel  0 Oct 10 18:53 /home/testfile2


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-11 04:06 UTC] drachma60 at ml1 dot net
(corrected typos in summary line)
 [2004-10-23 13:56 UTC]
Well, yes, PHP in this particular case works exactly as `cp`:
linux:/ # touch /tmp/testfile
linux:/ # chown nobody:nobody /tmp/testfile
linux:/ # ls -l /tmp/testfile
-rw-r--r--  1 nobody nobody 0 Oct 23 15:47 /tmp/testfile
linux:/ # cp /tmp/testfile /usr/testfile
linux:/ # ls -l /usr/testfile
-rw-r--r--  1 root root 0 Oct 23 15:47 /usr/testfile

but `mv` preserves permissions and IMO rename() should behave in the same way.

I'll write a patch shortly.
 [2004-10-24 14:00 UTC]
Here are the patches: - for 4.3.10-dev - for 5.1-dev

Waiting for Wez's response, as he's the maintainer of streams.
 [2004-10-27 14:06 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 12:01:28 2024 UTC