Skip to content

Commit

Permalink
fix: also reproduce symlinks when using patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
stefreak committed Sep 25, 2024
1 parent 0d32c10 commit b03c343
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/build-staging/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export async function scanDirectoryForClone(root: string, pattern?: string): Pro
filter: (stats) => {
// See if this is a file within a previously matched directory
// Note: `stats.path` is always POSIX formatted, relative to `sourceRoot`
if (stats.isFile()) {
if (stats.isFile() || stats.isSymbolicLink()) {
for (const dirPath of matchedDirectories) {
if (stats.path.startsWith(dirPath + "/")) {
// The file is in a matched directory. We need to map the target path, such that everything ahead of
Expand All @@ -286,7 +286,7 @@ export async function scanDirectoryForClone(root: string, pattern?: string): Pro
if (mm.match(stats.path)) {
if (stats.isDirectory()) {
matchedDirectories.push(stats.path)
} else if (stats.isFile()) {
} else if (stats.isFile() || stats.isSymbolicLink()) {
// When we match a file to the glob, we map it from the source path to just its basename under the target
// directory. Again, this matches rsync behavior.
mappedPaths.push([stats.path, basename(stats.path)])
Expand Down
10 changes: 10 additions & 0 deletions core/test/unit/src/build-staging/build-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ describe("BuildStaging", () => {
// second time
await sync({ log, sourceRoot, targetRoot, withDelete: false })
await assertIdentical(sourceRoot, targetRoot, expectedFiles)

// sync with pattern
targetRoot = join(tmpPath, "target3")
await ensureDir(targetRoot)
// first time
await sync({ log, sourceRoot, sourceRelPath: "*", targetRoot, withDelete: false })
await assertIdentical(sourceRoot, targetRoot, expectedFiles)
// second time
await sync({ log, sourceRoot, sourceRelPath: "*", targetRoot, withDelete: false })
await assertIdentical(sourceRoot, targetRoot, expectedFiles)
})

it("throws if source relative path is absolute", async () => {
Expand Down

0 comments on commit b03c343

Please sign in to comment.