Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
Fixes #30: Check directory is writable before moving downloaded file.…
Browse files Browse the repository at this point in the history
… Also check that is exists afterwards.
  • Loading branch information
bobbyshaw committed Mar 14, 2016
1 parent 637ec7e commit c7c41ef
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Meanbee/Magedbm/Command/GetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,16 @@ protected function backupMove($file)
{
$filename = $this->getFilePath($file);
$newFilename = getcwd() . '/' . $file;
if (rename($filename, $newFilename)) {
$this->getOutput()->writeln("<info>Downloaded to $newFilename.</info>");

if (!is_writable(getcwd())) {
$this->getOutput()->writeln("<info>Unable to write to current working directory. Check $filename</info>");
return;
}

$result = rename($filename, $newFilename);

if ($result && file_exists($newFilename)) {
$this->getOutput()->writeln("<info>Downloaded to $newFilename</info>");
} else {
$this->getOutput()->writeln("<error>Failed to move backup to current working directory. Check $filename</error>");
}
Expand Down

0 comments on commit c7c41ef

Please sign in to comment.