File-AtomicWrite

 view release on metacpan or  search on metacpan

lib/File/AtomicWrite.pm  view on Meta::CPAN

    if ( defined $group_name and $group_name ne '' ) {
        if ( $group_name =~ m/^([0-9]+)$/ ) {
            $gid = $1;
        } else {
            my ( $group_name, $pass, $group_gid ) = getgrnam($group_name)
              or croak 'group not in group database';
            $gid = $group_gid;
        }
    }

    my $count = chown( $uid, $gid, $filename );
    if ( $count != 1 ) {
        die "unable to chown temporary file\n";
    }

    return 1;
}

1;
__END__

=head1 NAME

lib/File/AtomicWrite.pm  view on Meta::CPAN

The module does not change C<umask>, nor is there a means to specify
the permissions on directories created if B<MKPATH> is set.

=item B<mtime> => I<mtime>

Accepts C<mtime> timestamp for C<utime> to be applied to the file.
Usual throwing of error.

=item B<owner> => I<unix ownership string>

Accepts similar arguments to chown(1) to be applied via C<chown>
to the file. Usual throwing of error.

  ...->write_file({ ..., owner => '0'   });
  ...->write_file({ ..., owner => '0:0' });
  ...->write_file({ ..., owner => 'user:somegroup' });

=item B<safe_level> => I<safe_level value>

Optional means to set the L<File::Temp> module C<safe_level> value.
Consult the L<File::Temp> documentation for more information on

t/010-write_file.t  view on Meta::CPAN

        my $stringmode_test_file = File::Spec->catfile( $work_dir, "stringmode$mode" );
        test_write_file(
            { file => $stringmode_test_file, input => \"whatever", mode => $mode } );
        $file_mode = ( stat $stringmode_test_file )[2] & 07777;
        is( $file_mode, $octo_mode, "test string mode $mode" );

    }
}

# owner - confirm that the module code is not buggy, as cannot expect to
# have the rights to chown a file to a different account. Might be able
# to test the group code, as the group could vary, depending on whether
# BSD or Solaris directory group id semantics are in play, but detecting
# that would be annoying.
SKIP: {
    my ( $user_name, $user_uid, $group_name, $group_gid );
    # getpwuid unimplemented on a certain OS, try to skip.
    eval {
        $user_name  = getpwuid($<) || undef;
        $user_uid   = $<           || '';
        $group_name = getgrgid($() || undef;



( run in 0.497 second using v1.01-cache-2.11-cpan-5511b514fd6 )