Skip to content

Commit 75ee8c5

Browse files
authored
feat: allow symlinks in workspaces (#2064)
* e2e-tests: add test for symlinks in workspace * pkg/build: fix workspace population with files which are symlinks to regular files This already worked on mac for some reason, which is probably another bug. But it didn't work on linux.
1 parent 7609599 commit 75ee8c5

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package:
2+
name: symlinks-in-workspace-build
3+
description: Test that symlinks are copied into workspaces
4+
version: 0.1.0
5+
epoch: 0
6+
7+
environment:
8+
contents:
9+
packages:
10+
- busybox
11+
12+
pipeline:
13+
- name: Test for symlink presence in workspace
14+
runs: |
15+
testdata_linked=$(cat testdata-symlink.txt)
16+
testdata=$(cat testdata.txt)
17+
[ "$testdata" = "$testdata_linked" ]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
testdata.txt

e2e-tests/test-fixtures/testdata.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test data is present

pkg/build/build.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,25 @@ func (b *Build) populateWorkspace(ctx context.Context, src fs.FS) error {
563563

564564
mode := fi.Mode()
565565
if !mode.IsRegular() {
566-
return nil
566+
// If this file is a symlink to a regular file, include it.
567+
// It would be easier to include all symlinks but that breaks
568+
// when the top-level workspace directory is a symlink.
569+
if mode&fs.ModeSymlink != 0 {
570+
targetPath, err := filepath.EvalSymlinks(filepath.Join(b.SourceDir, path))
571+
if err != nil {
572+
log.Debugf("path %s eval gives err %v", path, err)
573+
return err
574+
}
575+
target, err := os.Stat(targetPath)
576+
if err != nil {
577+
return err
578+
}
579+
if !target.Mode().IsRegular() {
580+
return nil
581+
}
582+
} else {
583+
return nil
584+
}
567585
}
568586

569587
for _, pat := range ignorePatterns {

0 commit comments

Comments
 (0)