Skip to content

Commit

Permalink
fix: allow relative symlinks to directories when using build staging (#…
Browse files Browse the repository at this point in the history
…6430)

* fix: allow relative symlinks to directories when using build staging

Allows using relative symlinks to directories and files when using build staging.

The goal is to reproduce symlinks in the target directory as-is, without having to resolve them.
The user would be responsible for making sure that both the relative symlink as well as the target
directory are included in the action.

If the symlink points to a file or directory outside the actions's source path, this throws an
error.

To avoid this becoming a breaking change, we keep the old behaviour if the symlink points to a
file. In that case, we resolve the symlink and copy the target file. If the target file is outside
 the action's source or build directory, log a warning.

In a future 0.14 release of Garden, we should remove that branch, only reproduce symlinks (without
resolving them recursively) and
throw an error if the link is out of bounds.

Fixes #2382

Co-authored-by: Thorarinn Sigurdsson <[email protected]>

* test: add additional test for the error

Co-authored-by: vova <[email protected]>

* refactor: rename param object property

To keep more precise naming.

* refactor: introduce param object for constructor

* refactor: introduce param object for factory method

* chore: declare non re-assignable props as readonly

* refactor: named type for standard stats callback

* refactor: named type for resolve symlink callback stats callback

* refactor: param object for resolve symlink callback

* fix: restore accidentally deleted condition check

Co-authored-by: Steffen Neubauer <[email protected]>

---------

Co-authored-by: Thorarinn Sigurdsson <[email protected]>
Co-authored-by: vova <[email protected]>
Co-authored-by: Vladimir Vagaytsev <[email protected]>
  • Loading branch information
4 people authored Sep 12, 2024
1 parent d619ece commit 26644fc
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 69 deletions.
4 changes: 3 additions & 1 deletion core/src/build-staging/build-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ export class BuildStaging {
const to = targetShouldBeDirectory || targetStat?.isDirectory() ? join(targetPath, sourceBasename) : targetPath

await syncFileAsync({
log,
sourceRoot,
from: sourceRoot,
to,
allowDelete: withDelete,
Expand Down Expand Up @@ -323,7 +325,7 @@ export class BuildStaging {
([fromRelative, toRelative], fileCb) => {
const from = joinWithPosix(sourceRoot, fromRelative)
const to = joinWithPosix(targetPath, toRelative)
cloneFile({ from, to, allowDelete: withDelete, statsHelper }, fileCb)
cloneFile({ log, sourceRoot, from, to, allowDelete: withDelete, statsHelper }, fileCb)
},
cb
)
Expand Down
Loading

0 comments on commit 26644fc

Please sign in to comment.