Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DylanDonkersgoed opened this issue Oct 23, 2020 · 1 comment

Comments

@DylanDonkersgoed
Copy link

DylanDonkersgoed commented Oct 23, 2020

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.

@AbhayPai
Copy link

I faced similar issue, what i did was just to put default stat

        // Use the size of our handle, since it could have been written to or
        // truncated.
        $stream_util_size = StreamUtil::getSize($this->handle);
        if (!empty($stream_util_size)) {
            // Only set size if stream_util_size is available or
            // just send original file metadata.
            $stat['size'] = $stat[7] = $stream_util_size;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants