* 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`.
- 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.

View File

@ -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

View File

@ -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");

View File

@ -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,

View File

@ -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;
}
}
}

View File

@ -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 "<?php define(\"APP_VERSION\", \"${TAG}\"); define(\"BUILD_DATE\", \"${NOW}\");" > src/version.php
tools/pharlite
#phpxmake -o "$OUT.phpx" index.php src vendor
# copy raw phar into destination
cp -v fresh.phar "$OUT.phar"