diff --git a/CHANGES b/CHANGES index 3e1fc4d..43245f3 100644 --- a/CHANGES +++ b/CHANGES @@ -27,3 +27,8 @@ - Renamed the lock file from `fresh.lock` to `.fresh.lock`. - Added option `--lockfile` to override lockfile file name. - Implemented the fresh configuration loader. + +**0.1.5** + +- Bugfix: The lockfile is no longer removed automatically, but only if it was + created by the current instance. diff --git a/README.md b/README.md index ef2c1fc..0d6e8e3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ a light-weight easy-to-use alternative to more complex toolkits. Fresh requires **PHP 8.0** or later. Download the latest version (or build it yourself) and move it into `/usr/bin`. -You can grab it at [https://dev.noccylabs.info/noccy/fresh/releases](https://dev.noccylabs.info/noccy/fresh/releases). +You can grab it at [https://dev.noccylabs.info/noccy/fresh/releases](https://dev.noccylabs.info/noccy/fresh/releases) +or [https://files.noccylabs.info/fresh](https://files.noccylabs.info/fresh) ### Building diff --git a/src/Refresher.php b/src/Refresher.php index 8dc7bc0..50ff4f8 100644 --- a/src/Refresher.php +++ b/src/Refresher.php @@ -198,6 +198,8 @@ class Refresher $this->setupConfiguration(); $this->setupHooks(); + $this->lockfile->lock(); + $updated = $this->checkUpdates(); // If called with --check, only return exit status @@ -217,7 +219,7 @@ class Refresher $this->callHooks($updated, 'after'); $this->callScript('after'); } - + $this->lockfile->release(); exit(($updated === null) ? 0 : 1); } catch (\Throwable $t) { @@ -226,6 +228,7 @@ class Refresher if (!$this->options['verbose']) { fprintf(STDERR, $this->log->asString()."\n"); } + $this->lockfile->release(); exit(2); } @@ -253,6 +256,8 @@ class Refresher $lockfile = $this->options['lockfile']; if (!str_starts_with($lockfile,'/')) $lockfile = $this->path . "/" . $lockfile; + $this->log->append("Statefile: {$statefile}"); + $this->log->append("Lockfile: {$lockfile}"); $this->state = new PersistentState($statefile); // $this->path . "/" . self::$StateFileName); $this->lockfile = new Lockfile($lockfile); // $this->path . "/" . self::$LockFileName); } @@ -359,8 +364,6 @@ class Refresher private function checkUpdates(): ?array { - $this->lockfile->lock(); - $checks = $this->config->getChecks(); if (count($checks) === 0) { fwrite(STDERR, "error: couldn't find any images to check\n"); diff --git a/src/Registry/RegistryV2Client.php b/src/Registry/RegistryV2Client.php index f35816c..c3f55a1 100644 --- a/src/Registry/RegistryV2Client.php +++ b/src/Registry/RegistryV2Client.php @@ -23,7 +23,11 @@ class RegistryV2Client public function getManifest(string $image, string $tag) { - $response = $this->client->get("{$image}/manifests/{$tag}"); + $response = $this->client->get("{$image}/manifests/{$tag}", [ + 'headers' => [ + //'Accept' => 'application/vnd.docker.distribution.manifest.v2+json', + ] + ]); $body = $response->getBody(); return json_decode($body); } @@ -32,12 +36,16 @@ class RegistryV2Client { $manifest = $this->getManifest($image, $tag); - $fslayers = (array)$manifest->fsLayers; - $fshashes = array_map(fn($layer) => $layer->blobSum, $fslayers); + //print_r($manifest); + + $fslayers = (array)(($manifest->fsLayers??$manifest->layers)??[]); + $fshashes = array_map(fn($layer) => $layer->blobSum??$layer->digest, $fslayers); $metahash = hash("sha256", join("|", $fshashes)); - $history = $manifest->history[0]; - $info = json_decode($history->v1Compatibility); + if (isset($manifest->history)) { + $history = $manifest->history[0]; + $info = json_decode($history->v1Compatibility); + } return [ 'image' => $image, diff --git a/src/State/Lockfile.php b/src/State/Lockfile.php index 21abcc8..e87d687 100644 --- a/src/State/Lockfile.php +++ b/src/State/Lockfile.php @@ -8,6 +8,8 @@ class Lockfile private int $maxLock = 3600; + private bool $locked = false; + public function __construct(string $filename) { $this->filename = $filename; @@ -22,15 +24,16 @@ class Lockfile } } touch($this->filename); + $this->locked = true; } public function release() { - if (file_exists($this->filename)) { + if ($this->locked && file_exists($this->filename)) { unlink($this->filename); } - + $this->locked = false; } -} \ No newline at end of file +} diff --git a/tools/build.sh b/tools/build.sh index 55dc025..b5d2ab1 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -11,9 +11,10 @@ NOW="$(date +"%Y-%m-%d")" # create output directory mkdir -p dist -# update version.php and build thephar +# update version.php and build the phar echo " src/version.php tools/pharlite +#phpxmake -o "$OUT.phpx" index.php src vendor # copy raw phar into destination cp -v fresh.phar "$OUT.phar"