Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

dep: update calculatePrune to not assume "/" as file separator #780

Merged
merged 2 commits into from
Jun 25, 2017

Conversation

ibrasho
Copy link
Collaborator

@ibrasho ibrasho commented Jun 21, 2017

What does this do / why do we need it?

As reported in #775 , dep prune deletes all directories in vendor. After digging in, the culpirt seems to be calculatePrune in txn_writer.go.

This line assume all paths use / as a separator. And therefore, causes this check to be always true (on filesystems that don't use /) thus adding all directories to the toDelete slice.

What should your reviewer look out for in this PR?

Generic review.

Which issue(s) does this PR fix?

fixes #775

Add a test for dep.calculatePrune

Signed-off-by: Ibrahim AshShohail <[email protected]>
@ibrasho ibrasho force-pushed the fix-prune-bug-on-windows branch from 0c1c8ea to 07d30f6 Compare June 21, 2017 00:20
@andreynering
Copy link

I didn't look deep in the code, but maybe it should call filepath.ToSlash(path) on both sides before doing any comparison?

@ibrasho ibrasho force-pushed the fix-prune-bug-on-windows branch from 07d30f6 to a9cd3d8 Compare June 21, 2017 12:07
@ibrasho
Copy link
Collaborator Author

ibrasho commented Jun 21, 2017

Actually, the filepath.ToSlash is not needed. We are comparing file paths and not import paths. I've updated the commit.

@ibrasho ibrasho force-pushed the fix-prune-bug-on-windows branch 3 times, most recently from 05e9e87 to 0016724 Compare June 21, 2017 19:54
@ibrasho ibrasho requested a review from darkowlzz June 22, 2017 09:27
@ibrasho
Copy link
Collaborator Author

ibrasho commented Jun 22, 2017

@darkowlzz I think we can merge this now. But I'll like another pair of eyes to ensure I didn't miss anything. 😁

Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

Great to see test for calculatePrune.
I don't see anything missing. Just little improvement in the test failure text 👍

}

if !reflect.DeepEqual(want, got) {
t.Fatalf("expected %s, got %s", want, got)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make this more informative. Previously, I used to do the same but Sam asked me to make the failures more informative. Something like:

t.Fatalf("Calculated prune paths are not as expected: \n\t(GOT) %v\n\t(WNT) %v", got, want)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes total sense. 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've removed the tabs since they are not needed here. An error would like this now:

--- FAIL: TestCalculatePrune (0.00s)
	txn_writer_test.go:602: calculated prune paths are not as expected.
		(WNT) [/private/var/folders/hb/pdqmtgn954zbj319w8djtncr0000gn/T/gotest236842704/vendor/github.com/prune/pkg/sub /private/var/folders/hb/pdqmtgn954zbj319w8djtncr0000gn/T/gotest236842704/vendor/github.com/prune/pkg]
		(GOT) [/private/var/folders/hb/pdqmtgn954zbj319w8djtncr0000gn/T/gotest236842704/vendor/github.com/prune/pkg/sub /private/var/folders/hb/pdqmtgn954zbj319w8djtncr0000gn/T/gotest236842704/vendor/github.com/prune/pkg /private/var/folders/hb/pdqmtgn954zbj319w8djtncr0000gn/T/gotest236842704/vendor/github.com/prune]

@ibrasho ibrasho force-pushed the fix-prune-bug-on-windows branch 3 times, most recently from 2383dce to a2f09dc Compare June 22, 2017 14:41
@ibrasho
Copy link
Collaborator Author

ibrasho commented Jun 23, 2017

AppVeyor is stuck again. 😞

@ibrasho ibrasho closed this Jun 23, 2017
@ibrasho ibrasho reopened this Jun 23, 2017
dep.calculatePrune assumes "/" is the file separtor. This change fixes
an issue caused by that on Windows.

Fixes golang#775

Signed-off-by: Ibrahim AshShohail <[email protected]>
@ibrasho ibrasho force-pushed the fix-prune-bug-on-windows branch from a2f09dc to 30ba901 Compare June 23, 2017 13:57
Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

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

Looks ready 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dep prune is deleting the entire folder (on Windows only)
4 participants