File-Truncate-Undoable

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    Usage:

     truncate(%args) -> [status, msg, result, meta]

    Truncate a file, with undo support.

    On do, will trash file then create an empty file (with the same
    permission and ownership as the original). On undo, will trash the new
    file and untrash the old file.

    Note: chown will not be done if we are not running as root. Symlink is
    currently not permitted.

    Fixed state: file exists and size is not zero.

    Fixable state: file exists and size is not zero.

    Unfixable state: file does not exist or path is not a regular file
    (directory and symlink included).

    This function is not exported.

lib/File/Truncate/Undoable.pm  view on Meta::CPAN


$SPEC{truncate} = {
    v           => 1.1,
    summary     => 'Truncate a file, with undo support',
    description => <<'_',

On do, will trash file then create an empty file (with the same permission and
ownership as the original). On undo, will trash the new file and untrash the old
file.

Note: chown will not be done if we are not running as root. Symlink is currently
not permitted.

Fixed state: file exists and size is not zero.

Fixable state: file exists and size is not zero.

Unfixable state: file does not exist or path is not a regular file (directory
and symlink included).

_

lib/File/Truncate/Undoable.pm  view on Meta::CPAN

                    ['File::Trash::Undoable::trash',
                     {path=>$path, suffix=>substr($taid,0,8)."n"}], # trash new
                ]}];
    } elsif ($tx_action eq 'fix_state') {
        log_info("Truncating file $path ...");
        my $res = File::Trash::Undoable::trash(
            -tx_action=>'fix_state', path=>$path, suffix=>substr($taid,0,8));
        return $res unless $res->[0] == 200 || $res->[0] == 304;
        open my($fh), ">", $path or return [500, "Can't create: $!"];
        chmod $st[2] & 07777, $path; # ignore error?
        unless ($>) { chown $st[4], $st[5], $path } # XXX ignore error?
        return [200, "OK"];
    }
    [400, "Invalid -tx_action"];
}

1;
# ABSTRACT: Truncate a file, with undo support

__END__

lib/File/Truncate/Undoable.pm  view on Meta::CPAN

Usage:

 truncate(%args) -> [status, msg, result, meta]

Truncate a file, with undo support.

On do, will trash file then create an empty file (with the same permission and
ownership as the original). On undo, will trash the new file and untrash the old
file.

Note: chown will not be done if we are not running as root. Symlink is currently
not permitted.

Fixed state: file exists and size is not zero.

Fixable state: file exists and size is not zero.

Unfixable state: file does not exist or path is not a regular file (directory
and symlink included).

This function is not exported.



( run in 0.511 second using v1.01-cache-2.11-cpan-71847e10f99 )