Skip to content

Commit

Permalink
fixed download
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Feb 19, 2025
1 parent f42def4 commit 23d3c39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

return Command::SUCCESS;
}
die('RESTORE FROM HERE');

$this->downloadVortex();

die('RESTORE FROM HERE');
$this->prepareDestination();

$this->replaceTokens();
Expand Down Expand Up @@ -311,7 +311,7 @@ protected function handleDemo(): void {

$command = sprintf('curl -s -L "%s" -o "%s/%s"', $url, $data_dir, $file);

if (!passthru($command)) {
if (passthru($command) === FALSE) {
throw new \RuntimeException(sprintf('Unable to download demo database from "%s".', $url));
}
}
Expand Down
26 changes: 10 additions & 16 deletions .vortex/installer/src/Utils/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@
*/
class Downloader {

protected string $tmpDir;

public function __construct() {
$this->tmpDir = File::tmpdir();
}

public function download(string $src, ?string $dst = NULL): string {
$dst = $dst ?? $this->tmpDir;

public function download(string $src, string $dst = NULL): string {
[$repo, $ref] = $this->parseUri($src);

if (str_starts_with($src, 'https://') || str_starts_with($src, 'git@')) {
Expand Down Expand Up @@ -72,18 +64,20 @@ public static function makeUri(string $repo, string $ref): string {
}

protected function downloadFromRemote(string $repo, string $ref, string $destination): void {
$repo_url = str_ends_with($repo, '.git') ? substr($repo, 0, -4) : $repo;

if ($ref == 'stable') {
$ref = $this->discoverLatestRelease($repo);
$ref = $this->discoverLatestRelease($repo_url);
}

$url = sprintf('%s/archive/%s.tar.gz', $repo, $ref);
$url = sprintf('%s/archive/%s.tar.gz', $repo_url, $ref);
$command = sprintf(
'curl -sS -L "%s" | tar xzf - -C "%s" --strip 1',
$url,
$destination
);

if (!passthru($command)) {
if (passthru($command) === FALSE) {
throw new RuntimeException(sprintf('Failed to download the remote archive: %s', $command));
}
}
Expand All @@ -97,14 +91,14 @@ protected function downloadFromLocal(string $repo, string $ref, string $destinat
$destination
);

if (!passthru($command)) {
if (passthru($command)=== FALSE) {
throw new RuntimeException(sprintf('Failed to download the local archive: %s', $command));
}
}

protected function discoverLatestRelease(string $repo, ?string $release_prefix = NULL): ?string {
$path = parse_url($repo, PHP_URL_PATH);
$path = str_ends_with($path, '.git') ? substr($path, 0, -4) : $path;
protected function discoverLatestRelease(string $repo_url, ?string $release_prefix = NULL): ?string {
$path = parse_url($repo_url, PHP_URL_PATH);
$path = ltrim($path, '/');

$release_url = sprintf('https://api.github.com/repos/%s/releases', $path);
$release_contents = file_get_contents($release_url, FALSE, stream_context_create([
Expand Down

0 comments on commit 23d3c39

Please sign in to comment.