Merge lp:~percona-toolkit-dev/percona-toolkit/fix-942114-bad-find-usage into lp:percona-toolkit/2.1

Proposed by Brian Fraser
Status: Merged
Approved by: Daniel Nichter
Approved revision: 355
Merged at revision: 381
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-942114-bad-find-usage
Merge into: lp:percona-toolkit/2.1
Diff against target: 71 lines (+27/-7)
2 files modified
bin/pt-stalk (+3/-3)
t/pt-stalk/pt-stalk.t (+24/-4)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-942114-bad-find-usage
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+120920@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Do we want -warn? The man page says "The default behaviour corresponds to -warn if standard input is a tty, and to -nowarn otherwise." pt-stalk is often run as a daemon, so STDIN won't be a tty.

Revision history for this message
Brian Fraser (fraserbn) wrote :

That's to trigger the warning during the tests, otherwise we could have a regression and never notice. And also, a slightly less valid and rather more paranoid reason, I've learnt not to trust defaults in shell commands : D

Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-stalk'
2--- bin/pt-stalk 2012-08-14 15:11:41 +0000
3+++ bin/pt-stalk 2012-08-23 06:39:00 +0000
4@@ -1031,14 +1031,14 @@
5 local retention_time="$2"
6
7 # Delete collect files which more than --retention-time days old.
8- find "$dir" -type f -mtime +$retention_time -exec rm -f '{}' \;
9+ find "$dir" -warn -type f -mtime +$retention_time -exec rm -f '{}' \;
10
11 local oprofile_dir="/var/lib/oprofile/samples"
12 if [ -d "$oprofile_dir" ]; then
13 # "pt_collect_" here needs to match $CMD_OPCONTROL --save=pt_collect_$p
14 # in collect(). TODO: fix this
15- find "$oprofile_dir" -type d -name 'pt_collect_*' \
16- -depth -mtime +$retention_time -exec rm -rf '{}' \;
17+ find "$oprofile_dir" -warn -depth -type d -name 'pt_collect_*' \
18+ -mtime +$retention_time -exec rm -rf '{}' \;
19 fi
20 }
21
22
23=== modified file 't/pt-stalk/pt-stalk.t'
24--- t/pt-stalk/pt-stalk.t 2012-06-04 15:53:44 +0000
25+++ t/pt-stalk/pt-stalk.t 2012-08-23 06:39:00 +0000
26@@ -23,9 +23,6 @@
27 if ( !$dbh ) {
28 plan skip_all => 'Cannot connect to sandbox master';
29 }
30-else {
31- plan tests => 27;
32-}
33
34 my $cnf = "/tmp/12345/my.sandbox.cnf";
35 my $pid_file = "/tmp/pt-stalk.pid.$PID";
36@@ -282,6 +279,28 @@
37 "Not stalking, pt-stalk is not running"
38 );
39
40+# ############################################################################
41+# bad "find" usage in purge_samples gives
42+# https://bugs.launchpad.net/percona-toolkit/+bug/942114
43+# ############################################################################
44+
45+use File::Temp qw( tempdir );
46+
47+my $tempdir = tempdir( CLEANUP => 1 );
48+
49+my $script = <<"EOT";
50+. $trunk/bin/pt-stalk
51+purge_samples $tempdir 10000 2>&1
52+EOT
53+
54+$output = `$script`;
55+
56+unlike(
57+ $output,
58+ qr/\Qfind: warning: you have specified the -depth option/,
59+ "Bug 942114: no bad find usage"
60+);
61+
62 # #############################################################################
63 # Done.
64 # #############################################################################
65@@ -289,4 +308,5 @@
66 diag(`rm $log_file 2>/dev/null`);
67 diag(`rm -rf $dest 2>/dev/null`);
68 ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
69-exit;
70+
71+done_testing;

Subscribers

People subscribed via source and target branches