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

From: Date: Tue, 31 Aug 2021 17:17:31 +0000
Subject: Bug #81404 [Opn]: rename() does not keep extended file attributes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236200@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
 Updated by:         cmb@php.net
 Reported by:        rdueck at mcmillan-mcgee dot com
 Summary:            rename() does not keep extended file attributes
 Status:             Open
 Type:               Bug
 Package:            *General Issues
 Operating System:   Debian 10, Linux 4.19.0-17-amd64
 PHP Version:        8.0.10
 Block user comment: N
 Private report:     N

 New Comment:

For files, PHP's rename tries to rename(2), but if that fails for
whatever reason, it actually copies the file, and removes the
original.  The latter would indeed ignore extended file attributes.
I'm not sure though, whether this is the reason in your case.


Previous Comments:
------------------------------------------------------------------------
[2021-08-31 17:05:18] rdueck at mcmillan-mcgee dot com

Description:
------------
When running from Apache2 using apache-mod-php, rename() strips extended attributes.  The same code
works from the command line, and the system 'mv' command works in both cases.

move_uploaded_file() has the same problem as rename().

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');
  xattr_set($a,'owner','me');
  switch($i){
    case 0: rename($a,$b); $fn='rename'; break;
    case 1: mv $a $b; $fn='mv'; break;
  }
  $owner = xattr_get($b,'owner');
  echo "$fn
".($owner=='me'?'SUCCEEDED':'FAILED')."\n";
}

Expected result:
----------------
rename SUCCEEDED
mv SUCCEEDED

Actual result:
--------------
rename FAILED
mv SUCCEEDED


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



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


Thread (11 messages)

« previous php.bugs (#236200) next »