Gulliver has asked for the wisdom of the Perl Monks concerning the following question:
I have written a Perl application that downloads several directories to a temporary download folder before doing some operations and then moving subfolders from the download folder to various locations. The problem is that other people browse through the download folder during the ftp transfer and occasionally cause the dirmove function to fail.
The download folder gets created with a timestamp ( 12 digits in the actual application) so it is unique and easy to find if something goes wrong. I read about flock but it doesn't seem to work for directories when I tried it. I'm thinking about setting the hidden bit (Windows 2008 server) during the download. I already have a function that is triggered by __DIE__ so I could unhide it if something happens.
The code below allowed me to recreate the problem. I found if I opened the directory in Windows Explorer then there was no error. If I opened the file with Notepad at the target location my script would move the file but then die without moving the directory. By changing to the directory in a command prompt before the dirmove then I get the "Permission Denied" error and nothing is moved.
Has anyone else dealt with this? Any suggestions?
#!/usr/bin/perl use warnings; use strict; use File::Copy::Recursive qw( dirmove fmove ); # 'D:/Users/bas/ftp_20110722/1/logs/ACREROCK TIE_SUB_log. +txt'; my $frompath = 'D:/Users/bas/ftp_20110722'; my $topath = 'D:/Users/bas/logs'; my $target = '/1/logs'; print "\nabout to move $frompath$target\n"; print "press <enter>"; <>; dirmove "$frompath$target", "$topath$target" or die "can't move $frompath$target to $topath$target :",$!;
Results in this:
d:\Users\bas>perl dirmove_test.pl about to move D:/Users/bas/ftp_20110722/1/logs press <enter> can't move D:/Users/bas/ftp_20110722/1/logs to D:/Users/bas/logs/1/log +s :Permiss ion denied at dirmove_test.pl line 22, <> line 1.
|
|---|