duangouyan3328 2017-11-08 04:03
浏览 172

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); 
}
  • 写回答

1条回答 默认 最新

  • douqiang1910 2017-11-08 04:21
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)