You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-15 01:04:37 +02:00
Added file and directory syncs to the File object for additional safety during backup and archiving.
This commit is contained in:
47
lib/BackRest/FileCommon.pm
Normal file
47
lib/BackRest/FileCommon.pm
Normal file
@ -0,0 +1,47 @@
|
||||
####################################################################################################################################
|
||||
# FILE COMMON MODULE
|
||||
####################################################################################################################################
|
||||
package BackRest::FileCommon;
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
|
||||
use Exporter qw(import);
|
||||
use File::Basename qw(dirname);
|
||||
use IO::Handle;
|
||||
|
||||
use lib dirname($0) . '/../lib';
|
||||
use BackRest::Exception;
|
||||
use BackRest::Utility;
|
||||
|
||||
####################################################################################################################################
|
||||
# Operation constants
|
||||
####################################################################################################################################
|
||||
use constant OP_FILE_BASE => 'FileBase';
|
||||
|
||||
use constant OP_FILE_BASE_PATH_SYNC => OP_FILE_BASE . '::filePathSync';
|
||||
|
||||
####################################################################################################################################
|
||||
# filePathSync
|
||||
#
|
||||
# Sync a directory.
|
||||
####################################################################################################################################
|
||||
sub filePathSync
|
||||
{
|
||||
my $strPath = shift;
|
||||
|
||||
&log(TRACE, OP_FILE_BASE_PATH_SYNC . "(): path = ${strPath}");
|
||||
|
||||
open(my $hPath, "<", $strPath)
|
||||
or confess &log(ERROR, "unable to open ${strPath}", ERROR_PATH_OPEN);
|
||||
open(my $hPathDup, ">&", $hPath)
|
||||
or confess &log(ERROR, "unable to duplicate handle for ${strPath}", ERROR_PATH_OPEN);
|
||||
|
||||
$hPathDup->sync
|
||||
or confess &log(ERROR, "unable to sync ${strPath}", ERROR_PATH_SYNC);
|
||||
}
|
||||
|
||||
our @EXPORT = qw(filePathSync);
|
||||
|
||||
1;
|
Reference in New Issue
Block a user