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

Commit

Permalink
Merge pull request #31 from meanbee/30-improve-check-for-file-move-su…
Browse files Browse the repository at this point in the history
…ccess

Fixes #30: Check directory is writable before moving downloaded file.
  • Loading branch information
bobbyshaw committed Mar 16, 2016
2 parents 6a3c905 + c7c41ef commit e4cb77e
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 e4cb77e

Please sign in to comment.