puppet-mongodb icon indicating copy to clipboard operation
puppet-mongodb copied to clipboard

Reorder switches in dbpath_fix find command

Open pavloos opened this issue 5 years ago • 4 comments

Pull Request (PR) description

Fix ordering of switches in dbpath_fix's find command

This Pull Request (PR) fixes the following issues

Fixes #571

pavloos avatar Dec 30 '19 16:12 pavloos

Hi. I gave this a quick look and I'm not sure if this change is correct. The find output differs, depending on the command order. I am not sure if the new output is still correct.

bastelfreak avatar Dec 30 '19 18:12 bastelfreak

My understanding is that this block of code is supposed to run if the ~~output~~ return code of only_if command is 0. This will happen only if grep matches any lines and for that find needs to produce any output which does not happen with -print in its current position. In fact -print could be skipped altogether because it is default if no other expression is specified.

pavloos avatar Dec 30 '19 20:12 pavloos

@pjfbashton can you provide an acceptance test that valides this PR?

bastelfreak avatar Feb 10 '20 16:02 bastelfreak

Apologies for delayed response.

You are actually correct. Proposed solution was not working as intended as it would always return results thus that exec would always run. Existing find command is not correct though because it will never return results and it seems that the correct solution is to drop -print altogether and I have update the PR to that effect.

Please see the following

test 1 - mixed ownership

# find m/ -ls
  2886300      4 drwxr-xr-x   5  root     root         4096 Mar 18 11:47 m
  2886303      4 drwxr-xr-x   2  root     root         4096 Mar 18 11:47 m/3
  2886301      4 drwxr-xr-x   2  mongod   mongod       4096 Mar 18 11:47 m/1
  2886302      4 drwxr-xr-x   2  mongod   mongod       4096 Mar 18 11:47 m/2
  • current solution is wrong - it should return 2 results so that grep matches and exec is run
# find m -not -user mongod -o -not -group mongod -print -quit  | wc -l
0
  • working solution is to actually drop -print altogether
# find m/ -not -user mongod -o -not -group mongod -quit | wc -l
2

test 2 - ownership on all files is wrong

# find m/ -ls
  2886300      4 drwxr-xr-x   5  root     root         4096 Mar 18 11:47 m
  2886303      4 drwxr-xr-x   2  root     root         4096 Mar 18 11:47 m/3
  2886301      4 drwxr-xr-x   2  root     root         4096 Mar 18 11:47 m/1
  2886302      4 drwxr-xr-x   2  root     root         4096 Mar 18 11:47 m/2
  • existing solution returns no results and it should return 4 lines
# find m/ -not -user mongod -o -not -group mongod -print -quit  | wc -l
0
  • no -print solution - correct result
# find m/ -not -user mongod -o -not -group mongod -quit  | wc -l
4

test 3 - ownership on all files is correct

# find m -ls
  2886300      4 drwxr-xr-x   5  mongod   mongod       4096 Mar 18 11:47 m
  2886303      4 drwxr-xr-x   2  mongod   mongod       4096 Mar 18 11:47 m/3
  2886301      4 drwxr-xr-x   2  mongod   mongod       4096 Mar 18 11:47 m/1
  2886302      4 drwxr-xr-x   2  mongod   mongod       4096 Mar 18 11:47 m/2
  • existing solution
# find m/ -not -user mongod -o -not -group mongod -print -quit  | wc -l
0
  • proposed solution
# find m/ -not -user mongod -o -not -group mongod -quit  | wc -l
0

As you can see from above 3 cases only find command without -print works fine.

pavloos avatar Mar 18 '20 12:03 pavloos