]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 368250: collectstats.pl creates files with wrong ownership
authorFrédéric Buclin <LpSolit@gmail.com>
Sat, 26 Nov 2011 13:18:04 +0000 (14:18 +0100)
committerFrédéric Buclin <LpSolit@gmail.com>
Sat, 26 Nov 2011 13:18:04 +0000 (14:18 +0100)
r/a=mkanat

Bugzilla/Install/Filesystem.pm
collectstats.pl

index 15106dab995e87add2c3fb6d75b902010a88eda0..c5215ecfaca1eee229a5af867d76e934729e2feb 100644 (file)
@@ -46,6 +46,7 @@ our @EXPORT = qw(
     update_filesystem
     create_htaccess
     fix_all_file_permissions
+    fix_dir_permissions
     fix_file_permissions
 );
 
@@ -645,6 +646,26 @@ sub _update_old_charts {
     } 
 }
 
+sub fix_dir_permissions {
+    my ($dir) = @_;
+    return if ON_WINDOWS;
+    # Note that _get_owner_and_group is always silent here.
+    my ($owner_id, $group_id) = _get_owner_and_group();
+
+    my $perms;
+    my $fs = FILESYSTEM();
+    if ($perms = $fs->{recurse_dirs}->{$dir}) {
+        _fix_perms_recursively($dir, $owner_id, $group_id, $perms);
+    }
+    elsif ($perms = $fs->{all_dirs}->{$dir}) {
+        _fix_perms($dir, $owner_id, $group_id, $perms);
+    }
+    else {
+        # Do nothing. We know nothing about this directory.
+        warn "Unknown directory $dir";
+    }
+}
+
 sub fix_file_permissions {
     my ($file) = @_;
     return if ON_WINDOWS;
@@ -843,6 +864,12 @@ Params:      C<$output> - C<true> if you want this function to print
 
 Returns:     nothing
 
+=item C<fix_dir_permissions>
+
+Given the name of a directory, its permissions will be fixed according to
+how they are supposed to be set in Bugzilla's current configuration.
+If it fails to set the permissions, a warning will be printed to STDERR.
+
 =item C<fix_file_permissions>
 
 Given the name of a file, its permissions will be fixed according to
index 007669fad01ea68b0eab220e421d9035cf3dc63d..1487e5a72e8cca992df1f1cbf3e6f112fca95907 100755 (executable)
@@ -41,6 +41,7 @@ use Bugzilla::Search;
 use Bugzilla::User;
 use Bugzilla::Product;
 use Bugzilla::Field;
+use Bugzilla::Install::Filesystem qw(fix_dir_permissions);
 
 my %switch;
 GetOptions(\%switch, 'help|h', 'regenerate');
@@ -139,32 +140,28 @@ my $tstart = time;
 my @myproducts = Bugzilla::Product->get_all;
 unshift(@myproducts, "-All-");
 
-foreach (@myproducts) {
-    my $dir = "$datadir/mining";
-
-    &check_data_dir ($dir);
+my $dir = "$datadir/mining";
+if (!-d $dir) {
+    mkdir $dir or die "mkdir $dir failed: $!";
+    fix_dir_permissions($dir);
+}
 
+foreach (@myproducts) {
     if ($switch{'regenerate'}) {
         regenerate_stats($dir, $_, \%bug_resolution, \%bug_status, \%removed);
     } else {
         &collect_stats($dir, $_);
     }
 }
+# Fix permissions for all files in mining/.
+fix_dir_permissions($dir);
+
 my $tend = time;
 # Uncomment the following line for performance testing.
 #print "Total time taken " . delta_time($tstart, $tend) . "\n";
 
 CollectSeriesData();
 
-sub check_data_dir {
-    my $dir = shift;
-
-    if (! -d $dir) {
-        mkdir $dir, 0755;
-        chmod 0755, $dir;
-    }
-}
-
 sub collect_stats {
     my $dir = shift;
     my $product = shift;
@@ -250,7 +247,6 @@ FIN
     }
     print DATA (join '|', @row) . "\n";
     close DATA;
-    chmod 0644, $file;
 }
 
 sub get_old_data {
@@ -406,14 +402,13 @@ FIN
             foreach (@resolutions) { print DATA "|$bugcount{$_}"; }
             print DATA "\n";
         }
-        
+
         # Finish up output feedback for this product.
         my $tend = time;
         print "\rRegenerating $product \[100.0\%] - " .
             delta_time($tstart, $tend) . "\n";
-            
+
         close DATA;
-        chmod 0640, $file;
     }
 }