Corrected shadow copy logic to not use stream_copy_to_stream() as it causes unexpected results.
This commit is contained in:
parent
9ded98c3e1
commit
770dde9ed2
1 changed files with 27 additions and 5 deletions
|
@ -692,19 +692,41 @@
|
||||||
public function saveCopy(string $path): void
|
public function saveCopy(string $path): void
|
||||||
{
|
{
|
||||||
$destination = fopen($path, 'wb');
|
$destination = fopen($path, 'wb');
|
||||||
if($destination === false)
|
|
||||||
|
if ($destination === false)
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('Failed to open file \'%s\'', $path));
|
throw new IOException(sprintf('Failed to open file \'%s\'', $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the package file to the destination
|
fseek($this->package_file, $this->package_offset);
|
||||||
if(stream_copy_to_stream($this->package_file, $destination, $this->package_length, $this->package_offset) === false)
|
$remaining_bytes = $this->package_length;
|
||||||
|
|
||||||
|
while ($remaining_bytes > 0)
|
||||||
{
|
{
|
||||||
throw new IOException(sprintf('Failed to copy package file to \'%s\'', $path));
|
$bytes_to_read = min($remaining_bytes, 4096);
|
||||||
|
$data = fread($this->package_file, $bytes_to_read);
|
||||||
|
|
||||||
|
if ($data === false)
|
||||||
|
{
|
||||||
|
throw new IOException('Failed to read from package file');
|
||||||
|
}
|
||||||
|
|
||||||
|
$written_bytes = fwrite($destination, $data, $bytes_to_read);
|
||||||
|
|
||||||
|
if ($written_bytes === false)
|
||||||
|
{
|
||||||
|
throw new IOException(sprintf('Failed to write to file \'%s\'', $path));
|
||||||
|
}
|
||||||
|
|
||||||
|
$remaining_bytes -= $written_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done!
|
|
||||||
fclose($destination);
|
fclose($destination);
|
||||||
|
|
||||||
|
if((new PackageReader($path))->getChecksum() !== $this->getChecksum())
|
||||||
|
{
|
||||||
|
throw new IOException(sprintf('Failed to save package copy to \'%s\', checksum mismatch', $path));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue