From f8107753a9a850bb86a2a8d07c71de082ea7a2c5 Mon Sep 17 00:00:00 2001 From: kitsunyan Date: Sat, 19 May 2018 08:41:50 +0300 Subject: Clone AUR repos without tags to user cache --- src/common.nim | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/common.nim b/src/common.nim index eb973c5..62966ee 100644 --- a/src/common.nim +++ b/src/common.nim @@ -8,7 +8,7 @@ type repositories BareKind* {.pure.} = enum - repo + pkg, repo SyncFoundPackageInfo* = tuple[ base: string, @@ -625,19 +625,42 @@ proc cloneAurRepo*(config: Config, base: string, gitUrl: string, dropPrivileges: bool): (int, Option[string]) = let repoPath = repoPath(config.tmpRoot(dropPrivileges), base) - let message = ensureTmpOrError(config, dropPrivileges) + let message = block: + let message = ensureUserCacheOrError(config, CacheKind.repositories, dropPrivileges) + if message.isNone: + ensureTmpOrError(config, dropPrivileges) + else: + message + if message.isSome: (1, message) elif repoPath.existsDir(): (0, none(string)) else: - let cloneCode = forkWait(() => (block: + let fullName = bareFullName(BareKind.pkg, base) + let cachePath = config.userCache(dropPrivileges).cache(CacheKind.repositories) + let bareRepoPath = repoPath(cachePath, fullName) + + let cloneBareCode = forkWait(() => (block: if not dropPrivileges or dropPrivileges(): - execResult(gitCmd, "-C", config.tmpRoot(dropPrivileges), - "clone", "-q", gitUrl, "--single-branch", base) + if existsDir(bareRepoPath): + execResult(gitCmd, "-C", bareRepoPath, "fetch", "-q", "--no-tags") + else: + execResult(gitCmd, "-C", cachePath, "clone", "-q", "--bare", "--no-tags", + gitUrl, "--single-branch", fullName) else: quit(1))) + let cloneCode = if cloneBareCode == 0: + forkWait(() => (block: + if not dropPrivileges or dropPrivileges(): + execResult(gitCmd, "-C", config.tmpRoot(dropPrivileges), + "clone", "-q", bareRepoPath, "--single-branch", base) + else: + quit(1))) + else: + cloneBareCode + if cloneCode != 0: (cloneCode, some(tr"$#: failed to clone git repository" % [base])) else: -- cgit v1.2.3-70-g09d2