Skip to content

Twistor\FlysystemStreamWrapper::stream_stat() sets size to 0 for at least some remote files, can result in empty files being written #21

Open
@DylanDonkersgoed

Description

@DylanDonkersgoed

I encountered this issue with https://github.com/thephpleague/flysystem-azure-blob-storage/issues/22 but I believe it could occur for other remote filesystems.

When I attempt copy with a remote file backed by flysystem-azure-blob-storage as the source it always writes 0 byte files at the destination. The culprit seems to be Twistor\FlysystemStreamWrapper::stream_stat() which sets the size of the returned $stat array to zero. This is because it calls Twistor\StreamUtil::getSize() which uses https://www.php.net/manual/en/function.fstat.php. There's a note on the documentation page:

Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.

I'm guessing that's why, though it fails in a much less obvious way than I'd expect from the note.

I'll attach a pull request shortly with a crude fix which ignores the fstat() filesize if it is zero and just uses the original file size from url_stat. I'm not sure if this is the best solution but it seems to work for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions