|
|
@ -25,8 +25,6 @@ import static org.apache.dolphinscheduler.common.constants.Constants.RESOURCE_VI |
|
|
|
import static org.apache.dolphinscheduler.common.constants.Constants.UTF_8; |
|
|
|
import static org.apache.dolphinscheduler.common.constants.Constants.UTF_8; |
|
|
|
import static org.apache.dolphinscheduler.common.constants.DateConstants.YYYYMMDDHHMMSS; |
|
|
|
import static org.apache.dolphinscheduler.common.constants.DateConstants.YYYYMMDDHHMMSS; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.constants.TenantConstants; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
import org.apache.commons.lang3.SystemUtils; |
|
|
|
import org.apache.commons.lang3.SystemUtils; |
|
|
|
|
|
|
|
|
|
|
@ -37,15 +35,12 @@ import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.file.FileSystems; |
|
|
|
|
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.nio.file.NoSuchFileException; |
|
|
|
import java.nio.file.NoSuchFileException; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.nio.file.attribute.FileAttribute; |
|
|
|
import java.nio.file.attribute.FileAttribute; |
|
|
|
import java.nio.file.attribute.PosixFilePermission; |
|
|
|
import java.nio.file.attribute.PosixFilePermission; |
|
|
|
import java.nio.file.attribute.PosixFilePermissions; |
|
|
|
import java.nio.file.attribute.PosixFilePermissions; |
|
|
|
import java.nio.file.attribute.UserPrincipal; |
|
|
|
|
|
|
|
import java.nio.file.attribute.UserPrincipalLookupService; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.zip.CRC32; |
|
|
|
import java.util.zip.CRC32; |
|
|
|
import java.util.zip.CheckedInputStream; |
|
|
|
import java.util.zip.CheckedInputStream; |
|
|
@ -328,19 +323,23 @@ public class FileUtils { |
|
|
|
return crcString; |
|
|
|
return crcString; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void setFileOwner(Path path, String tenant) { |
|
|
|
public static void setFileOwner(Path filePath, String fileOwner) throws InterruptedException, IOException { |
|
|
|
try { |
|
|
|
// We use linux command to set the file owner, since jdk api will not use sudo.
|
|
|
|
if (TenantConstants.DEFAULT_TENANT_CODE.equals(tenant)) { |
|
|
|
String command = String.format("sudo chown %s %s", fileOwner, filePath.toString()); |
|
|
|
log.debug("The current tenant: {} is the default tenant, no need to set the owner for file: {}", tenant, |
|
|
|
Runtime.getRuntime().exec(command); |
|
|
|
path); |
|
|
|
Process process = Runtime.getRuntime().exec(command); |
|
|
|
return; |
|
|
|
if (0 != process.waitFor()) { |
|
|
|
} |
|
|
|
throw new RuntimeException("Set file: " + filePath + " to owner: " + fileOwner + " failed"); |
|
|
|
UserPrincipalLookupService userPrincipalLookupService = |
|
|
|
} |
|
|
|
FileSystems.getDefault().getUserPrincipalLookupService(); |
|
|
|
} |
|
|
|
UserPrincipal tenantPrincipal = userPrincipalLookupService.lookupPrincipalByName(tenant); |
|
|
|
|
|
|
|
Files.setOwner(path, tenantPrincipal); |
|
|
|
public static void setDirectoryOwner(Path filePath, String fileOwner) throws IOException, InterruptedException { |
|
|
|
} catch (IOException e) { |
|
|
|
// We use linux command to set the file owner, since jdk api will not use sudo.
|
|
|
|
log.error("Set file: {} owner to: {} failed", path, tenant, e); |
|
|
|
String command = String.format("sudo chown -R %s %s", fileOwner, filePath.toString()); |
|
|
|
|
|
|
|
Runtime.getRuntime().exec(command); |
|
|
|
|
|
|
|
Process process = Runtime.getRuntime().exec(command); |
|
|
|
|
|
|
|
if (0 != process.waitFor()) { |
|
|
|
|
|
|
|
throw new RuntimeException("Set directory: " + filePath + " to owner: " + fileOwner + " failed"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|