[Bps-public-commit] Config-GitLike branch, master, updated. 584c1c9ea56367ed26c9d0b03f8e86ab42f5c968

spang at bestpractical.com spang at bestpractical.com
Thu Jul 2 11:53:08 EDT 2009


The branch, master has been updated
       via  584c1c9ea56367ed26c9d0b03f8e86ab42f5c968 (commit)
       via  35d2eb9b2ed9c37568a25e9ea7dd2ade6bd1dec2 (commit)
       via  4c349577c59476f53d5249d2a985a1ab4351a7b2 (commit)
      from  1ce733042824f0de06da05581631d7fef878e07c (commit)

Summary of changes:
 .gitignore            |    1 +
 .shipit               |   10 ++++++++++
 lib/Config/GitLike.pm |   30 +++++++-----------------------
 3 files changed, 18 insertions(+), 23 deletions(-)
 create mode 100644 .shipit

- Log -----------------------------------------------------------------
commit 4c349577c59476f53d5249d2a985a1ab4351a7b2
Author: Christine Spang <spang at mit.edu>
Date:   Thu Jul 2 09:54:58 2009 -0400

    skeleton .shipit

diff --git a/.shipit b/.shipit
new file mode 100644
index 0000000..44c02c1
--- /dev/null
+++ b/.shipit
@@ -0,0 +1,10 @@
+# auto-generated shipit config file.
+steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN, Twitter
+
+git.tagpattern = %v
+twitter.config = ~/.twitterrc
+
+# svn.tagpattern = MyProj-%v
+# svn.tagpattern = http://code.example.com/svn/tags/MyProj-%v
+
+# CheckChangeLog.files = ChangeLog, MyProj.CHANGES

commit 35d2eb9b2ed9c37568a25e9ea7dd2ade6bd1dec2
Author: Christine Spang <spang at mit.edu>
Date:   Thu Jul 2 09:55:42 2009 -0400

    Add inc/.author to .gitignore

diff --git a/.gitignore b/.gitignore
index b23e3ee..d627b3e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ pm_to_blib
 Makefile
 Makefile.old
 *.tmp
+inc/.author

commit 584c1c9ea56367ed26c9d0b03f8e86ab42f5c968
Author: Christine Spang <spang at mit.edu>
Date:   Thu Jul 2 10:09:51 2009 -0400

    Don't try to do clever things with locking as it seems to backfire.

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index 6bfb2bd..067941a 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -8,7 +8,7 @@ use File::HomeDir;
 use Regexp::Common;
 use Any::Moose;
 use Scalar::Util qw(openhandle);
-use Fcntl qw(:DEFAULT :flock);
+use Fcntl qw(O_CREAT O_EXCL O_WRONLY);
 use 5.008;
 
 our $VERSION = '1.00';
@@ -129,28 +129,14 @@ sub load_user {
 # returns undef if the file was unable to be opened
 sub _read_config {
     my $filename = shift;
-    my $lock_and_return_fh = shift;
-
-    my $fh;
-    if ( !open($fh, '<', $filename) && $lock_and_return_fh ) {
-        open($fh, '>', $filename)
-            or die "Can't open $filename for writing: $!\n";
-        flock($fh, LOCK_EX);
-        return ('', $fh);
-    }
 
-    # lock the filehandle because we want to write to it later and want to
-    # (try to) ensure that no one else writes to the file in the meantime so
-    # that we don't overwrite their update
-    flock($fh, LOCK_EX) if $lock_and_return_fh;
+    open(my $fh, '<', $filename) or return;
 
     my $c = do {local $/; <$fh>};
 
-    close $fh unless $lock_and_return_fh;
-
     $c =~ s/\n*$/\n/; # Ensure it ends with a newline
 
-    return openhandle $fh ? ($c, $fh) : $c;
+    return $c;
 }
 
 sub load_file {
@@ -698,7 +684,7 @@ sub group_set {
     my $self = shift;
     my ($filename, $args_ref) = @_;
 
-    my ($c, $fh) = _read_config($filename, 1);  # undef if file doesn't exist
+    my $c = _read_config($filename);  # undef if file doesn't exist
 
     # loop through each value to set, modifying the content to be written
     # or erroring out as we go
@@ -851,8 +837,6 @@ sub group_set {
         }
     }
     return _write_config( $filename, $c );
-    # release lock
-    close $fh;
 }
 
 sub set {
@@ -952,6 +936,8 @@ sub _write_config {
     }
 
     # write new config file to temp file
+    # (the only reason we call it .lock is because that's the
+    # way git does it)
     sysopen(my $fh, "${filename}.lock", O_CREAT|O_EXCL|O_WRONLY)
         or die "Can't open ${filename}.lock for writing: $!\n";
     print $fh $content;
@@ -974,7 +960,7 @@ sub rename_section {
 
     die "No section to rename from given\n" unless defined $args{from};
 
-    my ($c, $fh) = _read_config($args{filename}, 1);
+    my $c = _read_config($args{filename});
     # file couldn't be opened = nothing to rename
     return if !defined($c);
 
@@ -1060,8 +1046,6 @@ sub rename_section {
     }
 
     return _write_config($args{filename}, $c);
-    # release lock
-    close $fh;
 }
 
 sub remove_section {

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



More information about the Bps-public-commit mailing list