Skip to content

Commit

Permalink
fix: exclude symlinks to directories from hashing (#1044)
Browse files Browse the repository at this point in the history
* fix: exclude symlinks to directories from hashing
  • Loading branch information
10ko authored and edvald committed Jul 30, 2019
1 parent a1dfaba commit 514f9f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion garden-service/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ export class GitHandler extends VcsHandler {
// If we can't compute the hash, i.e. the file is gone, we filter it out below
let hash = ""
try {
hash = await this.hashObject(resolvedPath) || ""
// "git ls-files" returns a symlink even if it points to a directory.
// We filter symlinked directories out, since hashObject() will fail to
// process them.
if (!(await stat(resolvedPath)).isDirectory()) {
hash = await this.hashObject(resolvedPath) || ""
}
} catch (err) {
// 128 = File no longer exists
if (err.code !== 128 && err.code !== "ENOENT") {
Expand Down
17 changes: 16 additions & 1 deletion garden-service/test/unit/src/vcs/git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai"
import * as tmp from "tmp-promise"
import { createFile, writeFile, realpath, mkdir, remove } from "fs-extra"
import { createFile, writeFile, realpath, mkdir, remove, symlink } from "fs-extra"
import { join, resolve } from "path"

import { expectError } from "../../../helpers"
Expand Down Expand Up @@ -231,6 +231,21 @@ describe("GitHandler", () => {

expect(files).to.eql([])
})

it("should exclude an untracked symlink to a directory", async () => {
const tmpDir2 = await tmp.dir({ unsafeCleanup: true })
const tmpPathB = await realpath(tmpDir2.path)

const name = "a-symlink-to-a-directory"
const path = resolve(tmpPath, name)

await symlink(tmpPathB, path)

const files = (await handler.getFiles(tmpPath, undefined, []))
.filter(f => !f.path.includes(ignoreFileName))

expect(files).to.eql([])
})
})

describe("hashObject", () => {
Expand Down

0 comments on commit 514f9f5

Please sign in to comment.