-
Notifications
You must be signed in to change notification settings - Fork 560
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
Refactor and fix find bugs #2273
Conversation
Still working on the unit tests, but it is ready for the early eyes. |
f065c8f
to
36feb55
Compare
Codecov Report
@@ Coverage Diff @@
## master #2273 +/- ##
==========================================
+ Coverage 10.12% 10.55% +0.43%
==========================================
Files 100 100
Lines 9582 9598 +16
==========================================
+ Hits 970 1013 +43
+ Misses 8477 8450 -27
Partials 135 135
Continue to review full report at Codecov.
|
36feb55
to
11c7faa
Compare
11c7faa
to
46a6dff
Compare
Done, ready for review. |
46a6dff
to
4e9c547
Compare
4e9c547
to
bfbd832
Compare
cmd/find-main.go
Outdated
for _, arg := range args { | ||
if strings.TrimSpace(arg) == "" { | ||
fatalIf(errInvalidArgument().Trace(args...), "Unable to validate empty argument.") | ||
} | ||
} | ||
|
||
// Extract input URLs. | ||
URLs := ctx.Args() | ||
for _, url := range URLs { |
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.
comment like "Validate the extracted URLs. " will be good.
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
cmd/find-main.go
Outdated
fatalIf(err.Trace(ctx.String("newer")), "Unable to parse input threshold value into time.Time") | ||
} | ||
|
||
var e error |
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.
Why can't we use already declared 'err' variable?
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.
they both have different type.
bfbd832
to
1c860b1
Compare
@@ -74,6 +73,14 @@ func (f findMessage) JSON() string { | |||
func nameMatch(pattern, path string) bool { | |||
matched, e := filepath.Match(pattern, filepath.Base(path)) | |||
errorIf(probe.NewError(e).Trace(pattern, path), "Unable to match with input pattern") | |||
if !matched { |
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.
When will this happen? Meaning do you have an example for me to better understand when this piece of code will be needed.
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 a compatibility code.. it will happen when the filepath.Match() didn't match say for example if user said mc find pkg --name console
cmd/find.go
Outdated
@@ -145,30 +115,95 @@ func doFindExec(ctx *cli.Context, fileContent contentMessage) { | |||
console.Println(string(out.Bytes())) | |||
} | |||
|
|||
// doFindWatch - enables listening on the input path, listens for all file/object | |||
// watchFind - enables listening on the input path, listens for all file/object |
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.
Line 113 above, looks like unreachable code. If it is unreachable, we need to remove it.
@@ -67,17 +70,13 @@ var ( | |||
Name: "smaller", | |||
Usage: "Match all objects smaller than specified size in units (see UNITS)", | |||
}, | |||
cli.StringFlag{ | |||
cli.UintFlag{ |
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.
Can we have the flags alphabetically sorted in the usage below, line#97, for readability purposes, and here for debugging purposes?
4099e2e
to
e1ed1fc
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.
LGTM
02dffe5
to
9a436e4
Compare
cmd/find-main.go
Outdated
) | ||
if ctx.String("older") != "" { | ||
olderThan, err = parseTime(ctx.String("older")) | ||
fatalIf(err.Trace(ctx.String("older")), "Unable to parse input threshold value into time.Time") |
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.
time.Time
in the error message not necessarily means something useful to the end-user.
We need to have our messages in the simplest possible way without assuming anything about the end-user's programming knowledge and/or background.
This also applies to line#232.
cmd/find-main.go
Outdated
if ctx.Bool("watch") && !strings.Contains(args[0], "/") { | ||
console.Println("Users must specify a bucket name for watch") | ||
console.Fatalln() | ||
if !ctx.Args().Present() { |
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 there any specific reason you preferred to use ctx.Args
instead of args
?
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.
No reason.
cmd/find-main.go
Outdated
if !ctx.Args().Present() { | ||
args = []string{"./"} // No args just default to present directory. | ||
} else if ctx.Args().Get(0) == "." { | ||
ctx.Args()[0] = "./" // If the arg is '.' treat it as './'. |
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.
Did you mean args[0] = "./"
here or is this for a reason?
If so, I guess we should use args
all over after assigning args := ctx.Args()
is done.
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.
No reason.
9a436e4
to
75fd5e4
Compare
cmd/find-main.go
Outdated
for _, arg := range args { | ||
if strings.TrimSpace(arg) == "" { | ||
fatalIf(errInvalidArgument().Trace(args...), "Unable to validate empty argument.") | ||
} | ||
} | ||
|
||
// Extract input URLs and validate. | ||
URLs := ctx.Args() | ||
for _, url := range URLs { |
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.
Why not have for _, url := range args {
and get rid of line#178 completely?
Also change the comment at line#177 to // Extract input urls and validate.
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 can.
|
||
if !ctx.Args().Present() { | ||
args = []string{"."} | ||
if !args.Present() { |
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.
Checks and codes between line#222 and line#227 are already covered as part of the call to checkFindSyntax(ctx)
. So, they are unnecessary and can be removed.
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 needed for argument adjustment.
cmd/find-main.go
Outdated
fatalIf(err.Trace(args...), "Unable to initialize `"+args[0]+"`") | ||
fatalIf(err.Trace(args...), "Unable to initialize `"+args[0]+"`.") | ||
|
||
var ( |
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 could be declared like var olderThan, newerThan time.Time
cmd/find.go
Outdated
return path | ||
} | ||
// Remove the requested prefix from consideration, maxDepth is | ||
// only considered for all other levels excluding th starting prefix. |
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.
...excluding th? starting prefix.
?
cmd/find.go
Outdated
match = smallerSizeMatch(ctx.String("smaller"), fileContent.Size) | ||
if ctx.ignorePattern != "" { | ||
match = !pathMatch(ctx.ignorePattern, fileContent.Key) | ||
} else if ctx.namePattern != "" { |
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.
To be able to combine find options/choices with AND
, these elses need to be removed.
75fd5e4
to
a8631aa
Compare
- Watch now avoids an unnecessary waitgroup and simplifies overall flow. - Watch now honors maxDepth parameter as well. - Parsing logic is fully outside in the mainFind() function. - Enhance and fix behavior of nameMatch to comply with unix find behavior. - Enhance and fix behavior of maxdepth to comply with unix find behavior. Fixes minio#2272
a8631aa
to
6c0bec5
Compare
match = largerSizeMatch(ctx.String("larger"), fileContent.Size) | ||
} else if ctx.String("smaller") != "" { | ||
match = smallerSizeMatch(ctx.String("smaller"), fileContent.Size) | ||
if match && ctx.ignorePattern != "" { |
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.
match here is unncessary
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 for completeness.. otherwise logically it is hard.
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.
OK
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
find behavior.
find behavior.