private void createHardlink()

in plugins/sandbox/src/main/java/co/elastic/gradle/sandbox/SandboxExecBaseTask.java [369:391]


    private void createHardlink(Path source, Path destination) {
        if (Files.exists(destination)) {
            try {
                Files.delete(destination);
            } catch (IOException e) {
                throw new UncheckedIOException("Can't remove existing file " + destination, e);
            }
        }
        try {
            Files.createDirectories(destination.getParent());
        } catch (IOException e) {
            throw new UncheckedIOException("Can't create directory " + destination.getParent(), e);
        }
        try {
            Files.createLink(destination, source);
        } catch (IOException e) {
            // Note does not work for network drives, e.g. Vagrant
            throw new UncheckedIOException(
                    "Failed to create hard link " + destination + " pointing to " + source,
                    e
            );
        }
    }