Skip Menu |

This queue is for tickets about the Unix-ConfigFile CPAN distribution.

Report information
The Basics
Id: 8963
Status: new
Priority: 0/
Queue: Unix-ConfigFile

People
Owner: Nobody in particular
Requestors: tonvoon [...] mac.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



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; }
[guest - Fri Dec 17 04:42:29 2004]: Show quoted text
> 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.
Sorry, attached the wrong patch. Trying again.
*** Unix-ConfigFile-0.06.original/ConfigFile.pm Tue May 2 16:49:57 2000 --- Unix-ConfigFile-0.06/ConfigFile.pm Fri Dec 17 09:30:42 2004 *************** *** 9,14 **** --- 9,15 ---- use IO::File; use Fcntl qw(:flock); use Text::Tabs; + use File::Compare; require Exporter; *************** *** 92,101 **** $this->write($fh) or return 0; } undef $fh; ! if (defined $opt{backup}) { ! rename $this->filename, $this->filename . $opt{backup}; } - return rename $tempname, $this->filename; } --- 93,106 ---- $this->write($fh) or return 0; } undef $fh; ! if (compare ($tempname, $this->filename) == 0) { ! unlink $tempname; ! } else { ! if (defined $opt{backup}) { ! rename $this->filename, $this->filename . $opt{backup}; ! } ! rename $tempname, $this->filename; } }