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

Refactor and fix find bugs #2273

Merged
merged 1 commit into from
Oct 10, 2017
Merged

Conversation

harshavardhana
Copy link
Member

@harshavardhana harshavardhana commented Oct 6, 2017

  • 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.

@harshavardhana
Copy link
Member Author

Still working on the unit tests, but it is ready for the early eyes.

@codecov-io
Copy link

codecov-io commented Oct 6, 2017

Codecov Report

Merging #2273 into master will increase coverage by 0.43%.
The diff coverage is 21.62%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
cmd/watch.go 0% <ø> (ø) ⬆️
cmd/watch-main.go 0% <ø> (ø) ⬆️
cmd/find-main.go 0% <0%> (ø) ⬆️
cmd/find.go 44.15% <31.25%> (+18.72%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f38471...6c0bec5. Read the comment docs.

@harshavardhana harshavardhana changed the title Fixes find command and bring it to a workable condition. Refactor and fix find bugs Oct 6, 2017
@harshavardhana
Copy link
Member Author

Still working on the unit tests, but it is ready for the early eyes.

Done, ready for review.

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 {
Copy link
Collaborator

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.

Copy link
Member Author

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
Copy link
Collaborator

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?

Copy link
Member Author

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.

@@ -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 {
Copy link
Collaborator

@kannappanr kannappanr Oct 6, 2017

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.

Copy link
Member Author

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
Copy link
Collaborator

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{
Copy link
Collaborator

@ebozduman ebozduman Oct 7, 2017

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?

@harshavardhana harshavardhana force-pushed the find-cleanup branch 3 times, most recently from 4099e2e to e1ed1fc Compare October 7, 2017 02:00
Copy link
Collaborator

@kannappanr kannappanr left a comment

Choose a reason for hiding this comment

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

LGTM

@harshavardhana harshavardhana force-pushed the find-cleanup branch 3 times, most recently from 02dffe5 to 9a436e4 Compare October 9, 2017 07:01
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")
Copy link
Collaborator

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() {
Copy link
Collaborator

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?

Copy link
Member Author

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 './'.
Copy link
Collaborator

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.

Copy link
Member Author

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
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 {
Copy link
Collaborator

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.

Copy link
Member Author

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() {
Copy link
Collaborator

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.

Copy link
Member Author

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 (
Copy link
Collaborator

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.
Copy link
Collaborator

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 != "" {
Copy link
Collaborator

@ebozduman ebozduman Oct 9, 2017

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.

- 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
match = largerSizeMatch(ctx.String("larger"), fileContent.Size)
} else if ctx.String("smaller") != "" {
match = smallerSizeMatch(ctx.String("smaller"), fileContent.Size)
if match && ctx.ignorePattern != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

match here is unncessary

Copy link
Member Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK

Copy link
Collaborator

@ebozduman ebozduman left a comment

Choose a reason for hiding this comment

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

LGTM

@harshavardhana harshavardhana merged commit c10b429 into minio:master Oct 10, 2017
@harshavardhana harshavardhana deleted the find-cleanup branch October 10, 2017 02:45
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