From c6010b0ae78b530a1c1ce1325944cf3cd899f9ce Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Mon, 15 Jan 2024 16:38:04 +0300 Subject: [PATCH] support sui git paths (#129) Co-authored-by: qingfengzs --- .../org/move/cli/manifest/TomlDependency.kt | 24 +++++++++++++++---- .../kotlin/org/move/utils/tests/FileTree.kt | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/move/cli/manifest/TomlDependency.kt b/src/main/kotlin/org/move/cli/manifest/TomlDependency.kt index 04801702d..936ccb666 100644 --- a/src/main/kotlin/org/move/cli/manifest/TomlDependency.kt +++ b/src/main/kotlin/org/move/cli/manifest/TomlDependency.kt @@ -1,5 +1,6 @@ package org.move.cli.manifest +import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths @@ -24,15 +25,28 @@ sealed class TomlDependency { override fun localPath(): Path { val home = System.getProperty("user.home") - val dirName = dirName(repo, rev) - return Paths.get(home, ".move", dirName, subdir) + // TODO: add choice based on selected blockchain + val dirNameAptos = dirNameAptos(repo, rev) + val aptosPath = Paths.get(home, ".move", dirNameAptos, subdir) + if (Files.exists(aptosPath)) { + return aptosPath + } else { + val dirNameSui = dirNameSui(repo, rev) + val suiPath = Paths.get(home, ".move", dirNameSui, subdir) + return suiPath + } } companion object { - fun dirName(repo: String, rev: String): String { + fun dirNameAptos(repo: String, rev: String): String { + val sanitizedRepoName = repo.replace(Regex("[/:.@]"), "_") + val aptosRevName = rev.replace("/", "_") + return "${sanitizedRepoName}_$aptosRevName" + } + fun dirNameSui(repo: String, rev: String): String { val sanitizedRepoName = repo.replace(Regex("[/:.@]"), "_") - val revName = rev.replace('/', '_') - return "${sanitizedRepoName}_$revName" + val suiRevName = rev.replace("/", "__") + return "${sanitizedRepoName}_$suiRevName" } } } diff --git a/src/main/kotlin/org/move/utils/tests/FileTree.kt b/src/main/kotlin/org/move/utils/tests/FileTree.kt index bdca81dc0..fc76e51ca 100644 --- a/src/main/kotlin/org/move/utils/tests/FileTree.kt +++ b/src/main/kotlin/org/move/utils/tests/FileTree.kt @@ -84,7 +84,7 @@ interface FileTreeBuilder { ) fun git(repo: String, rev: String, builder: TreeBuilder = {}) { - val dirName = TomlDependency.Git.dirName(repo, rev) + val dirName = TomlDependency.Git.dirNameAptos(repo, rev) return dir(dirName, builder) }