Skip to content

Commit 21e6455

Browse files
committed
Fix token ordering for LINKFILE/LINKDIR
1 parent 3736125 commit 21e6455

File tree

3 files changed

+53
-19
lines changed

3 files changed

+53
-19
lines changed

src/base/os.lua

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,38 @@
637637
return "echo " .. v
638638
end,
639639
linkdir = function(v)
640-
return "ln -s " .. path.normalize(v)
640+
-- split the source and target
641+
-- source and target may be quoted with spaces
642+
-- if the source or target was quoted, retain the quotes
643+
local src, tgt = v:match("^%s*\"(.-)\"%s+\"(.-)\"%s*$")
644+
if not src then
645+
src, _ = v:match("^%s*(.-)%s+(.-)%s*$")
646+
else
647+
src = '"' .. src .. '"'
648+
end
649+
if not tgt then
650+
_, tgt = v:match("^%s*(.-)%s+(.-)%s*$")
651+
else
652+
tgt = '"' .. tgt .. '"'
653+
end
654+
return "ln -s " .. path.normalize(tgt) .. " " .. path.normalize(src)
641655
end,
642656
linkfile = function(v)
643-
return "ln -s " .. path.normalize(v)
657+
-- split the source and target
658+
-- source and target may be quoted with spaces
659+
-- if the source or target was quoted, retain the quotes
660+
local src, tgt = v:match("^%s*\"(.-)\"%s+\"(.-)\"%s*$")
661+
if not src then
662+
src, _ = v:match("^%s*(.-)%s+(.-)%s*$")
663+
else
664+
src = '"' .. src .. '"'
665+
end
666+
if not tgt then
667+
_, tgt = v:match("^%s*(.-)%s+(.-)%s*$")
668+
else
669+
tgt = '"' .. tgt .. '"'
670+
end
671+
return "ln -s " .. path.normalize(tgt) .. " " .. path.normalize(src)
644672
end,
645673
mkdir = function(v)
646674
return "mkdir -p " .. path.normalize(v)

tests/base/test_os.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,15 @@
313313
end
314314

315315
function suite.translateCommand_posixLinkDir()
316-
test.isequal('ln -s a b', os.translateCommands('{LINKDIR} a b', "posix"))
316+
test.isequal('ln -s b a', os.translateCommands('{LINKDIR} a b', "posix"))
317317
end
318318

319319
function suite.translateCommand_posixLinkFile()
320-
test.isequal('ln -s a b', os.translateCommands('{LINKFILE} a b', "posix"))
320+
test.isequal('ln -s b a', os.translateCommands('{LINKFILE} a b', "posix"))
321+
end
322+
323+
function suite.translateCommand_posixLinkDirWithSpaces()
324+
test.isequal('ln -s "b b" "a a"', os.translateCommands('{LINKDIR} "a a" "b b"', "posix"))
321325
end
322326
--
323327
-- os.getWindowsRegistry windows tests

website/docs/Tokens.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,19 @@ Command tokens are replaced with an appropriate command for the target shell. Fo
9999

100100
The available tokens, and their replacements:
101101

102-
| Token | DOS/cmd | Posix |
103-
|------------|---------------------------------------------|-----------------|
104-
| {CHDIR} | chdir {args} | cd {args} |
105-
| {COPYFILE} | copy /B /Y {args} | cp -f {args} |
106-
| {COPYDIR} | xcopy /Q /E /Y /I {args} | cp -rf {args} |
107-
| {DELETE} | del {args} | rm -rf {args} |
108-
| {ECHO} | echo {args} | echo {args} |
109-
| {LINKDIR} | mklink /d {args} | ln -s {args} |
110-
| {LINKFILE} | mklink {args} | ln -s {args} |
111-
| {MKDIR} | IF NOT EXIST {args} (mkdir {args}) | mkdir -p {args} |
112-
| {MOVE} | move /Y {args} | mv -f {args} |
113-
| {RMDIR} | rmdir /S /Q {args} | rm -rf {args} |
114-
| {TOUCH} | type nul >> {arg} && copy /b {arg}+,, {arg} | touch {args} |
102+
| Token | DOS/cmd | Posix |
103+
|------------|---------------------------------------------|-----------------------|
104+
| {CHDIR} | chdir {args} | cd {args} |
105+
| {COPYFILE} | copy /B /Y {args} | cp -f {args} |
106+
| {COPYDIR} | xcopy /Q /E /Y /I {args} | cp -rf {args} |
107+
| {DELETE} | del {args} | rm -rf {args} |
108+
| {ECHO} | echo {args} | echo {args} |
109+
| {LINKDIR} | mklink /d {args} | ln -s {reversed args} |
110+
| {LINKFILE} | mklink {args} | ln -s {reversed args} |
111+
| {MKDIR} | IF NOT EXIST {args} (mkdir {args}) | mkdir -p {args} |
112+
| {MOVE} | move /Y {args} | mv -f {args} |
113+
| {RMDIR} | rmdir /S /Q {args} | rm -rf {args} |
114+
| {TOUCH} | type nul >> {arg} && copy /b {arg}+,, {arg} | touch {args} |
115115

116116
:::caution
117117
The following tokens are deprecated:
@@ -135,9 +135,11 @@ buildcommands {
135135
}
136136
```
137137

138-
### Symbolic Links and Windows
138+
### Symbolic Links
139139

140-
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.
140+
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.
141+
142+
LINKDIR and LINKFILE follow Windows `mklink` semantics, i.e. `{LINKFILE} LINK TARGET`, instead of Posix semantics.
141143

142144
## Tokens and Filters
143145

0 commit comments

Comments
 (0)