in bigtop-manager-stack/bigtop-manager-stack-core/src/main/java/org/apache/bigtop/manager/stack/core/utils/linux/LinuxFileUtils.java [308:336]
public static void createSymbolicLink(String target, String source) {
if (StringUtils.isBlank(target) || StringUtils.isBlank(source)) {
log.error("target, source must not be null");
return;
}
Path targetPath = Paths.get(target);
Path sourcePath = Paths.get(source);
try {
log.info("Creating symbolic link: [{}] -> [{}]", target, source);
if (Files.exists(targetPath)) {
if (Files.isSymbolicLink(targetPath)) {
Path existingSourcePath = Files.readSymbolicLink(targetPath);
if (!existingSourcePath.equals(sourcePath)) {
throw new IOException(
"Symbolic link already exists and points to a different source: " + existingSourcePath);
}
} else {
throw new IOException("Target path exists and is not a symbolic link: " + target);
}
}
Files.createSymbolicLink(targetPath, sourcePath);
} catch (IOException e) {
log.error("Error when create symbolic link", e);
throw new StackException(e);
}
}