in reply to When is it safe to move a file?
You can then loop for some reasonable amount of time, and if the mtime doesn't change, you can guess that the ftp server isn't writing to them anymore.
Something like:
This still leaves a small race condition between the two rename(s) in which the control file might have been overwritten. (a real small timeslice, but a timeslice nonetheless...)if ( -f $control_file && -f $data_file ) { rename($data_file,$data_file. $$); rename($control_file,$control_file . $$); } else { exit; } while (1) { $mtime=(stat($data_file . $$))[9]; # drop out of the loop if the file hasn't # changed in 5 minutes (perhaps longer # for a wan connection ?) last if (time > $mtime + 300); sleep(30); } #process the files
You mentioned you didn't have control over the process, but if you ever do get control, here's two ideas:
Update: yep..I missed a sleep in the lower loop, which would burn lots of resources...fixed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: When is it safe to move a file?
by Dominus (Parson) on Jan 14, 2001 at 22:41 UTC | |
by kschwab (Vicar) on Jan 15, 2001 at 03:27 UTC | |
by Dominus (Parson) on Jan 15, 2001 at 04:01 UTC | |
by kschwab (Vicar) on Jan 15, 2001 at 04:20 UTC | |
by Dominus (Parson) on Jan 15, 2001 at 09:10 UTC | |
|