-
Notifications
You must be signed in to change notification settings - Fork 1k
allow cachedir override using env var #1234
Conversation
internal/gps/source_manager.go
Outdated
@@ -292,6 +292,11 @@ func NewSourceManager(c SourceManagerConfig) (*SourceMgr, error) { | |||
return sm, nil | |||
} | |||
|
|||
// Cachedir is a getter for the cachedir location. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Cachedir returns the location of the cache directory.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure @jmank88. I'll wait for some more feedback and do it along with the other requested changes(if any).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, i agree with @jmank88's suggestion.
I am on a windows machine and the newly added tests were passing. However, the appveyor build failed while trying to |
appveyor tests can be pretty flaky, and network failures like that aren't uncommon. i kicked the test to rerun, but it revealed a new incompatibility that's popped up as a result of a push from a couple days ago, so you'll need to rebase and accommodate that change anyway. |
bf6fcea
to
e3930c6
Compare
@sdboyer I have rebased. However, I am not able to replicate the error on appveyor:
|
ok, i'm gonna choose to think that whatever we saw was transient. please update the |
8fce7de
to
740f9bb
Compare
@sdboyer Do you think we should validate the value of env var |
hmmm - fair point, that is definitely user input. yes, we should validate. the empirical approach there is fine - it'll also be a requirement to make sure that the directory exists in order for gps to work correctly with it, I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving back to "request changes" until we've got the validation done.
@sdboyer Wouldn't creating the directory, if it does not exist, make sense? I think it is a valid scenario where the user gives the dir as Edit: This should take care of creating the dir - dep/internal/gps/source_manager.go Lines 196 to 204 in 1d73a4a
|
69c070f
to
e52321c
Compare
CHANGELOG.md
Outdated
@@ -7,6 +7,8 @@ NEW FEATURES: | |||
(#1206) | |||
* `dep ensure -no-vendor -dry-run` now exits with an error when changes would | |||
have to be made to `Gopkg.lock`. This is useful for CI. (#1256) | |||
* Allow override of cache directory location using environment variable | |||
`DEPCACHEDIR`. (#1234) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just released v0.3.2, so please move this under v0.3.3. We have started using release milestones to avoid this in the future.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with rebase.
e52321c
to
eec7c00
Compare
@darkowlzz Small note, in the release notes for Edit: I might have misunderstood what |
eec7c00
to
a46f562
Compare
a46f562
to
e96719a
Compare
Rebased and resolved conflicts. Can we please merge this in? I can do the changes if any are required. |
@sdboyer Could we move forward with this? The failure in CI is unrelated to changes in this PR as far as I can tell. |
I'm still not back from vacation yet.
…On November 11, 2017 7:43:45 AM GMT+01:00, Suhas Karanth ***@***.***> wrote:
@sdboyer Could we move forward with this? The failure in CI is
unrelated to changes in this PR as far as I can tell.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#1234 (comment)
|
My apologies. Hope you enjoy your vacation 😄 . |
ok, i'm back. thanks for your patience. so, the only question i have at this point is re: the use of i think i'd prefer we be more conservative initially with this, and use |
e96719a
to
ab78af5
Compare
@sdboyer To be clear, I did not modify |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like overkill. It's pretty typical for CLI tools to simply report that they could not create a directory - they don't go and walk back up the tree to explain that it was because the parent dir is missing. I don't see a compelling need to do more than that.
The ordering relationship you're concerned about is what i was trying to address in my comment from yesterday. To make it clearer, I've made some quick inline comments to indicate where i think the calls should be made in order to avoid directory creation ordering problems.
cmd/dep/main.go
Outdated
} | ||
|
||
// Cachedir is loaded from env if present. `$GOPATH/pkg/dep` is used as the | ||
// fallback cache location. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"default" is better than "fallback" here.
context.go
Outdated
// When `DEPCACHEDIR` isn't set in the env, fallback to `$GOPATH/pkg/dep`. | ||
cachedir = filepath.Join(c.GOPATH, "pkg", "dep") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably where where first the os.Mkdir()
call should be made to attempt to ensure that the cachedir
exists prior to setting up the SourceManager
, so that the calls within NewSourceManager()
won't have a problem.
I am going to list all the scenarios just so that we(mostly me 😅) are clear.
|
i'm not suggesting that the does that clarify sufficiently? |
ab78af5
to
4698075
Compare
Thank you @sdboyer for being so patient with me. I have made the changes as per your suggestions. |
a4cbceb
to
398de52
Compare
c4c6c51
to
bff0adc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i'm happy with the code here, now, with the exception of that appveyor error.
The test doesn't produce consistent results. It failed for me once on my system. I also tried to add some logging and it works correctly: diff --git a/cmd/dep/integration_test.go b/cmd/dep/integration_test.go
index 0ecebaff..26e192de 100644
--- a/cmd/dep/integration_test.go
+++ b/cmd/dep/integration_test.go
@@ -82,6 +82,23 @@ func TestDepCachedir(t *testing.T) {
t.Logf("`dep ensure` error output: \n%s", testProj.GetStderr())
t.Errorf("got an unexpected error: %s", err)
}
+ visit := func(path string, info os.FileInfo, err error) error {
+ path = strings.Replace(path, cachedir, "[cachedir]", -1)
+ if info.IsDir() {
+ if info.Name() == ".git" {
+ return filepath.SkipDir
+ }
+ fmt.Println("dir: ", path)
+ } else {
+ fmt.Println("file: ", path)
+ }
+ return nil
+ }
+
+ err := filepath.Walk(cachedir, visit)
+ if err != nil {
+ t.Fatal(err)
+ }
// Check that the cache was created in the cachedir. Our fixture has the dependency
// `github.com/sdboyer/deptest` Test output:
Not sure how I can fix it. Does it have anything to do with the parallel execution? |
i'm not sure what the problem is there, honestly, and i still don't have access to a windows box to be able to test it myself. if it's working on your windows system, then honestly, i'd be OK with bypassing the test on windows, so long as an explanatory note is included in a comment. |
I think this is fine. I've tried reproducing this failure 10 times in appveyor (with an intent to debug the issue), but couldn't reproduce the failure even once. And in the past, we have seen some weird failures on Windows due to parallel execution. This could be like one of those. |
I agree with @darkowlzz but I am okay with disabling the test on Windows. @sdboyer, what do you suggest? |
yep, let's disable the test on windows, with a comment. |
source - main.go: Read and use env var `DEPCACHEDIR` for instantiating dep context. - context.go: - Add field `Cachedir` to struct `Ctx`. This holds the value of env var `DEPCACHEDIR`. - Use `Ctx.Cachedir` while instantiating `gps.SourceMgr` if present, fallback to `$GOPATH/pkg/dep` otherwise. - source_manager.go: Add a getter func `Cachedir` to facilitate testing in `context_test.go`. test - context_test.go Add test to check `gps.SourceMgr` is instantiated with appropriate `cachedir`. - integration_test.go: Add test to check environment variable `DEPCACHEDIR` is loaded and used if present. misc - update changelog
- fs.go - Add method `IsValidPath` to check if given file path string is valid. Add tests as well. - main.go - After loading cachedir from env, if it has been set, check validity, exit with status 1 if not. Update integration tests for this scenario.
source - main.go: Try to ensure directory for given `cachedir` path. - context.go: Create the default cache directory, `$GOPATH/pkg/dep`, if the user did not override it. - source_manager.go: Use `fs.EnsureDir` instead of `os.MkdirAll` for creating sources folder in cache directory. - fs.go: - Add func `EnsureDir` to create a directory if it does not exist. - Remove func `IsValidPath`. test - integration_test.go: Improve tests for invalid cache directory. - fs_test.go: Add test for `EnsureDir`, remove test for `IsValidPath`. - manager_test.go: fix TestSourceManagerInit - Re-create cache directory before trying to call `NewSourceManager` the 2nd time and defer it's removal. - If `NewSourceManager` fails the 2nd time, exit the error using `t.Fatal` to avoid panic in `sm.Release` misc - language - {fallback => default} for cachedir
bff0adc
to
e88d062
Compare
ok, in we go! 🎉 🎉 thanks for your patience. |
Thank you for your guidance! |
@sdboyer While I not the sharpest tool in the shed and need some hand-holding, I still enjoy contributing here immensely. If you think there is anything else I could work on, please do ping. I'd be delighted to. |
What does this do / why do we need it?
Allows to override the cache directory location using an environment variable(
DEPCACHEDIR
). Having the cache location depend on the gopath can negatively affect performance for anyone using multiple Go workspaces.What should your reviewer look out for in this PR?
The source code change was simple enough but it was a bit challenging to write the tests. Please check if they look alright.
Do you need help or clarification on anything?
Tests.
Which issue(s) does this PR fix?
fixes #1066
Changelog
DEPCACHEDIR
for instantiating dep context.Cachedir
to structCtx
. This holds the value of env varDEPCACHEDIR
.Ctx.Cachedir
while instantiatinggps.SourceMgr
if present, fallbackto
$GOPATH/pkg/dep
otherwise.Cachedir
to facilitate testing incontext_test.go
.gps.SourceMgr
is instantiated withappropriate
cachedir
.DEPCACHEDIR
isloaded and used if present.