From 03e1369adcc8eba530c27a14b5d28cc11aafb859 Mon Sep 17 00:00:00 2001 From: Phoenix-Starlight <64714532+Phoenix-Starlight@users.noreply.github.com> Date: Thu, 3 Nov 2022 11:26:49 -0700 Subject: [PATCH] Patch download to work with symlinks (#736) * Fix Download to work with symlinks - Create SymlinkWalker * isPathSymbolic for whether any part of the path is symbolic, existing or not. * getRealPath for obtaining absolute, real path. - Change Download to use SymlinkWalker - Add in a new test for testing with symlinks * Refactor Switch to using Guava method for creating directories * Fix import * Alter test and fix arguments * Forgot a def * Fix method argument * Change argument to child file * Bump --- .../fabricmc/loom/util/download/Download.java | 4 +++- .../unit/download/DownloadFileTest.groovy | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/util/download/Download.java b/src/main/java/net/fabricmc/loom/util/download/Download.java index aa5da5b4..ad643bc7 100644 --- a/src/main/java/net/fabricmc/loom/util/download/Download.java +++ b/src/main/java/net/fabricmc/loom/util/download/Download.java @@ -24,6 +24,8 @@ package net.fabricmc.loom.util.download; +import static com.google.common.io.Files.createParentDirs; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -160,7 +162,7 @@ public class Download { } try { - Files.createDirectories(output.getParent()); + createParentDirs(output.toFile()); Files.deleteIfExists(output); } catch (IOException e) { throw error(e, "Failed to prepare path for download"); diff --git a/src/test/groovy/net/fabricmc/loom/test/unit/download/DownloadFileTest.groovy b/src/test/groovy/net/fabricmc/loom/test/unit/download/DownloadFileTest.groovy index 9b911b42..6d7a408b 100644 --- a/src/test/groovy/net/fabricmc/loom/test/unit/download/DownloadFileTest.groovy +++ b/src/test/groovy/net/fabricmc/loom/test/unit/download/DownloadFileTest.groovy @@ -30,13 +30,30 @@ import net.fabricmc.loom.util.download.Download import net.fabricmc.loom.util.download.DownloadException import net.fabricmc.loom.util.download.DownloadExecutor import net.fabricmc.loom.util.download.DownloadProgressListener - import java.nio.file.Files import java.nio.file.attribute.FileTime +import java.nio.file.Paths import java.time.Duration import java.time.Instant class DownloadFileTest extends DownloadTest { + def "Directory: Symlink"() { + setup: + server.get("/symlinkFile") { + it.result("Hello World") + } + def output = new File(File.createTempDir(), "file.txt").toPath() + def linkedtmp = new File(File.createTempDir(), "linkedtmp").toPath() + Files.createSymbolicLink(linkedtmp, output.getParent()) + def symlink = Paths.get(linkedtmp.toString(), "file.txt") + + when: + def result = Download.create("$PATH/symlinkFile").downloadPath(symlink) + + then: + Files.readString(symlink) == "Hello World" + } + def "File: Simple"() { setup: server.get("/simpleFile") {