File::Copy::Verify - data-safe copy
use File::Copy::Verify qw(verify_copy);
use Try::Tiny::Retry;
retry {
verify_copy('a', 'b'); #or copy or cp - all variants are exportable
};
#OOP equivalent:
$verify_copy = File::Copy::Verify->new(
src => 'a',
dst => 'b',
);
retry {
$verify_copy->copy();
};
#I know source SHA-256 hash and I can use for validation
retry {
File::Copy::Verify::copy('a', 'b', {src_hash => '0'x64, hash_algo => 'SHA-256'});
};
#OOP equivalent
$verify_copy = File::Copy::Verify->new(
src => 'a',
src_hash => '0' x 64,
dst => 'b',
hash_algo => 'SHA-256',
);
retry {
$verify_copy->copy();
};
This module calculates hash before and after copying and if the hash doesn't match, then dies. I recommend Try::Tiny::Retry module for copy retry mechanism. This module is useful for network storages/filesystems, but it is harmful for local storages/filesystems because of overhead. The `verified_copy` function is at least 3 times slower then standard `copy`!
File::Copy::Verify is module for verifying copy. Some storages (in particular net storages) can have troubles with valid copy and copy
function from File::Copy doesn't find this problems (like random buffers in copied file).
This module calculates hash before and after copying and if hash doesn't match, then dies. I recommend Try::Tiny::Retry module for copy retry mechanism.
This module is useful for network storages/filesystems, but it is harmful for localstorages/filesystems because of overhead. The verify_copy
function is at least 3 times slower then standard copy
!
source path
destination path
digest alghoritm used for check
default is fast MD5
more about Digest
manualy set source hash
this is usefully if I know source hash (doesn't calculate again)
manualy set destination hash
this is usefully if I know destination hash (doesn't calculate again)
If is file invalid (means hash-check failed), dst
is removed.
This decreases potentional problems with bad-copied files.
If you need keep this bad file anyway. Or for debugging. Use this option.
$options
- same parameters (except src
and dst
) like in constructor new
alias for verify_copy
alias for verify_copy
same as verify_copy and after success copy remove source $src
file
alias for verify_move
alias for verify_move
File::Copy::Vigilant - Looks really good, don't support other digests - only MD5, don't support hard-set src or dst hash. Support retry mechanism by default.
File::Copy::Reliable - only "checks that the file size of the copied or moved file is the same as the source".
Copyright (C) Avast Software.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Jan Seidl seidl@avast.com