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-16918][Task] Fix wrong permissions configuration while executing shell #16923

Merged
merged 12 commits into from
Jan 8, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.nio.file.attribute.UserPrincipal;
import java.nio.file.attribute.UserPrincipalLookupService;
import java.util.Optional;
import java.util.Set;
import java.util.zip.CRC32;
Expand Down Expand Up @@ -272,6 +271,12 @@ public static void createDirectoryWith755(@NonNull Path path) throws IOException
}
}

public static Path setOwner(@NonNull Path path, @NonNull String owner) throws IOException {
UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
UserPrincipal user = lookupService.lookupPrincipalByName(owner);
return Files.setOwner(path, user);
BruceWong96 marked this conversation as resolved.
Show resolved Hide resolved
}

public static void setFileTo755(File file) throws IOException {
if (OSUtils.isWindows()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

Expand All @@ -51,6 +52,9 @@ public static void createTaskInstanceWorkingDirectory(TaskExecutionContext taskE
taskInstanceWorkingDirectory);
}
FileUtils.createDirectoryWith755(Paths.get(taskInstanceWorkingDirectory));
final Path taskInstanceWorkingDirectoryPath = Paths.get(taskInstanceWorkingDirectory);
SbloodyS marked this conversation as resolved.
Show resolved Hide resolved
FileUtils.createDirectoryWith755(taskInstanceWorkingDirectoryPath);
FileUtils.setOwner(taskInstanceWorkingDirectoryPath, taskExecutionContext.getTenantCode());

taskExecutionContext.setExecutePath(taskInstanceWorkingDirectory);
taskExecutionContext.setAppInfoPath(FileUtils.getAppInfoPath(taskInstanceWorkingDirectory));
Expand Down
Loading