Skip to content

Commit

Permalink
create directory from absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Adamczyk committed Jan 26, 2021
1 parent fabdbce commit f540ee6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 5 additions & 1 deletion common/src/main/kotlin/flank/common/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String>): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -37,7 +37,7 @@ private fun neededFilesListByOs(): List<String> = 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)
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
)
)
Expand All @@ -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")
)
)
Expand Down

0 comments on commit f540ee6

Please sign in to comment.