make gopass mount store idem-potent

This commit is contained in:
az 2023-06-02 19:36:18 +02:00
parent 59c5c8ba5a
commit 0c648eeac7
2 changed files with 8 additions and 2 deletions

View file

@ -71,8 +71,13 @@ fun Prov.configureGopass(gopassRootFolder: String? = null, publicGpgKey: Secret?
}
fun Prov.gopassMountStore(storeName: String, path: String) = task {
cmd("gopass mounts add $storeName $path")
fun Prov.gopassMountStore(storeName: String, path: String) = taskWithResult {
val mounts = cmdNoEval("gopass mounts").out ?: return@taskWithResult ProvResult(false, err = "could not determin gopass mounts")
if (mounts.contains(storeName)) {
ProvResult(true, out = "Store $storeName already mounted.")
} else {
cmd("gopass mounts add $storeName $path")
}
}

View file

@ -41,6 +41,7 @@ internal class GopassKtTest {
configureGopass(prov.userHome() + gopassRootDir)
gopassInitStoreFolder("~/exampleStoreFolder")
gopassMountStore("exampleStore", "~/exampleStoreFolder")
gopassMountStore("exampleStore", "~/exampleStoreFolder") // check that mounting twice gives no error
prov.cmd("gopass ls")
}