aboutsummaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorkitsunyan2018-06-06 23:35:28 +0000
committerkitsunyan2018-06-06 23:35:28 +0000
commitf227d1088f6a8aee3654804b5fd0110e15532c5b (patch)
tree1b865f5437417a716b281e27cb69dfa8c47e8189 /src/feature
parentc5a91071172e206b5d02bed66e893469bde17629 (diff)
Add support for "-Sc" to clean package repositories
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/syncclean.nim51
-rw-r--r--src/feature/syncinstall.nim7
2 files changed, 52 insertions, 6 deletions
diff --git a/src/feature/syncclean.nim b/src/feature/syncclean.nim
new file mode 100644
index 0000000..2e57908
--- /dev/null
+++ b/src/feature/syncclean.nim
@@ -0,0 +1,51 @@
+import
+ future, options, os, posix, sequtils, strutils, tables,
+ "../args", "../aur", "../common", "../config", "../format", "../lists",
+ "../package", "../pacman", "../utils",
+ "../wrapper/alpm"
+
+proc handleSyncClean*(args: seq[Argument], config: Config): int =
+ let code = pacmanRun(true, config.color, args)
+ if code != 0:
+ code
+ else:
+ let cleanCount = args.count(%%%"clean")
+ let noconfirm = args.noconfirm
+
+ let reposCacheDir = config.userCacheCurrent.cache(CacheKind.repositories)
+ let homeDir = currentUser.home
+ let printReposCacheDir = if reposCacheDir.find(homeDir & "/") == 0:
+ '~' & reposCacheDir[homeDir.len .. ^1]
+ else:
+ reposCacheDir
+ echo()
+ echo(tr"Repositories directory: $#" % [printReposCacheDir])
+
+ if (cleanCount == 1 and
+ printColonUserChoice(config.color, tr"Do you want to remove unused repositories?",
+ ['y', 'n'], 'y', 'n', noconfirm, 'y') == 'y') or
+ (cleanCount >= 2 and
+ printColonUserChoice(config.color, tr"Do you want to remove ALL repositories?",
+ ['y', 'n'], 'n', 'n', noconfirm, 'n') == 'y'):
+ if cleanCount == 1:
+ echo(tr"removing unused package repositories...")
+ else:
+ echo(tr"removing all package repositories...")
+
+ if existsDir(reposCacheDir):
+ withAlpmConfig(config, false, handle, dbs, errors):
+ for e in errors: printError(config.color, e)
+
+ let local = handle.local
+ for file in walkDir(reposCacheDir):
+ if file.kind == pcDir:
+ let index = file.path.rfind('/')
+ let dirName = if index >= 0: file.path[index + 1 .. ^1] else: file.path
+ for name in bareFullNameDeconstruct(BareKind.pkg, dirName):
+ if cleanCount >= 2 or local[name] == nil:
+ removeDirQuiet(file.path)
+
+ discard rmdir(reposCacheDir)
+ discard rmdir(config.userCacheCurrent)
+
+ 0
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index 1ca1083..7d638cc 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -1324,12 +1324,7 @@ proc handleSyncInstall*(args: seq[Argument], config: Config): int =
else:
none(string)
- let noconfirm = args
- .filter(arg => arg.matchOption(%%%"confirm") or
- arg.matchOption(%%%"noconfirm")).optLast
- .map(arg => arg.key == "noconfirm").get(false) or
- args.check(%%%"ask")
-
+ let noconfirm = args.noconfirm
let targets = args.packageTargets(false)
withAur():