Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use chmod #40

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions src/post/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function stopKnoxctlScan(): void {
try {
process.kill(Number(pid), "SIGINT");
log("Sent SIGINT signal to knoxctl scan process");
setTimeout(() => {
setTimeout(async () => {
try {
process.kill(Number(pid), 0);
log("Process is still running. Attempting to force kill...");
Expand All @@ -114,23 +114,29 @@ function stopKnoxctlScan(): void {
fs.unlinkSync(pidFile);
log("Removed PID file");

// Change ownership of output files
// Change permissions of output files
const outputDir = getOutputDir();
exec
.exec("sudo", [
"sh",
"-c",
`chown -R $(id -u):$(id -g) "${outputDir}"`,
])
.then(() => {
log("Changed ownership of output files");
})
.catch((error) => {
log(
`Failed to change ownership of output files: ${error instanceof Error ? error.message : String(error)}`,
"warning",
);
});
log(`Attempting to change permissions of files in: ${outputDir}`);
try {
await exec.exec("sudo", ["chmod", "-R", "644", outputDir]);
log("Changed permissions of output files");

// List directory contents to verify
const { stdout, stderr } = await exec.getExecOutput("ls", [
"-l",
outputDir,
]);
log("Directory contents after permission change:");
log(stdout);
if (stderr) {
log(`stderr: ${stderr}`, "warning");
}
} catch (error) {
log(
`Failed to change permissions of output files: ${error instanceof Error ? error.message : String(error)}`,
"error",
);
}
}, 5000);
} catch (error) {
log(
Expand Down Expand Up @@ -226,10 +232,10 @@ async function processResults(): Promise<void> {

async function run(): Promise<void> {
try {
stopKnoxctlScan();

// Increase wait time and add file system sync
await new Promise((resolve) => setTimeout(resolve, 15000));
await new Promise<void>((resolve) => {
stopKnoxctlScan();
setTimeout(resolve, 10000);
});

const outputDir = getOutputDir();
log(`Output directory: ${outputDir}`);
Expand Down
Loading