Skip to content

Commit f6b7f80

Browse files
authored
Merge pull request #28: Hotfixes
2 parents cad237e + ce15726 commit f6b7f80

File tree

9 files changed

+241
-345
lines changed

9 files changed

+241
-345
lines changed

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,27 @@ DLoad handles both binary executables and regular files:
159159
</software>
160160
```
161161

162+
### Automatic Binary Downloads with Composer Update
163+
164+
Integrate DLoad with Composer to automatically download required binaries whenever dependencies are updated.
165+
This ensures your team always has the necessary tools without manual intervention.
166+
167+
Add the following to your `composer.json`:
168+
169+
```json
170+
{
171+
"scripts": {
172+
"post-update-cmd": "dload get --no-interaction -v",
173+
"get:binaries": "dload get --no-interaction --force -vv"
174+
}
175+
}
176+
```
177+
178+
This configuration:
179+
180+
- Automatically downloads required binaries after `composer update`
181+
- Provides a custom command `composer get:binaries` to force download all binaries with detailed output
182+
162183
## Custom Software Registry
163184

164185
### Defining Custom Software

psalm-baseline.xml

-13
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@
6767
<MoreSpecificReturnType>
6868
<code><![CDATA[non-empty-string]]></code>
6969
</MoreSpecificReturnType>
70-
<PossiblyNullReference>
71-
<code><![CDATA[getPathname]]></code>
72-
</PossiblyNullReference>
7370
</file>
7471
<file src="src/Module/Archive/ArchiveFactory.php">
7572
<MixedPropertyTypeCoercion>
@@ -113,16 +110,6 @@
113110
<code><![CDATA[$output]]></code>
114111
</MixedArgumentTypeCoercion>
115112
</file>
116-
<file src="src/Module/Binary/Internal/VersionComparator.php">
117-
<PossiblyNullArgument>
118-
<code><![CDATA[$versionOnly]]></code>
119-
<code><![CDATA[\preg_replace('/[-+].*$/', '', $constraint)]]></code>
120-
</PossiblyNullArgument>
121-
<RedundantCondition>
122-
<code><![CDATA[!$hasPreB]]></code>
123-
<code><![CDATA[$bIsNum]]></code>
124-
</RedundantCondition>
125-
</file>
126113
<file src="src/Module/Common/Config/Action/Download.php">
127114
<MissingConstructor>
128115
<code><![CDATA[$software]]></code>

resources/software.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
],
5151
"binary": {
5252
"name": "dolt",
53-
"version-command": "--version"
53+
"version-command": "version"
5454
}
5555
},
5656
{
@@ -137,4 +137,4 @@
137137
}
138138
}
139139
]
140-
}
140+
}

src/DLoad.php

+41-18
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,46 @@ public function addTask(DownloadConfig $action, bool $force = false): void
7777
// Check different constraints
7878
$binary = $this->binaryProvider->getBinary($destinationPath, $software->binary);
7979

80+
if ($binary === null) {
81+
goto add_task;
82+
}
83+
84+
\assert($binary !== null);
85+
$version = $binary->getVersion();
86+
if ($action->version === null) {
87+
$this->logger->info(
88+
'Binary `%s` exists with version `%s`, but no version constraint specified. Skipping download.',
89+
$binary->getName(),
90+
$version ?? 'unknown',
91+
);
92+
$this->logger->info('Use flag `--force` to force download.');
93+
94+
// Skip task creation entirely
95+
return;
96+
}
97+
8098
// Check if binary exists and satisfies version constraint
81-
if ($binary !== null && ($version = $binary->getVersion()) !== null) {
82-
if ($action->version !== null && $binary->satisfiesVersion($action->version)) {
83-
$this->logger->info(
84-
'Binary `%s` exists with version `%s`, satisfies constraint `%s`. Skipping download. Use `--force` to override.',
85-
$binary->getName(),
86-
(string) $binary->getVersion(),
87-
$action->version,
88-
);
89-
90-
// Skip task creation entirely
91-
return;
92-
}
99+
if ($binary->satisfiesVersion($action->version)) {
100+
$this->logger->info(
101+
'Binary `%s` exists with version `%s`, satisfies constraint `%s`. Skipping download.',
102+
$binary->getName(),
103+
(string) $binary->getVersion(),
104+
$action->version,
105+
);
106+
$this->logger->info('Use flag `--force` to force download.');
93107

94-
// Download a newer version only if version is specified
95-
if ($version) {
96-
// todo
97-
}
108+
// Skip task creation entirely
109+
return;
110+
}
111+
112+
// Download a newer version only if version is specified
113+
if ($version !== null) {
114+
// todo
98115
}
99116
}
100117

118+
add_task:
119+
101120
$this->taskManager->addTask(function () use ($software, $action): void {
102121
// Create a Download task
103122
$task = $this->prepareDownloadTask($software, $action);
@@ -175,7 +194,11 @@ private function prepareExtractTask(Software $software, DownloadConfig $action):
175194

176195
$to = $this->shouldBeExtracted($file, $files, $action);
177196

178-
$overwrite = \is_file($to->getPathname());
197+
if ($to === null) {
198+
$extractor->next();
199+
continue;
200+
}
201+
179202
$extractor->send($to);
180203

181204
// Success
@@ -185,7 +208,7 @@ private function prepareExtractTask(Software $software, DownloadConfig $action):
185208
'%s (<comment>%s</comment>) has been installed%s into <info>%s</info>',
186209
$to->getFilename(),
187210
$downloadResult->version,
188-
$overwrite ? ' (overwriting)' : '',
211+
$to->isFile() ? ' (overwriting)' : '',
189212
$path,
190213
),
191214
);

src/Module/Binary/Internal/BinaryHandle.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Internal\DLoad\Module\Binary\Internal;
66

7+
use Composer\Semver\Semver;
78
use Internal\DLoad\Module\Binary\Binary;
89
use Internal\DLoad\Module\Common\Config\Embed\Binary as BinaryConfig;
910
use Internal\DLoad\Module\Common\FileSystem\Path;
@@ -23,15 +24,13 @@ final class BinaryHandle implements Binary
2324
* @param BinaryConfig $config Original configuration
2425
* @param BinaryExecutor $executor Binary execution service
2526
* @param VersionResolver $versionResolver Version extraction service
26-
* @param VersionComparator $versionComparator Version comparison service
2727
*/
2828
public function __construct(
2929
private readonly string $name,
3030
private readonly Path $path,
3131
private readonly BinaryConfig $config,
3232
private readonly BinaryExecutor $executor,
3333
private readonly VersionResolver $versionResolver,
34-
private readonly VersionComparator $versionComparator,
3534
) {}
3635

3736
public function getName(): string
@@ -77,7 +76,7 @@ public function satisfiesVersion(string $versionConstraint): ?bool
7776
$version = $this->getVersion();
7877
return $version === null
7978
? null
80-
: $this->versionComparator->satisfies($version, $versionConstraint);
79+
: Semver::satisfies($version, $versionConstraint);
8180
}
8281

8382
public function getSize(): ?int

src/Module/Binary/Internal/BinaryProviderImpl.php

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public function __construct(
2121
private readonly OperatingSystem $operatingSystem,
2222
private readonly BinaryExecutor $executor,
2323
private readonly VersionResolver $versionResolver,
24-
private readonly VersionComparator $versionComparator,
2524
) {}
2625

2726
public function getBinary(Path|string $destinationPath, BinaryConfig $config): ?Binary
@@ -36,7 +35,6 @@ public function getBinary(Path|string $destinationPath, BinaryConfig $config): ?
3635
config: $config,
3736
executor: $this->executor,
3837
versionResolver: $this->versionResolver,
39-
versionComparator: $this->versionComparator,
4038
);
4139

4240
// Return binary only if it exists

0 commit comments

Comments
 (0)