NFS升级后,由于目录不为空,rmdir失败

I have a website that has an assets directory. Sometimes I need to delete a whole folder and previously on AWS I had an EC2 with an EBS for storage, and it worked fine.

I'm now testing EFS to share the assets across multiple instances. The files are removed however when it goes to remove the directory it throws a warning saying the directory isn't empty:

ERROR [Warning]: rmdir(/path/): Directory not empty

Upon looking at the file system the directory is empty so I can only assume there is some lag. I've put a sleep function in to see if that fixes it as a test but it doesn't.

Permissions on the directory look correct and it has no issue saving / deleting files.

Is my only option to exec the rm -rf command? The code that does the deleting below:

public function delTree($dir) {
    $files = array_diff(scandir($dir), array('.','..')); 
    foreach ($files as $file) {
        (is_dir("$dir/$file")) ? $this->delTree($dir . $file . "/") : unlink("$dir/$file"); 
    }
    return rmdir($dir); 
}

Most likely this means that another process has a lock held on one or more files. This could be a software bug where files are not closed properly.

The reason that this may have worked with EBS but not with NFS is differences in how deleted files are handled.

There are software tools available that can tell you what files are open on file systems. Use one of these tools to figure out what is happening. Usually you can also see the process that has the open file.

rm -rf will most likely not work. The -f option is "force" which means change the permissions on a read only file so that it can be deleted. rm cannot change / remove a file system lock.