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)
* Improved `$page->forms()` call, added `$page->addForms()`
* Made `FormFlashFile` more robust against deleted files (over time)
1. [](#bugfix)
* 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->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;
}
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 $this->flash->getTmpDir() . '/' . $tmpName;
$tmpFile = $this->flash->getTmpDir() . '/' . $tmpName;
return file_exists($tmpFile) ? $tmpFile : null;
}
public function __debugInfo()
@@ -142,7 +145,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
}
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');
}
}