[Bps-public-commit] Test-Chimps-Client branch, master, updated. 63f5acb1da21d3cd7d70f7094d869cb6196c0e11

Alex Vandiver alexmv at bestpractical.com
Thu May 27 11:51:00 EDT 2010


The branch, master has been updated
       via  63f5acb1da21d3cd7d70f7094d869cb6196c0e11 (commit)
       via  25b91a8316383cf840fbf765b8198b4cc838cb9c (commit)
      from  9915da70ba6bfead7116815512595889a272879c (commit)

Summary of changes:
 examples/tmp_cleaner.pl          |   50 ++++++++++++++++++++++++++++++++++++++
 lib/Test/Chimps/Smoker/Source.pm |   33 ++++++++++++++++---------
 2 files changed, 71 insertions(+), 12 deletions(-)
 create mode 100644 examples/tmp_cleaner.pl

- Log -----------------------------------------------------------------
commit 25b91a8316383cf840fbf765b8198b4cc838cb9c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Mar 30 22:36:38 2010 -0400

    Allow multiple ordered cleaner programs

diff --git a/lib/Test/Chimps/Smoker/Source.pm b/lib/Test/Chimps/Smoker/Source.pm
index beaf5f4..72b0e9e 100644
--- a/lib/Test/Chimps/Smoker/Source.pm
+++ b/lib/Test/Chimps/Smoker/Source.pm
@@ -130,16 +130,22 @@ sub do_checkout {
         }
     }
 
-    if (defined( my $cmd = $self->clean_cmd )) {
-        print "Going to run project cleaner '$cmd'\n";
-        my @args = (
-            '--project', $self->name,
-            '--config', $self->smoker->config_file,
-        );
-        open my $fh, '-|', join(' ', $cmd, @args)
-            or die "Couldn't run `". join(' ', $cmd, @args) ."`: $!";
-        $self->cleaner( do { local $/; <$fh> } );
-        close $fh;
+    my $clean = $self->clean_cmd;
+    if (defined $clean) {
+        $clean = [ $clean ] unless ref $clean_cmd;
+        my @data;
+        for my $cmd ( @{$clean} ) {
+            print "Going to run project cleaner '$cmd'\n";
+            my @args = (
+                '--project', $self->name,
+                '--config', $self->smoker->config_file,
+            );
+            open my $fh, '-|', join(' ', $cmd, @args)
+                or die "Couldn't run `". join(' ', $cmd, @args) ."`: $!";
+            push @data, do { local $/; scalar <$fh> };
+            close $fh;
+        }
+        $self->cleaner( \@data );
     }
     return @libs;
 }
@@ -148,7 +154,10 @@ sub do_clean {
     my $self = shift;
     $self->chdir;
 
-    if (defined( my $cmd = $self->clean_cmd )) {
+    my $clean = $self->clean_cmd;
+    $clean = [ $clean ] if defined $clean and not ref $clean;
+    for my $pre (@{ $self->cleaner || [] }) {
+        my $cmd = shift @{$clean};
         my @args = (
             '--project', $self->name,
             '--config', $self->smoker->config_file,
@@ -156,7 +165,7 @@ sub do_clean {
         );
         open my $fh, '|-', join(' ', $cmd, @args)
             or die "Couldn't run `". join(' ', $cmd, @args) ."`: $!";
-        print $fh $self->cleaner;
+        print $fh $pre;
         close $fh;
     }
 

commit 63f5acb1da21d3cd7d70f7094d869cb6196c0e11
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Mar 30 22:36:53 2010 -0400

    Add a /tmp cleaner program

diff --git a/examples/tmp_cleaner.pl b/examples/tmp_cleaner.pl
new file mode 100644
index 0000000..729513b
--- /dev/null
+++ b/examples/tmp_cleaner.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+use File::Find;
+use constant TMPDIR => "/tmp";
+
+my @args = splice @ARGV;
+unless ( grep $_ eq '--clean', @args ) {
+    print "$_\n" for file_list();
+} else {
+    my %skip;
+    $skip{$_}++ for split /\n/, do {local $/; scalar <>};
+    my @destroy = grep {!$skip{$_}} file_list();
+    for (@destroy) {
+        if (-d $_) {
+            rmdir($_) or die "Can't rmdir $_: $!";
+        } else {
+            unlink($_) or die "Can't unlink $_: $!";
+        }
+    }
+}
+
+sub file_list {
+    my %open;
+    # Find all the open files under /tmp
+    $open{$_}++ for map {s/^n//;$_} grep {/^n(.*)/}
+        split /\n/, `lsof +D @{[TMPDIR]} -F 'n'`;
+
+    for my $file (keys %open) {
+        # Add the parent dirs, as well
+        $open{$file}++ while $file ne "/" and $file =~ s{/[^/]+$}{};
+    }
+
+    my @found;
+    finddepth(
+        {
+            preprocess => sub {
+                # Skip directories which had open files in them
+                return grep {not $open{$File::Find::dir."/".$_}} @_;
+            },
+            wanted => sub {
+                # Everything else gets listed
+                push @found, $File::Find::name;
+            }
+        },
+        TMPDIR
+    );
+    return @found;
+}

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list