Fix symlink/override issues

@see https://www.filebot.net/forums/viewtopic.php?f=6&t=5352
This commit is contained in:
Reinhard Pointner 2017-09-28 12:21:29 +02:00
parent cc9d823d78
commit 39e4dcebc2
1 changed files with 4 additions and 6 deletions

View File

@ -25,6 +25,7 @@ import java.nio.file.AtomicMoveNotSupportedException;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
@ -120,14 +121,11 @@ public final class FileUtilities {
public static File createRelativeSymlink(File link, File target, boolean relativize) throws IOException {
if (relativize) {
// make sure we're working with the full path
link = link.getCanonicalFile();
target = target.getCanonicalFile();
// make sure we're working with the correct full path of the file or link
try {
target = link.getParentFile().toPath().relativize(target.toPath()).toFile();
target = link.toPath().getParent().toRealPath(LinkOption.NOFOLLOW_LINKS).relativize(target.toPath()).toFile();
} catch (Throwable e) {
// unable to relativize link target
log.warning(cause("Unable to relativize link target", e));
}
}