r589@rob-kinyons-computer-2 (orig r10513): rkinyon | 2008-01-10 23:43:55 -0500
[dbsrgits/DBM-Deep.git] / lib / DBM / Deep / File.pm
index 83835d9..042cbaa 100644 (file)
@@ -5,9 +5,10 @@ use 5.006_000;
 use strict;
 use warnings;
 
-our $VERSION = q(1.0006);
+our $VERSION = q(1.0009);
 
 use Fcntl qw( :DEFAULT :flock :seek );
+use FileHandle::Fmode ();
 
 sub new {
     my $class = shift;
@@ -110,7 +111,7 @@ sub print_at {
         seek( $fh, $loc + $self->{file_offset}, SEEK_SET );
     }
 
-    print( $fh @_ );
+    print( $fh @_ ) or die "Internal Error (print_at($loc)): $!\n";
 
     return 1;
 }
@@ -163,8 +164,17 @@ sub lock {
 
     $type = LOCK_EX unless defined $type;
 
+    #XXX This is a temporary fix for Win32 and autovivification. It
+    # needs to improve somehow. -RobK, 2008-03-09
+    if ( $^O eq 'MSWin32' || $^O eq 'cygwin' ) {
+        $type = LOCK_EX;
+    }
+
     if (!defined($self->{fh})) { return; }
 
+    #XXX This either needs to allow for upgrading a shared lock to an
+    # exclusive lock or something else with autovivification.
+    # -RobK, 2008-03-09
     if ($self->{locking}) {
         if (!$self->{locked}) {
             flock($self->{fh}, $type);
@@ -226,5 +236,22 @@ sub flush {
     return 1;
 }
 
+sub is_writable {
+    my $self = shift;
+    return FileHandle::Fmode::is_W( $self->{fh} );
+}
+
+sub copy_stats {
+    my $self = shift;
+    my ($temp_filename) = @_;
+
+    my @stats = stat( $self->{fh} );
+    my $perms = $stats[2] & 07777;
+    my $uid = $stats[4];
+    my $gid = $stats[5];
+    chown( $uid, $gid, $temp_filename );
+    chmod( $perms, $temp_filename );
+}
+
 1;
 __END__