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

Add Windows support to cacheddownloader #6

Merged
merged 5 commits into from
Feb 27, 2015
Merged

Conversation

lvarvel
Copy link
Contributor

@lvarvel lvarvel commented Feb 20, 2015

Cacheddownloader has a number of issues on Windows, mostly due to irritating differences between Windows and Linux file open/closing and removal. This fixes one of them.

There's no additional test code necessary, because this change actually fixes three tests that currently fail when run on Windows.

After this change, there will still be 29 failing tests (previously 32), and we'll be submitting more pull requests as we stomp those.

@emalm
Copy link
Member

emalm commented Feb 21, 2015

Thanks, @lvarvel! I've created this Diego story to evaluate the PR.

@krishicks
Copy link
Contributor

Could you please clarify which tests were failing on Windows? Was it the cacheddownloader unit tests, or other tests from diego-release?

Thanks,
@krishicks && @ematpl

@lvarvel
Copy link
Contributor Author

lvarvel commented Feb 24, 2015

The tests were the cacheddownloader unit tests. I don't think we had any other failing diego tests.

@lvarvel
Copy link
Contributor Author

lvarvel commented Feb 24, 2015

There is also one final test that fails intermittently on Windows. We've dropped a chore into our backlog, and we'll get back to you on that one later. This PR should be good to go.

@emalm
Copy link
Member

emalm commented Feb 24, 2015

@lvarvel @mavenraven: The first commit was fine, but the second one (with the windowsSafeRename function) is failing on the Travis linux build. Could you please remove that commit and submit a separate PR for that one? Also, the Travis build is failing because that commit depends on several syscall functions that are unavailable on Linux. It may be possible to put the architecture-dependent details into separate files with different go build tags for the different platforms to get this to compile correctly, but it would be far preferable for us to find a solution that doesn't rely on these low-level details.

Thanks,
@ematpl && @matt-royal

@lvarvel
Copy link
Contributor Author

lvarvel commented Feb 24, 2015

Sorry about that. We've made some changes to use build tags.

@lvarvel
Copy link
Contributor Author

lvarvel commented Feb 24, 2015

Related: golang/go#8914

TLDR: os.Rename doesn't work as expected on Windows, and the Golang core team won't fix it. They might add an os.Replace function in go 1.5 that does the right thing (essentially what we've done here).

@emalm
Copy link
Member

emalm commented Feb 25, 2015

Excellent, thanks for the reference to the outstanding issue. If we can remove this with Go 1.5 or later, that would be great.

We tried the entire units/inigo/DATs run on OS X/bosh-lite and it seems fine, so we can merge and push this once ketchup is green. In the meantime, I have a few minor comments to make inline.

Thanks,
Eric

@@ -22,8 +22,8 @@ type CachedDownloader interface {
Fetch(urlToFetch *url.URL, cacheKey string, transformer CacheTransformer, cancelChan <-chan struct{}) (io.ReadCloser, int64, error)
}

func NoopTransform(source, destination string) (int64, error) {
err := os.Rename(source, destination)
func NoopTransform(source string, destination string) (int64, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's idiomatic Go to collapse type declarations for adjacent arguments of the same type, as was done before the change.

Fix file moving to be safe on Windows. A shim was added
that calls into the Win32 API / MoveFileEx that prevents an error
occurring on windows if the destination already exists. This shim might
not be needed once os.Replace lands, possibly in Go 1.5.

See: golang/go#8914

[#88907658]
@mavenraven
Copy link

We've completed the requested changes, waiting for Varvel to give us push access.

@lvarvel
Copy link
Contributor Author

lvarvel commented Feb 25, 2015

Access granted, mavenraven.

For windows compatibility.

We added a test for windows that exercises this.
Windows timer increments in 15.6ms ticks, which caused the eviction test
to fail since all files in the cache (sometimes) have the same timestamp.
The patch adds a sleep before fetching `A' to make sure it has a more
recent timestamp.
@lvarvel lvarvel changed the title Windows likes its files closed before removing them. Add Windows support to cacheddownloader Feb 26, 2015
@emalm emalm merged commit 176d84d into cloudfoundry:master Feb 27, 2015
krishicks added a commit that referenced this pull request Feb 27, 2015
Signed-off-by: Eric Malm <emalm@pivotal.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants