Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What will happen if Perl tries to call move() on a file that is being uploaded?

Someone is FTPing a file of size 10Mb to folder on a linux server. While the file is in transition a cron wakes up and fires off a Perl script that is designed to look at the ftp folder and move whatever it finds there to some alternate folder. I'm using the move() function from File::Copy. The Perl process actually renames the files as part of its task. Does that matter, or does the FTP not care what the file system describes the file as?

Will move() succeed and move a partial file, leaving the FTP to do what? Or will move fail and return 0?

like image 976
Yevgeny Simkin Avatar asked Apr 30 '09 18:04

Yevgeny Simkin


1 Answers

No, move should just let complete the download process on the new position . You are just moving the inode from one position to another. The open file descriptor from the download program should still point to it.

I just want to repeat what a few others mentioned. This only works as long as the move operation is on the same filesystem. If it as another filesystem than the inode cannot be transferred because it always belongs to the same filesystem. The most probably scenario then would be that the partial data at that moment is copied over to the new location while the program still downloads in the old inode which is not anymore attached to a file and therefor can not be used.

like image 182
Norbert Hartl Avatar answered Oct 21 '22 09:10

Norbert Hartl