From 92a1369101458c28f7f0138cccff1ce3d3aad459 Mon Sep 17 00:00:00 2001 From: Nick Clark Date: Sat, 28 Dec 2024 12:39:09 -0500 Subject: [PATCH] Fix token ordering for LINKFILE/LINKDIR --- src/base/os.lua | 32 ++++++++++++++++++++++++++++++-- tests/base/test_os.lua | 8 ++++++-- website/docs/Tokens.md | 32 +++++++++++++++++--------------- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/base/os.lua b/src/base/os.lua index d0f3699dff..23870b2366 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -637,10 +637,38 @@ return "echo " .. v end, linkdir = function(v) - return "ln -s " .. path.normalize(v) + -- split the source and target + -- source and target may be quoted with spaces + -- if the source or target was quoted, retain the quotes + local src, tgt = v:match("^%s*\"(.-)\"%s+\"(.-)\"%s*$") + if not src then + src, _ = v:match("^%s*(.-)%s+(.-)%s*$") + else + src = '"' .. src .. '"' + end + if not tgt then + _, tgt = v:match("^%s*(.-)%s+(.-)%s*$") + else + tgt = '"' .. tgt .. '"' + end + return "ln -s " .. path.normalize(tgt) .. " " .. path.normalize(src) end, linkfile = function(v) - return "ln -s " .. path.normalize(v) + -- split the source and target + -- source and target may be quoted with spaces + -- if the source or target was quoted, retain the quotes + local src, tgt = v:match("^%s*\"(.-)\"%s+\"(.-)\"%s*$") + if not src then + src, _ = v:match("^%s*(.-)%s+(.-)%s*$") + else + src = '"' .. src .. '"' + end + if not tgt then + _, tgt = v:match("^%s*(.-)%s+(.-)%s*$") + else + tgt = '"' .. tgt .. '"' + end + return "ln -s " .. path.normalize(tgt) .. " " .. path.normalize(src) end, mkdir = function(v) return "mkdir -p " .. path.normalize(v) diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index fe3c5e639c..1b8800e21e 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -313,11 +313,15 @@ end function suite.translateCommand_posixLinkDir() - test.isequal('ln -s a b', os.translateCommands('{LINKDIR} a b', "posix")) + test.isequal('ln -s b a', os.translateCommands('{LINKDIR} a b', "posix")) end function suite.translateCommand_posixLinkFile() - test.isequal('ln -s a b', os.translateCommands('{LINKFILE} a b', "posix")) + test.isequal('ln -s b a', os.translateCommands('{LINKFILE} a b', "posix")) + end + + function suite.translateCommand_posixLinkDirWithSpaces() + test.isequal('ln -s "b b" "a a"', os.translateCommands('{LINKDIR} "a a" "b b"', "posix")) end -- -- os.getWindowsRegistry windows tests diff --git a/website/docs/Tokens.md b/website/docs/Tokens.md index b71de6a5bf..9d871a473d 100644 --- a/website/docs/Tokens.md +++ b/website/docs/Tokens.md @@ -99,19 +99,19 @@ Command tokens are replaced with an appropriate command for the target shell. Fo The available tokens, and their replacements: -| Token | DOS/cmd | Posix | -|------------|---------------------------------------------|-----------------| -| {CHDIR} | chdir {args} | cd {args} | -| {COPYFILE} | copy /B /Y {args} | cp -f {args} | -| {COPYDIR} | xcopy /Q /E /Y /I {args} | cp -rf {args} | -| {DELETE} | del {args} | rm -rf {args} | -| {ECHO} | echo {args} | echo {args} | -| {LINKDIR} | mklink /d {args} | ln -s {args} | -| {LINKFILE} | mklink {args} | ln -s {args} | -| {MKDIR} | IF NOT EXIST {args} (mkdir {args}) | mkdir -p {args} | -| {MOVE} | move /Y {args} | mv -f {args} | -| {RMDIR} | rmdir /S /Q {args} | rm -rf {args} | -| {TOUCH} | type nul >> {arg} && copy /b {arg}+,, {arg} | touch {args} | +| Token | DOS/cmd | Posix | +|------------|---------------------------------------------|-----------------------| +| {CHDIR} | chdir {args} | cd {args} | +| {COPYFILE} | copy /B /Y {args} | cp -f {args} | +| {COPYDIR} | xcopy /Q /E /Y /I {args} | cp -rf {args} | +| {DELETE} | del {args} | rm -rf {args} | +| {ECHO} | echo {args} | echo {args} | +| {LINKDIR} | mklink /d {args} | ln -s {reversed args} | +| {LINKFILE} | mklink {args} | ln -s {reversed args} | +| {MKDIR} | IF NOT EXIST {args} (mkdir {args}) | mkdir -p {args} | +| {MOVE} | move /Y {args} | mv -f {args} | +| {RMDIR} | rmdir /S /Q {args} | rm -rf {args} | +| {TOUCH} | type nul >> {arg} && copy /b {arg}+,, {arg} | touch {args} | :::caution The following tokens are deprecated: @@ -135,9 +135,11 @@ buildcommands { } ``` -### Symbolic Links and Windows +### Symbolic Links -For Windows, it is required to create symbolic links from an elevated context or to have Developer Mode enabled. The minimum required Windows version to execute symbolic links is Windows 10. +For Windows, it is required to create symbolic links from an elevated context or to have Developer Mode enabled. The minimum required Windows version to execute symbolic links is Windows 10. + +LINKDIR and LINKFILE follow Windows `mklink` semantics, i.e. `{LINKFILE} LINK TARGET`, instead of Posix semantics. ## Tokens and Filters