Bug #88524

rmdir not respecting POSIX standard - missing files

Added by Pascal Christen 17 days ago. Updated 17 days ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2019-06-07
Due date:
% Done:

0%

TYPO3 Version:
10
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Hi

Having a problem with typo3 and it's own written rmdir function: https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/core/Classes/Utility/GeneralUtility.php#L2105

POSIX standard says the following:

If a file is removed from or added to the directory after 
the most recent call to opendir() or rewinddir(), whether 
a subsequent call to readdir() returns an entry for that file is unspecified

So the problem is, that it doesn't return all files while deleting it - for more details read the issue about the same topic here: https://github.com/emscripten-core/emscripten/issues/2528

As a consequence, e.g. deleting extensions does not work because it did not delete all files.

Thanks, greetings Pascal

History

#1 Updated by Pascal Christen 17 days ago

So I just "rebuilt" the function:

showfiles.php
<?php
function removeFiles($path)
{
    $handle = opendir($path);
        while (false !== ($file = readdir($handle))) {
            if ($file === '.' || $file === '..') {
                    continue;
            }
        echo "PATH $path/$file\n";
        #unlink($path . '/' . $file);
        }
        closedir($handle);
}
$path = realpath('/home/christes/test/');
removeFiles($path);

So, I'm touching 200 new files in the directory /home/christes/test/
[christes@xxx:~/test] $ touch test{001..200}.test

Now if I run the PHP-script without the unlink (commented out) - it's all fine:
[christes@xxx:~] $ php listdir.php | wc -l
     200

Now, if I remove the # in front of the ulink this happens:
[christes@xxx:~] $ php listdir.php | wc -l
     126
[christes@xxx:~] $ php listdir.php | wc -l
      74

On the first round, it only removes the first 126 files, if I rerun it again it deletes the remaining files.

And it deletes less files if the filename is longer:
[christes@xxx:~/test] $ touch testtesttesttesttesttesttesttesttesttesttest{001..200}.test
[christes@xxx:~] $ php listdir.php | wc -l
     111

Also available in: Atom PDF