* Fixed a bug where the lockfile would be released on exit even if
  it wasn't locked by the process
* Disabled the phpx build as it is broken
This commit is contained in:
Chris 2022-07-05 22:46:11 +02:00
parent 879bf88864
commit 88f3b75383
6 changed files with 34 additions and 13 deletions

View File

@ -27,3 +27,8 @@
- Renamed the lock file from `fresh.lock` to `.fresh.lock`. - Renamed the lock file from `fresh.lock` to `.fresh.lock`.
- Added option `--lockfile` to override lockfile file name. - Added option `--lockfile` to override lockfile file name.
- Implemented the fresh configuration loader. - 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.

View File

@ -19,7 +19,8 @@ a light-weight easy-to-use alternative to more complex toolkits.
Fresh requires **PHP 8.0** or later. Fresh requires **PHP 8.0** or later.
Download the latest version (or build it yourself) and move it into `/usr/bin`. 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 ### Building

View File

@ -198,6 +198,8 @@ class Refresher
$this->setupConfiguration(); $this->setupConfiguration();
$this->setupHooks(); $this->setupHooks();
$this->lockfile->lock();
$updated = $this->checkUpdates(); $updated = $this->checkUpdates();
// If called with --check, only return exit status // If called with --check, only return exit status
@ -217,7 +219,7 @@ class Refresher
$this->callHooks($updated, 'after'); $this->callHooks($updated, 'after');
$this->callScript('after'); $this->callScript('after');
} }
$this->lockfile->release();
exit(($updated === null) ? 0 : 1); exit(($updated === null) ? 0 : 1);
} catch (\Throwable $t) { } catch (\Throwable $t) {
@ -226,6 +228,7 @@ class Refresher
if (!$this->options['verbose']) { if (!$this->options['verbose']) {
fprintf(STDERR, $this->log->asString()."\n"); fprintf(STDERR, $this->log->asString()."\n");
} }
$this->lockfile->release();
exit(2); exit(2);
} }
@ -253,6 +256,8 @@ class Refresher
$lockfile = $this->options['lockfile']; $lockfile = $this->options['lockfile'];
if (!str_starts_with($lockfile,'/')) $lockfile = $this->path . "/" . $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->state = new PersistentState($statefile); // $this->path . "/" . self::$StateFileName);
$this->lockfile = new Lockfile($lockfile); // $this->path . "/" . self::$LockFileName); $this->lockfile = new Lockfile($lockfile); // $this->path . "/" . self::$LockFileName);
} }
@ -359,8 +364,6 @@ class Refresher
private function checkUpdates(): ?array private function checkUpdates(): ?array
{ {
$this->lockfile->lock();
$checks = $this->config->getChecks(); $checks = $this->config->getChecks();
if (count($checks) === 0) { if (count($checks) === 0) {
fwrite(STDERR, "error: couldn't find any images to check\n"); fwrite(STDERR, "error: couldn't find any images to check\n");

View File

@ -23,7 +23,11 @@ class RegistryV2Client
public function getManifest(string $image, string $tag) 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(); $body = $response->getBody();
return json_decode($body); return json_decode($body);
} }
@ -32,12 +36,16 @@ class RegistryV2Client
{ {
$manifest = $this->getManifest($image, $tag); $manifest = $this->getManifest($image, $tag);
$fslayers = (array)$manifest->fsLayers; //print_r($manifest);
$fshashes = array_map(fn($layer) => $layer->blobSum, $fslayers);
$fslayers = (array)(($manifest->fsLayers??$manifest->layers)??[]);
$fshashes = array_map(fn($layer) => $layer->blobSum??$layer->digest, $fslayers);
$metahash = hash("sha256", join("|", $fshashes)); $metahash = hash("sha256", join("|", $fshashes));
if (isset($manifest->history)) {
$history = $manifest->history[0]; $history = $manifest->history[0];
$info = json_decode($history->v1Compatibility); $info = json_decode($history->v1Compatibility);
}
return [ return [
'image' => $image, 'image' => $image,

View File

@ -8,6 +8,8 @@ class Lockfile
private int $maxLock = 3600; private int $maxLock = 3600;
private bool $locked = false;
public function __construct(string $filename) public function __construct(string $filename)
{ {
$this->filename = $filename; $this->filename = $filename;
@ -22,14 +24,15 @@ class Lockfile
} }
} }
touch($this->filename); touch($this->filename);
$this->locked = true;
} }
public function release() public function release()
{ {
if (file_exists($this->filename)) { if ($this->locked && file_exists($this->filename)) {
unlink($this->filename); unlink($this->filename);
} }
$this->locked = false;
} }

View File

@ -14,6 +14,7 @@ mkdir -p dist
# update version.php and build the phar # update version.php and build the phar
echo "<?php define(\"APP_VERSION\", \"${TAG}\"); define(\"BUILD_DATE\", \"${NOW}\");" > src/version.php echo "<?php define(\"APP_VERSION\", \"${TAG}\"); define(\"BUILD_DATE\", \"${NOW}\");" > src/version.php
tools/pharlite tools/pharlite
#phpxmake -o "$OUT.phpx" index.php src vendor
# copy raw phar into destination # copy raw phar into destination
cp -v fresh.phar "$OUT.phar" cp -v fresh.phar "$OUT.phar"