Skip to content

[Finder] isDir() with S3 stream wrapper is always false on Windows #57900

Open
@VT-TB

Description

@VT-TB

Symfony version(s) affected

5.4.42

Description

on Windows, isDir() always returns false on all files found using symfony/finder v5.4.42

S3 structure:

test-bucket-symfony-finder
    test_dir/
        test_obj.txt
        test_subdir/
            test_obj.txt

How to reproduce

composer.json

{
    "require": {
        "aws/aws-sdk-php": "^3.281",
        "symfony/finder": "^5.4.0"
    }
}

finder.php

<?php
require 'vendor/autoload.php';

$s3Client = new Aws\S3\S3Client([
    'version' => '2006-03-01',
    'region' => 'eu-central-1'
]);

$s3Client->registerStreamWrapper();

$bucket = "test-bucket-symfony-finder";
$root = "s3://$bucket/test_dir";

$finder = new \Symfony\Component\Finder\Finder();
try {
    $files = $finder->in($root);

    foreach ($files as $file) {
        echo "Finder File: " . $file->getPath() . '/' .  $file->getFilename() . "; isDir: " . ($file->isDir() ? "true" : "false") . "\n";
    }

    foreach ($files as $file) {
        $fi = new \SplFileInfo($file->getPath() . '/' .  $file->getFilename());
        echo "Raw File: " . $fi->getPath() . '/' .  $fi->getFilename() . "; isDir: " . ($fi->isDir() ? "true" : "false") . "\n";
    }
} catch (\Exception $e) {
    return false;

}

On Windows, php finder.php echos:

Finder File: s3://test-bucket-symfony-finder/test_dir/test_object.txt; isDir: false
Finder File: s3://test-bucket-symfony-finder/test_dir/test_subdir; isDir: false
Raw File: s3://test-bucket-symfony-finder/test_dir/test_object.txt; isDir: false
Raw File: s3://test-bucket-symfony-finder/test_dir/test_subdir; isDir: true

whereas on Linux it echos:

Finder File: s3://test-bucket-symfony-finder/test_dir/test_object.txt; isDir: false
Finder File: s3://test-bucket-symfony-finder/test_dir/test_subdir; isDir: true
Finder File: s3://test-bucket-symfony-finder/test_dir/test_subdir/test_object.txt; isDir: false
Raw File: s3://test-bucket-symfony-finder/test_dir/test_object.txt; isDir: false
Raw File: s3://test-bucket-symfony-finder/test_dir/test_subdir; isDir: true
Raw File: s3://test-bucket-symfony-finder/test_dir/test_subdir/test_object.txt; isDir: false

Possible Solution

as you can see, when creating a new \SplFileInfo from the Iterator Finder() returns, isDir() will return the correct result, but on Windows however the Finder() won't recursively traverse sub directories since it doesn't recognize that test_subdir/ is a directory. Wrapping everything manually and recursively would be pretty annoying

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions