savannah-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Savannah-cvs] administration/infra/bin sv_cvs_root_etc.pl


From: Sylvain Beucler
Subject: [Savannah-cvs] administration/infra/bin sv_cvs_root_etc.pl
Date: Thu, 24 Feb 2005 17:44:42 -0500

CVSROOT:        /cvsroot/administration
Module name:    administration
Branch:         
Changes by:     Sylvain Beucler <address@hidden>        05/02/24 22:44:42

Modified files:
        infra/bin      : sv_cvs_root_etc.pl 

Log message:
        Mimics authorized_keys support: read the file, and if it is already 
matching what we plan to write in it, just don't write

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/administration/administration/infra/bin/sv_cvs_root_etc.pl.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: administration/infra/bin/sv_cvs_root_etc.pl
diff -u administration/infra/bin/sv_cvs_root_etc.pl:1.4 
administration/infra/bin/sv_cvs_root_etc.pl:1.5
--- administration/infra/bin/sv_cvs_root_etc.pl:1.4     Thu Feb 10 10:43:55 2005
+++ administration/infra/bin/sv_cvs_root_etc.pl Thu Feb 24 22:44:42 2005
@@ -19,6 +19,18 @@
 # along with Savane; if not, write to the Free Software Foundation,
 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
+
+# TODO:
+# - If the first group if already more recent that /etc/group, maybe we can 
stop the script directly. This does not handle the case where this first group 
was manually edited since the last /etc/group change, but that should only 
occur rarely
+# - Create an array of users that belong to each group, and only add these 
users to etc/passwd
+# - Remove users that are not in the group
+# Code to keep meanwhile:
+# @passwd = grep {
+#     my ($user, $uid) = split(":", $_);
+#     ($uid > 1000) 1 : 0;
+# } @passwd;
+
+
 use strict;
 use Savannah;
 
@@ -70,12 +82,6 @@
 # Filtering
 ##
 
-# TODO: Remove users/groups that are not in the database
address@hidden = grep {
-#    my ($user, $uid) = split(":", $_);
-#    ($uid > 1000) 1 : 0;
-#} @passwd;
-
 my %group_content;
 # Builds the groups hash
 # Add www members to each webgroup
@@ -104,10 +110,6 @@
 my $group_mtime = (stat("/etc/group"))[9];
 
 
-# TODO Optimizations:
-# - If the first group if already more recent that /etc/group, maybe we can 
stop the script directly. This does not handle the case where this first group 
was manually edited since the last /etc/group change, but that should only 
occur rarely
-# - Mimics authorized_keys support: read the file, and if it is already 
matching what we plan to write in it, just don't write
-# - Create an array of users that belong to each group, and only add these 
users to etc/passwd
 # Process active public projects
 for my $project_name (sort @projects) {
     chomp($project_name);
@@ -128,10 +130,24 @@
 
 unlink($lockfile);
 
-
+# Copies the content to the given file, only if the file does not
+# already contain the content (write access is more time consuming
+# than read access)
 sub copy() {
     my ($content, $file) = @_;
-    open(OUT, "> $file");
-    print OUT $content;
-    close(OUT);
+
+    open(IN, "< $file");
+    my $previous_content;
+    # slurp mode
+    my $backup = $/;
+    undef $/;
+    $previous_content = <IN>;
+    $/ = $backup;
+    close(IN);
+
+    if ($previous_content ne $content) {
+       open(OUT, "> $file");
+       print OUT $content;
+       close(OUT);
+    }
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]