Skip to content

Commit

Permalink
fix(build): don't delete when syncing dependencies
Browse files Browse the repository at this point in the history
This fixes a regression from 9630192, where OpenFaas modules would
sometimes fail. This was because the sync of the built templates into
the build context directory of the module would result in files/folders
being deleted from there.
  • Loading branch information
thsig committed Mar 18, 2019
1 parent 5453f4f commit a5e12a7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions garden-service/src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class BuildDir {
await this.sync(
resolve(this.projectRoot, module.path) + sep,
await this.buildPath(module.name),
true,
)
}

Expand Down Expand Up @@ -83,7 +84,7 @@ export class BuildDir {

const sourcePath = join(sourceBuildPath, copy.source)
const destinationPath = join(buildPath, copy.target)
return this.sync(sourcePath, destinationPath)
return this.sync(sourcePath, destinationPath, false)
})
})
}
Expand All @@ -108,7 +109,12 @@ export class BuildDir {
return path
}

private async sync(sourcePath: string, destinationPath: string): Promise<void> {
/**
* Syncs sourcePath with destinationPath using rsync.
*
* If withDelete = true, files/folders in destinationPath that are not in sourcePath will also be deleted.
*/
private async sync(sourcePath: string, destinationPath: string, withDelete: boolean): Promise<void> {
const destinationDir = parse(destinationPath).dir
await ensureDir(destinationDir)

Expand All @@ -123,7 +129,11 @@ export class BuildDir {
destinationPath = stripWildcard(destinationPath)

// --exclude is required for modules where the module and project are in the same directory
await execa("rsync", ["-rptgo", "--delete", `--exclude=${GARDEN_DIR_NAME}`, sourcePath, destinationPath])
const syncOpts = ["-rptgo", `--exclude=${GARDEN_DIR_NAME}`]
if (withDelete) {
syncOpts.push("--delete")
}
await execa("rsync", [...syncOpts, sourcePath, destinationPath])
}
}

Expand Down

0 comments on commit a5e12a7

Please sign in to comment.