Added check to prevent installing local managed modules in the HOME directory or $HOME/mmm
h3rald h3rald@h3rald.com
Fri, 02 Feb 2024 13:23:52 +0100
2 files changed,
12 insertions(+),
1 deletions(-)
M
minpkg/core/mmm.nim
→
minpkg/core/mmm.nim
@@ -39,6 +39,10 @@ return MMM.modules.filterIt(it.hasKey("name") and it["name"] == %name)[0]
except CatchableError: raiseError "Module '$#' not found." % [name] +proc forbidLocalModulesInGlobalDir(MMM: var MinModuleManager, op: string) = + if MMM.localDir == MMM.globalDir or MMM.localDir.startsWith(MMM.globalDir/"mmm"): + raiseError "Cannot $# a module in the global directory without specifying -g." % [op] + proc setup*(MMM: var MinModuleManager, check = true) = MMM.registry = MMMREGISTRY MMM.globalDir = HOME / "mmm"@@ -106,6 +110,7 @@ createDir(pwd / "mmm")
notice "Created a mmm.json file in the current directory" proc uninstall*(MMM: var MinModuleManager, name, v: string, global = false) = + forbidLocalModulesInGlobalDir(MMM, "uninstall") var dir: string var version = v var versionLabel = version@@ -160,6 +165,7 @@ let version = parts[1]
MMM.uninstall name, version, global proc uninstall*(MMM: var MinModuleManager) = + forbidLocalModulesInGlobalDir(MMM, "uninstall") let pwd = getCurrentDir() if not fileExists(pwd / "mmm.json"): raiseError "mmm.json not found in current directory. Please run min init to initialize your managed module."@@ -171,6 +177,7 @@ except CatchableError:
raiseError "Unable to uninstall local managed modules." proc install*(MMM: var MinModuleManager, name, v: string, global = false) = + forbidLocalModulesInGlobalDir(MMM, "install") var version = v var dir: string let pwd = getCurrentDir()@@ -252,6 +259,7 @@ let version = parts[1]
MMM.install name, version, global proc install*(MMM: var MinModuleManager) = + forbidLocalModulesInGlobalDir(MMM, "install") let mmmJson = getCurrentDir() / "mmm.json" if not mmmJson.fileExists: raiseError "No mmm.json file found in the current directory."@@ -279,6 +287,7 @@ finally:
raiseError "Installation failed." proc update*(MMM: var MinModuleManager, name, v: string, global = false) = + forbidLocalModulesInGlobalDir(MMM, "update") var version = v var dir: string if version == "":@@ -339,6 +348,7 @@ let version = parts[1]
MMM.update name, version, global proc update*(MMM: var MinModuleManager) = + forbidLocalModulesInGlobalDir(MMM, "update") let mmmJson = getCurrentDir() / "mmm.json" if not mmmJson.fileExists: raiseError "No mmm.json file found in the current directory."
M
next-release.md
→
next-release.md
@@ -8,7 +8,8 @@ - Upgraded OpenSSL to v3.2.0
- mmm: It is now possible to install, uninstall, and update modules by specifying them via `<name>@<version>`. - mmm: The version is now optional when installing, uninstalling, and updating modules (the name of the HEAD branch will be used, e.g. "master" or "main", typically). +### Fixes and Improvements -### Fixes and Improvements +- Added check to prevent installing local managed modules in the HOME directory or $HOME/mmm.