core icon indicating copy to clipboard operation
core copied to clipboard

RecursiveDirectoryIterator does not work on NFS

Open pluijm opened this issue 12 years ago • 2 comments

See https://github.com/owncloud/core/blob/master/lib/private/files/storage/local.php#L44

I know this is a PHP bug, but it can be avoided. This might be related to https://bugs.php.net/bug.php?id=54256

Please use

<?php
$it->rewind();
while ($it->valid()) {
    echo $it->current()->getBasename().PHP_EOL;
    $it->next();
}
?>

In favor of

<?php
foreach ($it as $file) {
    echo $file->getBasename().PHP_EOL;
}
?>

Steps to reproduce

  1. Given $DIR is on an NFS mount
  2. mkdir $DIR/test
  3. touch $DIR/test/foo.bar
  4. cd $DIR
  5. Run:
<?php
$path = getcwd().'/test';
$it = new \RecursiveIteratorIterator(
    new \RecursiveDirectoryIterator($path),
    \RecursiveIteratorIterator::CHILD_FIRST
);
echo 'Test with foreach: '.PHP_EOL;
foreach ($it as $file) {
    echo $file->getBasename().PHP_EOL;
}
?>
  1. Run:
<?php
$path = getcwd().'/test';
$it = new \RecursiveIteratorIterator(
    new \RecursiveDirectoryIterator($path),
    \RecursiveIteratorIterator::CHILD_FIRST
);
echo 'Test with while: '.PHP_EOL;
$it->rewind();
while ($it->valid()) {
    echo $it->current()->getBasename().PHP_EOL;
    $it->next();
}
?>

Expected behaviour

Test with foreach:
foo.bar
..
Test with while: 
.
foo.bar
..

Actual behaviour

Test with foreach:
Test with while: 
.
foo.bar
..

The foreach fails.

Server configuration

Operating system: No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.04.4 LTS Release: 12.04 Codename: precise

Web server: Server version: Apache/2.2.22 (Ubuntu) Server built: Mar 19 2014 21:11:10

Database: psql (PostgreSQL) 9.1.9

PHP version: PHP 5.3.10-1ubuntu3.11 with Suhosin-Patch (cli) (built: Apr 4 2014 01:30:04)

ownCloud version: (see ownCloud admin page) ownCloud 6.0.2 (git)

Updated from an older ownCloud or fresh install: fresh install

List of activated apps: none

The content of config/config.php: Upon request

Are you using external storage, if yes which one: local/smb/sftp/... NFS3 on a local mount

Are you using encryption: yes/no encripted partition

Client configuration

Browser: N/A

Operating system: N/A

Logs

Web server error log

N/A

ownCloud log (data/owncloud.log)

N/A

Browser log

N/A

pluijm avatar Apr 28 '14 06:04 pluijm

Additional information: I've tested this with PHP5.5.9 on a NFS4 mount without any problems

pluijm avatar Apr 28 '14 07:04 pluijm

@icewind1991 @bantu @karlitschek Can you please have a look?

@pluijm Thanks a lot for digging into this! Can I ask you to open a pull request and contribute your fix? THX

DeepDiver1975 avatar Apr 28 '14 07:04 DeepDiver1975