Skip to content

Commit

Permalink
[Filesystem] Fix usages of error_get_last()
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed May 13, 2018
1 parent 9f01f9b commit da48c21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions File/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ public function move($directory, $name = null)
{
$target = $this->getTargetFile($directory, $name);

if (!@rename($this->getPathname(), $target)) {
$error = error_get_last();
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
$renamed = rename($this->getPathname(), $target);
restore_error_handler();
if (!$renamed) {
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error)));
}

@chmod($target, 0666 & ~umask());
Expand Down
8 changes: 5 additions & 3 deletions File/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ public function move($directory, $name = null)

$target = $this->getTargetFile($directory, $name);

if (!@move_uploaded_file($this->getPathname(), $target)) {
$error = error_get_last();
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message'])));
set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
$moved = move_uploaded_file($this->getPathname(), $target);
restore_error_handler();
if (!$moved) {
throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error)));
}

@chmod($target, 0666 & ~umask());
Expand Down

0 comments on commit da48c21

Please sign in to comment.