Search code examples
perlnfs

File::Copy reports incorrect failure on NFS write?


My Perl script is moving files onto an NFS mounted filesystem, using the move function from File::Copy. Recently, some of the files returned an error, causing my script to print the message "move returned 0, A file or directory in the path name does not exist." (move returns 1 on success, 0 on error, the error message is from $!)

The really weird thing is that the system that processes the files has reported back that it successfully processed the files that failed! I have never seen an error message from a successful write before, so I wonder if it has something to do with NFS. I thought it was strange that in a run where 28 files were moved, the first 24 failed and the last 4 succeeded. The script has been running with no errors for several months, and has now demonstrated this problem twice in 2 weeks.

The host is running on AIX, though I doubt that makes a difference.


Solution

  • I think it is a NFS issue, not Perl. NFS could be really weird in some cases.

    You should stat/read the writed file and do not depend on reported errors.

    The File::Copy::Reliable module use the same error handling it will fail with same error.

    Form source:

    copy( $source, $destination )
        || croak("copy_reliable($source, $destination) failed: $!");
    

    Simply put the copy into an eval block, and try to read/stat the file in the destination.

    If you really cautious you could use md5/sha1 hash on both files to be sure that they are the same.

    Regards,