1
0
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:
David Steele
2015-06-17 12:53:33 -04:00
parent 9511f9c35c
commit a5d9d6d84d
6 changed files with 103 additions and 17 deletions

View 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;