Skip to content

Commit

Permalink
fix: wrong permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Oct 12, 2023
1 parent 478f06d commit 0bc9de6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/cli/tools/dart/index.ts
Expand Up @@ -45,7 +45,7 @@ export class PrepareDartService extends PrepareToolBaseService {
this.envSvc.userName,
`${this.envSvc.userHome}/.dart`,
]);
await execa('chmod', ['-R', 'g=u', `${this.envSvc.userHome}/.dart`]);
await execa('chmod', ['-R', 'g+w', `${this.envSvc.userHome}/.dart`]);
}
}

Expand Down
41 changes: 22 additions & 19 deletions src/cli/tools/dotnet/index.ts
@@ -1,4 +1,4 @@
import { chmod, chown, mkdir } from 'node:fs/promises';
import fs from 'node:fs/promises';
import { join } from 'node:path';
import { execa } from 'execa';
import { inject, injectable } from 'inversify';
Expand Down Expand Up @@ -60,9 +60,10 @@ export class PrepareDotnetService extends PrepareToolBaseService {
});

const nuget = join(this.envSvc.userHome, '.nuget');
await mkdir(nuget);
await chown(nuget, this.envSvc.userId, 0);
await chmod(nuget, 0o775);
await fs.mkdir(join(nuget, 'NuGet'), { recursive: true });
// fs isn't recursive, so we use system binaries
await execa('chown', ['-R', this.envSvc.userName, nuget]);
await execa('chmod', ['-R', 'g+w', nuget]);
}
}

Expand Down Expand Up @@ -120,44 +121,46 @@ export class InstallDotnetService extends InstallToolBaseService {
';',
]);
}
}

override async link(version: string): Promise<void> {
const src = this.pathSvc.toolPath(this.name);
await this.shellwrapper({ srcDir: src });

await execa('dotnet', ['new']);
const dotnet = join(toolPath, 'dotnet');
await execa(dotnet, ['new']);
if (this.envSvc.isRoot) {
await execa('su', [this.envSvc.userName, '-c', 'dotnet new']);
await execa('su', [this.envSvc.userName, '-c', `${dotnet} new`]);
}

const ver = parse(version);
// command available since net core 3.1
// https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-list-source
if (ver.major > 3 || (ver.major === 3 && ver.minor >= 1)) {
// See https://github.com/NuGet/Home/issues/11607
await execa('dotnet', ['nuget', 'list', 'source']);
await execa(dotnet, ['nuget', 'list', 'source']);
if (this.envSvc.isRoot) {
await execa('su', [
this.envSvc.userName,
'-c',
'dotnet nuget list source',
`${dotnet} nuget list source`,
]);
}
}
const nuget = join(
this.envSvc.userHome,
'.config',
'NuGet',
'NuGet.Config',
);
const nuget = join(this.envSvc.userHome, '.nuget', 'NuGet', 'NuGet.Config');
if (await this.pathSvc.fileExists(nuget)) {
await this.pathSvc.setOwner({
file: join(this.envSvc.userHome, '.nuget'),
});
await this.pathSvc.setOwner({
file: join(this.envSvc.userHome, '.nuget', 'NuGet'),
});
await this.pathSvc.setOwner({
file: nuget,
});
}
}

override async link(_version: string): Promise<void> {
const src = this.pathSvc.toolPath(this.name);
await this.shellwrapper({ srcDir: src });
}

override async test(_version: string): Promise<void> {
await execa('dotnet', ['--info'], { stdio: ['inherit', 'inherit', 1] });
}
Expand Down
2 changes: 2 additions & 0 deletions test/dotnet/Dockerfile
Expand Up @@ -26,6 +26,8 @@ FROM base as net3
RUN install-tool dotnet 3.1.426
RUN set -ex; dotnet --version | grep 3.1.

RUN ls -la $USER_HOME/.nuget/NuGet

USER 1000

RUN dotnet --info
Expand Down

0 comments on commit 0bc9de6

Please sign in to comment.