When a file is created on a Linux NFS shared mount, the client is either Linux o r mac machines. The existence or absence of a file is the key for what to do next, but the checking is not always return the right result:
e.g I am doing this in perl, this still not working well, esp with mac machines
write_key_file(); # write a file that must be checked before proceeding
The following checks cannot always return true when the file does exist
Issue - this command in perl did not return correct status in NFS system:
if( -e $file){}
Overheared solution that did not work:
sleep(5); # wait 5 seconds
system("ls -ltr"); # force to cache?
if(-e $file){}
I do not intend to check every file like this, but there are a few key places where it is important to get the proper file status.
Do we have better ways to force refresh nfs cache on a specific file on a specific directory? Thanks.
I am not sure that this is a XY problem, but there are a few weakest points that can all be solutions.
A -- NFS clients setting
If there is a solution at this stage, it would be great!
B -- exit_code or return code of writing function
$exit_code = write_key_file();
The problem with it, not all writing are within the scope of the code block. this only solve part of the problem.
C -- Disable NFS cache for the specific file or directory for file checking
I need to make sure is this possible and how? if no and why?
and I am open to all possible solutions, no solution or other possibilities.