From f540ee667b0797388fc5af8bfa94a877571d8219 Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Tue, 26 Jan 2021 21:09:38 +0100 Subject: [PATCH] create directory from absolute path --- common/src/main/kotlin/flank/common/Files.kt | 6 +++++- .../ftl/ios/xctest/common/InstallParseBinaries.kt | 13 +++---------- .../ios/xctest/common/InstallParseBinariesTest.kt | 7 +++---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/common/src/main/kotlin/flank/common/Files.kt b/common/src/main/kotlin/flank/common/Files.kt index 77d8936509..db771f53b7 100644 --- a/common/src/main/kotlin/flank/common/Files.kt +++ b/common/src/main/kotlin/flank/common/Files.kt @@ -13,6 +13,10 @@ val userHome: String by lazy { if (isWindows) System.getenv("HOMEPATH") else System.getProperty("user.home") } +val appDataDirectory: String by lazy { + if (isWindows) System.getenv("APPDATA") else System.getProperty("user.home") +} + fun linkFiles( link: String, target: String @@ -91,7 +95,7 @@ fun String.toFile(): File = Paths.get(this).toFile() fun String.deleteFile() = Paths.get(this).delete() fun createDirectoryIfNotExist(path: Path) { - if (Files.notExists(path)) path.toFile().mkdir() + if (Files.notExists(path)) Files.createDirectory(path) } fun File.hasAllFiles(fileList: List): Boolean { diff --git a/test_runner/src/main/kotlin/ftl/ios/xctest/common/InstallParseBinaries.kt b/test_runner/src/main/kotlin/ftl/ios/xctest/common/InstallParseBinaries.kt index 44940754e1..595b0dc2e2 100644 --- a/test_runner/src/main/kotlin/ftl/ios/xctest/common/InstallParseBinaries.kt +++ b/test_runner/src/main/kotlin/ftl/ios/xctest/common/InstallParseBinaries.kt @@ -1,6 +1,7 @@ package ftl.ios.xctest.common import flank.common.OutputLogLevel +import flank.common.appDataDirectory import flank.common.createDirectoryIfNotExist import flank.common.createSymbolicLinkToFile import flank.common.downloadFile @@ -9,7 +10,6 @@ import flank.common.isMacOS import flank.common.isWindows import flank.common.logLn import flank.common.unzipFile -import flank.common.userHome import java.nio.file.Files import java.nio.file.Paths @@ -37,7 +37,7 @@ private fun neededFilesListByOs(): List = if (isWindows) { listOf("nm", "swift-demangle", "libatomic.so.1", "libatomic.so.1.2.0") } -private val flankBinariesDirectory = Paths.get(userHome, ".flank") +private val flankBinariesDirectory = Paths.get(appDataDirectory, ".flank").toAbsolutePath() private fun downloadAndUnzip(osname: String) { createDirectoryIfNotExist(flankBinariesDirectory) @@ -47,19 +47,12 @@ private fun downloadAndUnzip(osname: String) { sourceUrl = "https://github.com/Flank/binaries/releases/download/$osname/binaries.zip", destinationPath = destinationFile ) - Files.walk(flankBinariesDirectory).forEach { - println("File ${it.fileName}") - } - createDirectoryIfNotExist(flankBinariesDirectory) - unzipFile(destinationFile.toFile().absoluteFile, flankBinariesDirectory.toAbsolutePath().toString()) + unzipFile(destinationFile.toFile().absoluteFile, flankBinariesDirectory.toString()) .forEach { logLn("Binary file $it copied to $flankBinariesDirectory", OutputLogLevel.DETAILED) it.setExecutable(true) } - Files.walk(flankBinariesDirectory).forEach { - println("File ${it.fileName}") - } Files.delete(destinationFile) createSymbolicLinkToFile( link = Paths.get(flankBinariesDirectory.toString(), "libatomic.so.1"), diff --git a/test_runner/src/test/kotlin/ftl/ios/xctest/common/InstallParseBinariesTest.kt b/test_runner/src/test/kotlin/ftl/ios/xctest/common/InstallParseBinariesTest.kt index 84e4bd9888..ed81c72e3f 100644 --- a/test_runner/src/test/kotlin/ftl/ios/xctest/common/InstallParseBinariesTest.kt +++ b/test_runner/src/test/kotlin/ftl/ios/xctest/common/InstallParseBinariesTest.kt @@ -1,9 +1,9 @@ package ftl.ios.xctest.common +import flank.common.appDataDirectory import flank.common.hasAllFiles import flank.common.isMacOS import flank.common.isWindows -import flank.common.userHome import org.junit.Assert.assertTrue import org.junit.Assume.assumeTrue import org.junit.Test @@ -15,14 +15,13 @@ internal class InstallParseBinariesTest { fun `should install binaries for windows`() { // given assumeTrue(isWindows) - println("FLANK USER PATH: $userHome") // when installBinaries // then assertTrue( - Paths.get(userHome, ".flank").toFile().hasAllFiles( + Paths.get(appDataDirectory, ".flank").toFile().hasAllFiles( listOf("libatomic.so.1", "libatomic.so.1.2.0") ) ) @@ -38,7 +37,7 @@ internal class InstallParseBinariesTest { // then assertTrue( - Paths.get(userHome, ".flank").toFile().hasAllFiles( + Paths.get(appDataDirectory, ".flank").toFile().hasAllFiles( listOf("nm", "swift-demangle", "libatomic.so.1", "libatomic.so.1.2.0") ) )