Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle warnings when reading manifest and cleaning download locks #130

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/CoreAgent/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Log\LoggerInterface;
use RuntimeException;
use Throwable;
use Webmozart\Assert\Assert;
use function basename;
use function copy;
use function dirname;
Expand Down Expand Up @@ -149,7 +150,16 @@ private function obtainDownloadLock() : void

private function cleanStaleDownloadLock() : void
{
if (! file_exists($this->download_lock_path)) {
$this->logger->debug(sprintf('Lock path "%s" did not exist, nothing to clean', $this->download_lock_path));

return;
}

try {
Assert::fileExists($this->download_lock_path);
Assert::file($this->download_lock_path);

$delta = time() - filectime($this->download_lock_path);
if ($delta > $this->stale_download_secs) {
$this->logger->debug(sprintf('Clearing stale download lock file "%s".', $this->download_lock_path));
Expand Down
5 changes: 5 additions & 0 deletions src/CoreAgent/Manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psr\Log\LoggerInterface;
use RuntimeException;
use Throwable;
use Webmozart\Assert\Assert;
use const JSON_ERROR_NONE;
use function file_get_contents;
use function json_decode;
Expand Down Expand Up @@ -55,6 +56,10 @@ private function parse() : void
{
$this->logger->info(sprintf('Parsing Core Agent Manifest at "%s"', $this->manifestPath));

Assert::fileExists($this->manifestPath);
Assert::file($this->manifestPath);
Assert::readable($this->manifestPath);

$raw = file_get_contents($this->manifestPath);
$json = json_decode($raw, true); // decode the JSON into an associative array

Expand Down