Skip to content

Commit

Permalink
Added disk space detection (fixes #22) and renaming of invalid SPKs (f…
Browse files Browse the repository at this point in the history
…ixes #25).
  • Loading branch information
mbirth committed Feb 25, 2017
1 parent c89febd commit f85069d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/SSpkS/Package/Package.php
Expand Up @@ -187,7 +187,20 @@ public function extractIfMissing($inPkgName, $targetFile)
}
// Try to extract file
$tmp_dir = sys_get_temp_dir();
$p = new \PharData($this->filepath, \Phar::CURRENT_AS_FILEINFO | \Phar::KEY_AS_FILENAME);
$free_tmp = disk_free_space($tmp_dir);
if ($free_tmp < 2048) {
throw new \Exception('TMP folder only has ' . $free_tmp . ' Bytes space available. Disk full!');
}
$free = disk_free_space(dirname($targetFile));
if ($free < 2048) {
throw new \Exception('Package folder only has ' . $free . ' Bytes space available. Disk full!');
}
try {
$p = new \PharData($this->filepath, \Phar::CURRENT_AS_FILEINFO | \Phar::KEY_AS_FILENAME);
} catch (\UnexpectedValueException $e) {
rename($this->filepath, $this->filepath . '.invalid');
throw new \Exception('Package ' . $this->filepath . ' not readable! Will be ignored in the future. Please try again!');
}
$p->extractTo($tmp_dir, $inPkgName);
rename($tmp_dir . DIRECTORY_SEPARATOR . $inPkgName, $targetFile);
return true;
Expand Down

0 comments on commit f85069d

Please sign in to comment.