Subject: | Only overwrite file if changed (in commit method of ConfigFile) |
This patch is an enhancement. Whenever a commit is run, the file is regenerated. This seems unnecessary as timestamps are changed, the file disappears for a split second, etc.
The patch supplied will do a file comparison between the temporary file and the original file. If they are the same, then no change is made and the temporary file is removed.
This seems a "better" way of handling file changes.
*** PasswdFile.pm.original Tue Dec 14 16:58:14 2004
--- PasswdFile.pm Tue Dec 14 16:58:06 2004
***************
*** 25,30 ****
--- 25,33 ----
# The key is the username and the array contents are the next six fields
# found in the password file.
+ # Used to hold the nis entries, where the username field begins with a +
+ my @nisentries;
+
# Preloaded methods go here.
# Read the file and build the data structures
***************
*** 33,39 ****
while (<$fh>) {
chop;
! $this->user(split /:/);
}
return 1;
}
--- 36,46 ----
while (<$fh>) {
chop;
! if (/^\+/) {
! push @nisentries, $_;
! } else {
! $this->user(split /:/);
! }
}
return 1;
}
***************
*** 119,124 ****
--- 126,134 ----
next if ($user eq "root");
print $fh join(":", $user, $this->user($user)), "\n" or return 0;
}
+ foreach $_ (@nisentries) {
+ print $fh $_, "\n" or return 0;
+ }
return 1;
}