diff options
| author | William Boman <william@redwill.se> | 2023-04-23 22:25:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-23 22:25:51 +0200 |
| commit | b03c163f12684c21f43b98208ada78145763c6f1 (patch) | |
| tree | f2875067c3ddcd3eda47c7161725c9ab5807f84b /tests | |
| parent | fix(expr): fix strip_{prefix,suffix} (#1249) (diff) | |
| download | mason-b03c163f12684c21f43b98208ada78145763c6f1.tar mason-b03c163f12684c21f43b98208ada78145763c6f1.tar.gz mason-b03c163f12684c21f43b98208ada78145763c6f1.tar.bz2 mason-b03c163f12684c21f43b98208ada78145763c6f1.tar.lz mason-b03c163f12684c21f43b98208ada78145763c6f1.tar.xz mason-b03c163f12684c21f43b98208ada78145763c6f1.tar.zst mason-b03c163f12684c21f43b98208ada78145763c6f1.zip | |
fix(linker): don't symlink on Windows (#1253)
1) FAT (FAT32, exFAT, etc.) file systems doesn't support symlinks.
2) You need administrator access in order to create symlinks.
This was working for me locally because I'm running a NTFS fs with
"Developer Mode" enabled in Windows 10, which bypasses administrator
requirement for mklink.
Instead we uv_fs_rename() links. This should effectively be the same,
but will require special handling down the road if/when for example
multiple package versions can be installed at the same time. When
unlinking a package the renamed files should me moved back into the
package installation directory, instead of simply being unlinked (i.e.
removed).
Closes #1251.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/installer/linker_spec.lua | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/tests/mason-core/installer/linker_spec.lua b/tests/mason-core/installer/linker_spec.lua index ac66b212..0a2b62ab 100644 --- a/tests/mason-core/installer/linker_spec.lua +++ b/tests/mason-core/installer/linker_spec.lua @@ -21,7 +21,7 @@ describe("linker", function() local platform before_each(function() - package.loaded["mason-core.installer.platform"] = nil + package.loaded["mason-core.platform"] = nil package.loaded["mason-core.installer.linker"] = nil platform = require "mason-core.platform" linker = require "mason-core.installer.linker" @@ -131,7 +131,10 @@ describe("linker", function() local ctx = InstallContextGenerator(handle) ctx.links.share["nested/path/share-file"] = path.concat { "nested", "path", "to", "share-file" } ctx.links.share["share-file"] = "share-file" - assert.is_true(linker.link(ctx):is_success()) + + local result = linker.link(ctx) + + assert.is_true(result:is_success()) assert.spy(fs.async.write_file).was_called(0) assert.spy(fs.async.symlink).was_called(2) @@ -148,4 +151,53 @@ describe("linker", function() assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix "nested/path") end) ) + + it("should rename share files on Windows", function() + platform.is.darwin = false + platform.is.mac = false + platform.is.linux = false + platform.is.unix = false + platform.is.win = true + + local dummy = registry.get_package "dummy" + stub(fs.async, "mkdirp") + stub(fs.async, "dir_exists") + stub(fs.async, "file_exists") + stub(fs.async, "rename") + + -- mock non-existent dest files + fs.async.file_exists.on_call_with(path.share_prefix "share-file").returns(false) + fs.async.file_exists.on_call_with(path.share_prefix(path.concat { "nested", "share-file" })).returns(false) + + fs.async.dir_exists.on_call_with(path.share_prefix()).returns(false) + fs.async.dir_exists.on_call_with(path.share_prefix "nested/path").returns(false) + + -- mock existent source files + fs.async.file_exists.on_call_with(path.concat { dummy:get_install_path(), "share-file" }).returns(true) + fs.async.file_exists + .on_call_with(path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }) + .returns(true) + + local handle = InstallHandleGenerator "dummy" + local ctx = InstallContextGenerator(handle) + ctx.links.share["nested/path/share-file"] = path.concat { "nested", "path", "to", "share-file" } + ctx.links.share["share-file"] = "share-file" + + local result = linker.link(ctx) + + assert.is_true(result:is_success()) + + assert.spy(fs.async.rename).was_called(2) + assert + .spy(fs.async.rename) + .was_called_with(path.concat { dummy:get_install_path(), "share-file" }, path.share_prefix "share-file") + assert.spy(fs.async.rename).was_called_with( + path.concat { dummy:get_install_path(), "nested", "path", "to", "share-file" }, + path.share_prefix "nested/path/share-file" + ) + + assert.spy(fs.async.mkdirp).was_called(2) + assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix()) + assert.spy(fs.async.mkdirp).was_called_with(path.share_prefix "nested/path") + end) end) |
