~percona-toolkit-dev/percona-toolkit/fix-pqd-distill-bugs

« back to all changes in this revision

Viewing changes to lib/VersionCheck.pm

  • Committer: Daniel Nichter
  • Date: 2013-02-21 22:59:49 UTC
  • mto: This revision was merged to the branch mainline in revision 529.
  • Revision ID: daniel@percona.com-20130221225949-yypcyh6j2z0aa8c2
Simplify checking for  .bzr/ to auto-disable --version-check in dev and test envs.  Update t/pt-archiver/version_check.t.  Need to update all other tools...

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
local $Data::Dumper::Sortkeys  = 1;
38
38
local $Data::Dumper::Quotekeys = 0;
39
39
 
40
 
use Digest::MD5    qw(md5_hex);
41
 
use Sys::Hostname  qw(hostname);
 
40
use Digest::MD5 qw(md5_hex);
 
41
use Sys::Hostname qw(hostname);
42
42
use File::Basename qw();
43
43
use File::Spec;
44
 
 
45
 
use IPC::Cmd qw(can_run);
46
 
use FindBin  qw();
47
 
use Cwd      qw();
 
44
use FindBin qw();
48
45
 
49
46
eval {
50
47
   require Percona::Toolkit;
104
101
   my $instances = $args{instances} || [];
105
102
   my $instances_to_check;
106
103
 
107
 
   eval {
108
 
      if (exists $ENV{PERCONA_VERSION_CHECK} && !$ENV{PERCONA_VERSION_CHECK}) {
109
 
         PTDEBUG && _d('--version-check disabled by PERCONA_VERSION_CHECK=0');
 
104
   # This sub should only be called if $o->get('version-check') is true,
 
105
   # and it is by default because the option is on by default in PT 2.2.
 
106
   # However, we do not want dev and testing to v-c, so even though this
 
107
   # sub is called, force should be false because $o->got('version-check')
 
108
   # is false, then check for a .bzr dir which indicates dev or testing. 
 
109
   if ( !$args{force} ) {
 
110
      if ( $FindBin::Bin && -d "$FindBin::Bin/../.bzr" ) {
 
111
         PTDEBUG && _d("$FindBin::Bin/../.bzr disables --version-check");
110
112
         return;
111
113
      }
112
 
 
113
 
      if ( !$ENV{PERCONA_FORCE_VERSION_CHECK} ) {
114
 
         # Check if we're running from a bzr repo, and that repo is ours.
115
 
         if ( my $bzr = can_run('bzr') ) {
116
 
            my $percona_repo = Percona::Toolkit::bzr_repo();
117
 
            my $info         = `$bzr info 2>/dev/null`;
118
 
            if ( $info && $info =~ /\Q$percona_repo/ ) {
119
 
               PTDEBUG && _d('--version-check disabled by running from a bzr checkout');
120
 
               return;
121
 
            }
122
 
         }
123
 
 
124
 
         # Perhaps bzr isn't available, but we're still running from
125
 
         # a bzr repo. Brian occasionally does this when running in
126
 
         # his VMs, since it's usually easier than installing bzr.
127
 
         # So check if $Cwd/.bzrignore or $FindBin::Bin/../.bzrignore
128
 
         # exist, and if they do, check if it has this line:
129
 
         # special/percona-toolkit/v-c-internal
130
 
         for my $dir ( Cwd::cwd(), File::Spec->updir($FindBin::Bin) ) {
131
 
            my $ignore = File::Spec->catfile($dir, '.bzrignore');
132
 
            next unless -r $ignore;
133
 
            open my $fh, '<', $ignore or next;
134
 
            chomp(my $file_contents = do { local $/ = undef; <$fh> });
135
 
            close $fh;
136
 
            if ( $file_contents =~ m{special/percona-toolkit/v-c-internal} ) {
137
 
               PTDEBUG && _d('--version-check disabled by running from a bzr checkout');
138
 
               return;
139
 
            }
140
 
         }
141
 
      }
142
 
 
 
114
   }
 
115
 
 
116
   eval {
143
117
      # Name and ID the instances.  The name is for debugging,
144
118
      # and the ID is what the code uses to prevent double-checking.
145
119
      foreach my $instance ( @$instances ) {
195
169
   }
196
170
 
197
171
   # Always update the vc file, even if the version check fails.
198
 
   eval {
199
 
      # Update the check time for things we checked.  I.e. if we
200
 
      # didn't check it, do _not_ update its time.
201
 
      update_check_times(
202
 
         instances => $instances_to_check,
203
 
         vc_file   => $args{vc_file},  # testing
204
 
         now       => $args{now},      # testing
205
 
      );
206
 
   };
207
 
   if ( $EVAL_ERROR ) {
208
 
      PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR);
 
172
   if ( @$instances_to_check ) {
 
173
      eval {
 
174
         # Update the check time for things we checked.  I.e. if we
 
175
         # didn't check it, do _not_ update its time.
 
176
         update_check_times(
 
177
            instances => $instances_to_check,
 
178
            vc_file   => $args{vc_file},  # testing
 
179
            now       => $args{now},      # testing
 
180
         );
 
181
      };
 
182
      if ( $EVAL_ERROR ) {
 
183
         PTDEBUG && _d('Error updating version check file:', $EVAL_ERROR);
 
184
      }
209
185
   }
210
186
 
211
187
   if ( $ENV{PTDEBUG_VERSION_CHECK} ) {