Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afero symlinker #240

Merged
merged 6 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ jobs:
- stage: check
script:
- if [[ ! -z "${SNYK_TOKEN}" ]]; then snyk monitor --org=czi; snyk test; fi
- stage: check
script:
- curl --data-binary @codecov.yml https://codecov.io/validate
7 changes: 4 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

[[constraint]]
name = "github.com/spf13/afero"
version = "1.1.1"
source = "github.com/chanzuckerberg/afero"
branch = "symlinker"

[[constraint]]
name = "github.com/spf13/cobra"
Expand Down Expand Up @@ -53,3 +54,4 @@
[[constraint]]
name = "gopkg.in/yaml.v2"
version = "2.2.1"

6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ coverage: ## run the go coverage tool, reading file coverage.out
go tool cover -html=coverage.out

test: dep ## run tests
gotest -race ./...
gotest -race -cover ./...

test-coverage: ## run the test with proper coverage reporting
goverage -race -coverprofile=coverage.out -covermode=atomic ./...
Expand All @@ -69,8 +69,4 @@ dep: ## ensure dependencies are vendored
dep ensure # this should be super-fast in the no-op case
.PHONY: dep

dep:
dep ensure
.PHONY: dep

.PHONY: build clean coverage test install lint lint-slow packr release help setup
20 changes: 7 additions & 13 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ func applyTree(dest afero.Fs, source *packr.Box, targetBasePath string, subst in

linkTarget := string(linkTargetBytes)

err = linkFile(target, linkTarget)
linker, ok := dest.(afero.Symlinker)

if !ok {
return errs.NewInternal("can't cast to afero.SymLinker")
}

_, err = linker.SymlinkIfPossible(target, linkTarget)
if err != nil {
return errs.WrapInternal(err, "can't symlink file")
}
Expand Down Expand Up @@ -425,18 +431,6 @@ func getTargetPath(basePath, path string) string {
return target
}

func linkFile(name, target string) error {
log.Debugf("removing link at %s", name)
os.Remove(name)
log.Debugf("linking %s to %s", name, target)
relativePath, err := filepathRel(name, target)
log.Debugf("relative link %s err %#v", relativePath, err)
if err != nil {
return err
}
return os.Symlink(relativePath, name)
}

func filepathRel(path, name string) (string, error) {
dirs := strings.Count(path, "/")
fullPath := fmt.Sprintf("%s/%s", strings.Repeat("../", dirs), name)
Expand Down
12 changes: 8 additions & 4 deletions apply/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,15 @@ func TestCreateFileNonExistentDirectory(t *testing.T) {
}

func TestApplySmokeTest(t *testing.T) {
t.Skip("doesn't currently work because afero doesn't support symlinks")
// We have to use a BasePathFs so that we can calculate `RealPath` for symlinking. Afero doesn't support symlinks
fs := afero.NewBasePathFs(afero.NewMemMapFs(), "/")
json := `
{
"defaults": {
"aws_region": "reg",
"aws_profile": "prof",
"aws_region_provider": "reg",
"aws_region_backend": "reg",
"aws_profile_provider": "prof",
"aws_profile_backend": "prof",
"aws_provider_version": "0.12.0",
"infra_s3_bucket": "buck",
"project": "proj",
"terraform_version": "0.100.0",
Expand Down Expand Up @@ -237,6 +238,9 @@ func TestApplySmokeTest(t *testing.T) {
c2, e := config.UpgradeConfigVersion(c)
assert.NoError(t, e)

e = c2.Validate()
assert.NoError(t, e)

e = Apply(fs, c2, templates.Templates, false)
assert.NoError(t, e)
}
Expand Down
2 changes: 2 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "vendor"
43 changes: 43 additions & 0 deletions vendor/github.com/spf13/afero/basepath.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 48 additions & 2 deletions vendor/github.com/spf13/afero/copyOnWriteFs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/spf13/afero/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/spf13/afero/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/spf13/afero/os.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions vendor/github.com/spf13/afero/readonlyfs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions vendor/github.com/spf13/afero/symlinker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions vendor/github.com/spf13/afero/unionFile.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.