Home > Archive > PERL CGI Beginners > October 2006 > Getting status of files before copying/moving.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Getting status of files before copying/moving.
|
|
|
| I am copying/moving files from an FTP folder to other folders on server. The script reads the files and copy/move to separate folders etc. No problem till this point.
Now the problem is that users are constantly uploading files to this folder using FTP client. The script is invoked using cron after every 10-15 mins, now what will be the fate of the files that are in the upload process when the script is invoked?
Yes, these files are copied and moved what was uploaded till that point, means corrupt files.
How I can avoid it? that script should leave those files which are being uploaded at the time it was invoked.
######### Start of Subroutine #############
sub copy_files {
use File::Copy;
while (glob ("*.mp3")) {
copy("home/uploads/$_", "home/backup/$_");
move("home/uploads/$_", "home/music/$_");
}
}
######################################
Thanks,
Sara.
| |
| Greg Jetter 2006-10-03, 3:55 am |
| On Monday October 2 2006 9:03 pm, Sara wrote:
> I am copying/moving files from an FTP folder to other folders on server.
> The script reads the files and copy/move to separate folders etc. No
> problem till this point.
>
> Now the problem is that users are constantly uploading files to this folder
> using FTP client. The script is invoked using cron after every 10-15 mins,
> now what will be the fate of the files that are in the upload process when
> the script is invoked?
>
> Yes, these files are copied and moved what was uploaded till that point,
> means corrupt files.
>
> How I can avoid it? that script should leave those files which are being
> uploaded at the time it was invoked.
>
> ######### Start of Subroutine #############
>
> sub copy_files {
> use File::Copy;
> while (glob ("*.mp3")) {
> copy("home/uploads/$_", "home/backup/$_");
> move("home/uploads/$_", "home/music/$_");
> }
> }
>
> ######################################
>
> Thanks,
> Sara.
you should be locking these files wile your working with them so they can't
be accessed by other processes until your done with them.
Greg
| |
| Paul Lalli 2006-10-03, 7:56 am |
| Greg Jetter wrote:
> On Monday October 2 2006 9:03 pm, Sara wrote:
[color=darkred]
>
> you should be locking these files wile your working with them so they can't
> be accessed by other processes until your done with them.
Locking, of course, has absolutely no effect unless the *other* process
is also checking for and obeying locks. Locks are like traffic
lights. A green light merely guarantees that the other guy doesn't
also have a green. It doesn't guarantee the guy won't run his red
light anyway.
Paul Lalli
|
|
|
|
|