summaryrefslogtreecommitdiff
path: root/xmake/modules/private/action/require/impl/utils/plugins.lua
diff options
context:
space:
mode:
authorSaikari <[email protected]>2026-07-11 02:01:17 +0300
committerruki <[email protected]>2026-07-30 10:17:31 +0800
commit20127575d8f48d9b286021c779bdd85090273c39 (patch)
tree3304028349444b27824787b7eb16c731a739c980 /xmake/modules/private/action/require/impl/utils/plugins.lua
parenta12319420f9ba033b51f48761c28c30f863312c3 (diff)
fix: distinguish between plugin and package names to avoid conflicts
Diffstat (limited to 'xmake/modules/private/action/require/impl/utils/plugins.lua')
-rw-r--r--xmake/modules/private/action/require/impl/utils/plugins.lua15
1 files changed, 12 insertions, 3 deletions
diff --git a/xmake/modules/private/action/require/impl/utils/plugins.lua b/xmake/modules/private/action/require/impl/utils/plugins.lua
index 9cd7c5d86..f7d4d305f 100644
--- a/xmake/modules/private/action/require/impl/utils/plugins.lua
+++ b/xmake/modules/private/action/require/impl/utils/plugins.lua
@@ -33,11 +33,20 @@ function register(package)
assert(os.isfile(path.join(installdir, "xmake.lua")),
"plugin(%s): xmake.lua not found in the installed files, it should be installed with `os.cp(\"*\", package:installdir())`!", package:name())
local dir = plugindir(package:name())
- os.tryrm(dir)
- os.cp(installdir, dir)
+ -- we copy it to the temporary directory first and then swap it,
+ -- so the previous plugin will not be lost if copying fails. e.g. disk full
+ --
+ -- we cannot use the sibling directory, e.g. `plugins/<name>.tmp`,
+ -- because the task loader will load all plugins from `plugins/*/xmake.lua`
+ local tmpdir = path.join(path.directory(dir), ".tmp", package:name())
+ os.tryrm(tmpdir)
+ os.cp(installdir, tmpdir)
-- remove the install logs, they do not belong to the plugin,
-- but we keep manifest.txt to show the plugin version and description. e.g. `xmake plugin --list`
- os.tryrm(path.join(dir, "logs"))
+ os.tryrm(path.join(tmpdir, "logs"))
+ -- replace the previous plugin only after the new one is fully ready
+ os.tryrm(dir)
+ os.mv(tmpdir, dir)
vprint("register plugin(%s) to %s", package:name(), dir)
end