fix userHome for root user

This commit is contained in:
ansgarz 2022-01-17 19:28:58 +01:00
parent b92feb08d4
commit 24c0b796f0

View file

@ -222,12 +222,15 @@ fun Prov.deleteDir(dir: String, path: String, sudo: Boolean = false): ProvResult
fun Prov.userHome(): String { fun Prov.userHome(): String {
val user = cmd("whoami").out val user = cmd("whoami").out?.trim()
if (user == null) { if (user == null) {
throw RuntimeException("Could not determine user with whoami") throw RuntimeException("Could not determine user with whoami")
} else { } else {
// assume default home folder // set default home folder
return "/home/" + user.trim() + "/" return if (user == "root")
"/root/"
else
"/home/$user/"
} }
} }