mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
Only open target if source can be opened
This prevents empty files from being created if a remote file can't be opened.
This commit is contained in:
parent
2877a6e3da
commit
c67e9b9222
1 changed files with 7 additions and 6 deletions
|
|
@ -223,6 +223,12 @@ class NativeShare extends AbstractShare {
|
|||
if (!$target) {
|
||||
throw new InvalidPathException('Invalid target path: Filename cannot be empty');
|
||||
}
|
||||
|
||||
$sourceHandle = $this->getState()->open($this->buildUrl($source), 'r');
|
||||
if (!$sourceHandle) {
|
||||
throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading');
|
||||
}
|
||||
|
||||
$targetHandle = @fopen($target, 'wb');
|
||||
if (!$targetHandle) {
|
||||
$error = error_get_last();
|
||||
|
|
@ -231,15 +237,10 @@ class NativeShare extends AbstractShare {
|
|||
} else {
|
||||
$reason = 'Unknown error';
|
||||
}
|
||||
$this->getState()->close($sourceHandle);
|
||||
throw new InvalidResourceException('Failed opening local file "' . $target . '" for writing: ' . $reason);
|
||||
}
|
||||
|
||||
$sourceHandle = $this->getState()->open($this->buildUrl($source), 'r');
|
||||
if (!$sourceHandle) {
|
||||
fclose($targetHandle);
|
||||
throw new InvalidResourceException('Failed opening remote file "' . $source . '" for reading');
|
||||
}
|
||||
|
||||
while ($data = $this->getState()->read($sourceHandle, NativeReadStream::CHUNK_SIZE)) {
|
||||
fwrite($targetHandle, $data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue