Skip to content

Commit

Permalink
Fix token ordering for LINKFILE/LINKDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
nickclark2016 committed Dec 28, 2024
1 parent b8dffdb commit 92a1369
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
32 changes: 30 additions & 2 deletions src/base/os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions tests/base/test_os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 17 additions & 15 deletions website/docs/Tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit 92a1369

Please sign in to comment.