Skip to content

Commit b131448

Browse files
committed
fix: extracted binaries sometimes not being marked as executable
1 parent 769996c commit b131448

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/index.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function makeLoader(id: string, binaryName: string) {
4848

4949
interface InstallerMeta {
5050
repositoryId: string;
51+
binName: string;
5152
lookupLimit?: number;
5253
isWrappedDir?: boolean; // Wether archive contains files wrapped in a single directory
5354
}
@@ -68,15 +69,15 @@ function makeInstaller(id: string, meta: InstallerMeta) {
6869
/**
6970
* Usage:
7071
* ```
71-
* await installRelease('realesrgan', 'windows', utils);
72-
* await installRelease('realesrgan', 'macos', utils);
73-
* await installRelease('realesrgan', 'ubuntu|linux', utils);
72+
* await installRelease('realesrgan', 'windows', meta, utils);
73+
* await installRelease('realesrgan', 'macos', meta, utils);
74+
* await installRelease('realesrgan', 'ubuntu|linux', meta, utils);
7475
* ```
7576
*/
7677
async function installRelease(
7778
id: string,
7879
archiveSuffix: string,
79-
{repositoryId, lookupLimit = 10, isWrappedDir}: InstallerMeta,
80+
{repositoryId, binName, lookupLimit = 10, isWrappedDir}: InstallerMeta,
8081
{dataPath, tmpPath, download, extract, fetchJson, cleanup, progress, stage, log}: InstallUtils
8182
) {
8283
const dependencyDirectory = Path.join(dataPath, id);
@@ -174,6 +175,11 @@ async function installRelease(
174175
await FSP.rename(fromPath, toPath);
175176
}
176177

178+
stage(`ensuring binaries are executable`);
179+
const binPath = Path.join(dependencyDirectory, binName);
180+
log(`marking as executable: ${binPath}`);
181+
await FSP.chmod(binPath, 0o755);
182+
177183
/**
178184
* We need to write down the version manually, because the binary has no
179185
* API to describe itself.
@@ -905,14 +911,20 @@ const acceptsFlags = makeAcceptsFlags<Options>()({
905911
export type Payload = PayloadData<Options, typeof acceptsFlags>;
906912

907913
export default (plugin: Plugin) => {
914+
const waifu2xBinName = `waifu2x-ncnn-vulkan${process.platform === 'win32' ? '.exe' : ''}`;
908915
plugin.registerDependency('waifu2x', {
909-
load: makeLoader('waifu2x', `waifu2x-ncnn-vulkan${process.platform === 'win32' ? '.exe' : ''}`),
910-
install: makeInstaller('waifu2x', {repositoryId: 'nihui/waifu2x-ncnn-vulkan', isWrappedDir: true}),
916+
load: makeLoader('waifu2x', waifu2xBinName),
917+
install: makeInstaller('waifu2x', {
918+
repositoryId: 'nihui/waifu2x-ncnn-vulkan',
919+
binName: waifu2xBinName,
920+
isWrappedDir: true,
921+
}),
911922
});
912923

924+
const esrganBinName = `realesrgan-ncnn-vulkan${process.platform === 'win32' ? '.exe' : ''}`;
913925
plugin.registerDependency('realesrgan', {
914-
load: makeLoader('realesrgan', `realesrgan-ncnn-vulkan${process.platform === 'win32' ? '.exe' : ''}`),
915-
install: makeInstaller('realesrgan', {repositoryId: 'xinntao/Real-ESRGAN'}),
926+
load: makeLoader('realesrgan', esrganBinName),
927+
install: makeInstaller('realesrgan', {repositoryId: 'xinntao/Real-ESRGAN', binName: esrganBinName}),
916928
});
917929

918930
plugin.registerProcessor<Payload>('upscale', {

0 commit comments

Comments
 (0)