Made FormFlashFile more robust against deleted files (over time)

This commit is contained in:
Matias Griese
2019-01-29 22:22:00 +02:00
parent 5f5bfdaa42
commit bbdac0fd6d
2 changed files with 8 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
1. [](#improved) 1. [](#improved)
* Improved `$page->forms()` call, added `$page->addForms()` * Improved `$page->forms()` call, added `$page->addForms()`
* Made `FormFlashFile` more robust against deleted files (over time)
1. [](#bugfix) 1. [](#bugfix)
* Fixed a bug in `FormFlashFile::moveTo()` not deleting the old file * Fixed a bug in `FormFlashFile::moveTo()` not deleting the old file

View File

@@ -26,12 +26,13 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
$this->upload = $upload; $this->upload = $upload;
$this->flash = $flash; $this->flash = $flash;
if ($this->isOk() && (empty($this->upload['tmp_name']) || !file_exists($this->getTmpFile()))) { $tmpFile = $this->getTmpFile();
if (!$tmpFile && $this->isOk()) {
$this->upload['error'] = \UPLOAD_ERR_NO_FILE; $this->upload['error'] = \UPLOAD_ERR_NO_FILE;
} }
if (!isset($this->upload['size'])) { if (!isset($this->upload['size'])) {
$this->upload['size'] = $this->isOk() ? filesize($this->getTmpFile()) : 0; $this->upload['size'] = $tmpFile && $this->isOk() ? filesize($tmpFile) : 0;
} }
} }
@@ -116,7 +117,9 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
return null; return null;
} }
return $this->flash->getTmpDir() . '/' . $tmpName; $tmpFile = $this->flash->getTmpDir() . '/' . $tmpName;
return file_exists($tmpFile) ? $tmpFile : null;
} }
public function __debugInfo() public function __debugInfo()
@@ -142,7 +145,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
} }
if (!$this->getTmpFile()) { if (!$this->getTmpFile()) {
throw new \RuntimeException('Cannot retrieve stream as the file was not uploaded'); throw new \RuntimeException('Cannot retrieve stream as the file is missing');
} }
} }