I encountered an issue with IO::Compress::Gzip. After a successful gzip I want to unlink the original file but sometimes the unlink fails with a "permission denied" I made a pragmatic work around by adding a delay and try the unlink again. But a good solution would be preferred.
The same issue happens with moving the new .gz to another directory. The files are not in use by another process.
Running Strawberry Perl 5.22.0 on Windows 2008 and 2012
use warnings;
use strict;
use POSIX;
use Cwd;
use Cwd 'abs_path';
use Time::Local 'timelocal_nocheck'; # used for SCHEDULE option in
+the MQX.ini
use Net::Domain qw(hostname hostfqdn hostdomain domainname);
use File::Basename;
use File::Copy;
use IO::Compress::Gzip qw(gzip $GzipError) ;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
# module used in the state messages
use Digest::MD5;
# modules used in put mode
use threads;
use threads::shared;
use Thread::Queue;
if ( gzip $archfile => "$archfile.gz", AutoClose => 1, BinModeI
+n => 1 ) {
my $delete_try_counter = mqx_get_setting('ARCHIVEMOVETRY');
while ( -f $archfile and not unlink $archfile and $dele
+te_try_counter != 0 ) {
$global_EVENTLOG_IN_LQ->enqueue("WARNING, $arch_ha
+shref->{'EVENTLOG'},Can not delete $archfile. Error: $! try: $delete_
+try_counter");
$delete_try_counter -= 1;
sleep(mqx_get_setting('ARCHIVEMOVEWAIT')); # wait x sec
+onds before retrying
}
$archfile .= ".gz"; # add .gz to the file name
}
else { # if the gzip failed try to arc
+hive the original file
$global_EVENTLOG_IN_LQ->enqueue("ERROR, $arch_hashref->{'
+EVENTLOG'}, gzip failed on $archfile\n$GzipError");
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.