Bug #81404 [Com]: rename() does not keep extended file attributes

From: Date: Wed, 14 Dec 2022 05:19:06 +0000
Subject: Bug #81404 [Com]: rename() does not keep extended file attributes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243138@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81404&edit=1

 ID:                 81404
 Comment by:         fariba dot shami326 at gmail dot com
 Reported by:        rdueck at mcmillan-mcgee dot com
 Summary:            rename() does not keep extended file attributes
 Status:             Open
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   Debian 10, Linux 4.19.0-17-amd64
 PHP Version:        7.4.23
 Block user comment: N
 Private report:     N

 New Comment:

That's great. I was impressed by your writing. I am happy to see such a topic. Please come to
my blog and read it.


(https://www.mykplan.me/)php.net


Previous Comments:
------------------------------------------------------------------------
[2021-09-01 20:22:52] cmb@php.net

Okay, switching back to bug than.  However, this will be hard to
implement for all possible information (e.g. NTFS streams come to
mind), and might not be possible in a fully backwards compatible
way.

------------------------------------------------------------------------
[2021-09-01 14:50:30] rdueck at mcmillan-mcgee dot com

I disagree with it being a feature request.  If rename() switches to copy internally, it must still
produce the same result.  If it fails to produce exactly the same result, it should be reported as
an error, such as, "PHP Warning: extended attributes not moved".  Documentation would
certainly help, for example, "Extended attributes may or may not stay with the new file",
but unambiguous behaviour would be better.  I think it is most reasonable to expect that rename()
and the system 'mv' command would behave the same.

------------------------------------------------------------------------
[2021-09-01 09:33:25] cmb@php.net

> I added an inode check and confirmed that both rename() and 'mv'
> are being performed as copy-and-delete when run from apache.

Thanks for checking.  In this case this is more like a feature
request to me (and something that should be documented).

------------------------------------------------------------------------
[2021-08-31 20:00:16] rdueck at mcmillan-mcgee dot com

I added an inode check and confirmed that both rename() and 'mv' are being performed as
copy-and-delete when run from apache. 'mv' preserves extended attributes when copying, but
rename() does not.

Test script:

<?php
// Requires xattr:
//   pecl install xattr
// then add 'extension=xattr.so' to php.ini
// ASSUME: current directory is not /tmp
$a = tempnam('/tmp','my');
$b = basename($a);
for ($i=0; $i<2; $i++) {
  file_put_contents($a,'TestData');
  $inode_a = stat($a)['ino'];
  xattr_set($a,'owner','me');
  switch($i){
    case 0: rename($a,$b); $fn='rename'; break;
    case 1: mv $a $b; $fn='mv'; break;
  }
  $inode_b = stat($b)['ino'];
  $owner = xattr_get($b,'owner');
  echo "$fn ".($owner=='me'?'SUCCEEDED':'FAILED').",
internal operation: ".($inode_a==$inode_b?'move':'copy')."\n";
}

------------------------------------------------------------------------
[2021-08-31 17:40:00] rdueck at mcmillan-mcgee dot com

I tried the test script from the command-line as the www-data user, and rename() still works
correctly.

I've also corrected the PHP version; I have not tested PHP 8.0.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=81404


--
Edit this bug report at https://bugs.php.net/bug.php?id=81404&edit=1


Thread (11 messages)

« previous php.bugs (#243138) next »