-
Notifications
You must be signed in to change notification settings - Fork 77
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
Adds .tsuruignore file support #25
Conversation
tsuru/client/deploy_test.go
Outdated
c.Assert(headers, check.DeepEquals, expected) | ||
} | ||
|
||
func (s *S) TestIgnoreRelativeFolder(c *check.C) { |
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'd replace folder
with directory
or dir
tsuru/client/deploy_test.go
Outdated
c.Assert(contents, check.IsNil) | ||
} | ||
|
||
func (s *S) TestIgnoreFolder(c *check.C) { |
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'd replace folder
with directory
or dir
@@ -1,7 +1,3 @@ | |||
// Copyright 2016 tsuru-client authors. All rights reserved. |
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 this was removed by mistake, we need the header on every file.
tsuru/client/deploy.go
Outdated
@@ -290,13 +366,36 @@ func targz(ctx *cmd.Context, destination io.Writer, filepaths ...string) error { | |||
if err != nil { | |||
return err | |||
} | |||
wd, errWd := os.Getwd() | |||
if errWd != nil { | |||
return err |
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 you mean't return errWd
. I think you can also rename errWd
to err
tsuru/client/deploy.go
Outdated
@@ -348,11 +447,38 @@ func addDir(writer *tar.Writer, dirpath string) error { | |||
if err != nil { | |||
return err | |||
} | |||
wd, errWd := os.Getwd() | |||
if errWd != nil { | |||
return err |
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.
Same as before
Codecov Report@@ Coverage Diff @@
## master #25 +/- ##
==========================================
- Coverage 67.54% 67.34% -0.21%
==========================================
Files 34 34
Lines 6335 6403 +68
==========================================
+ Hits 4279 4312 +33
- Misses 1441 1464 +23
- Partials 615 627 +12
Continue to review full report at Codecov.
|
tsuru/client/deploy.go
Outdated
if err != nil { | ||
return err | ||
} | ||
fiName := filepath.Join(wd, fi.Name()) | ||
if fi.IsDir() { |
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 lines 375-383 can be moved to before the if
statement (so you can remove the ones in 389-397).
I think there is some repetition that can be avoided by moving the checks to the begin of addDir and addFile. |
tsuru/client/deploy.go
Outdated
for _, pattern := range ignorePatterns { | ||
ignPats, errProc := processTsuruIgnore(pattern, context.Args...) | ||
if errProc != nil { | ||
return err |
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.
return errProc
tsuru/client/deploy.go
Outdated
return nil, err | ||
} | ||
for i := range paths { | ||
if dir == "." { |
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.
Is this if
necessary? Couldn't this loop always do paths[i] = filepath.Join(dir, paths[i])
?
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.
It is, we got this as a bug while uploading static
into lab so without It, the path would be only paths[i]
and It would never match glob
on the root dir
tsuru/client/deploy.go
Outdated
return nil, err | ||
} | ||
defer os.Chdir(old) | ||
for _, dir := range dirPath { |
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.
It would be better to rename this vars to for _, dirPath := range dirPaths
as dir
is also used inside the for body.
tsuru/client/deploy.go
Outdated
} | ||
paths[i] = filepath.Join(dir, paths[i]) | ||
} | ||
dir, err := os.Open(dir) |
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.
You need to call dir.Close()
after the Readdir
call.
tsuru/client/deploy.go
Outdated
defer file.Close() | ||
patterns := []string{} | ||
scanner := bufio.NewScanner(file) | ||
scanner.Split(bufio.ScanLines) |
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.
ScanLines is the default splitter, no need for this line.
tsuru/client/deploy.go
Outdated
scanner.Split(bufio.ScanLines) | ||
for scanner.Scan() { | ||
pattern := scanner.Text() | ||
patterns = append(patterns, pattern) |
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.
Simply patterns = append(patterns, scanner.Text())
tsuru/client/deploy.go
Outdated
if fi.IsDir() { | ||
for _, p := range ignoreList { |
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.
It would be more efficient for ignoreList
to be a var ignoreSet map[string]struct{}
. This way you could ignore patterns in O(1) by doing:
if _, inSet := ignoreSet[fiName]; !inSet {
continue
}
return errProc rename vars to `for _, dirPath := range dirPaths` call dir.Close() after the Readdir simplify scanner append
ignoreSet is a map[string]struct{} that allows better comparison to know If the pattern has matched or not
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.
LGTM
This LGTM, what do you think, @cezarsa ? |
Solving tsuru/tsuru#1512