[英]Folder seems to exist in OS but fails silently upon `sudo rm -rf dirname`
I am trying to delete a folder, but failing to do so.我正在尝试删除一个文件夹,但没有这样做。 I am sudo, and have all permissions.
我是 sudo,拥有所有权限。
cd /path/to/parent
ls
001 003 005 007 009 011 013 015 017 019 021 dent_detections_3d.ply dent_spread_debug.png paint_chip_spread_debug.png
002 004 006 008 010 012 014 016 018 020 _det__grouped.json dent_detections_debug.json paint_chip_detections_debug.json
I want to delete 003
which is the problematic folder.我想删除有问题的文件夹
003
。 Other folders behave normally.其他文件夹行为正常。
Observations:观察:
cd 003
gives -bash: cd: 003: No such file or directory
cd 003
给出-bash: cd: 003: No such file or directory
sudo rm -rf 003
or sudo rm -rf 003/
gives empty output, then ls
gives the same as above ( 003
exists). sudo rm -rf 003
或sudo rm -rf 003/
给出空的 output,然后ls
给出与上面相同的结果( 003
存在)。python
> import os
> path.os.exists("path/to/parent")
>> True
> path.os.exists("path/to/parent/003")
>> False
> os.mkdir("path/to/parent/003")
>>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 17] File exists: '/path/to/parent/003'
What may be causing this?这可能是什么原因造成的? How to debug this?
如何调试这个? I want the folder removed, and I need this to not happen again.
我希望删除该文件夹,并且我需要这种情况不再发生。
EDIT to answer comments:编辑回答评论:
> ls -la
total 6144
drwxr-xr-x 2 noam root 0 Dec 28 13:28 .
drwxr-xr-x 2 noam root 0 Dec 9 18:41 ..
drwxr-xr-x 2 noam root 0 Dec 28 13:28 001
drwxr-xr-x 2 noam root 0 Dec 28 13:28 002
drwxr-xr-x 2 noam root 0 Dec 28 13:28 003
drwxr-xr-x 2 noam root 0 Dec 28 13:26 004
drwxr-xr-x 2 noam root 0 Dec 28 13:26 005
drwxr-xr-x 2 noam root 0 Dec 28 13:26 006
drwxr-xr-x 2 noam root 0 Dec 28 13:26 007
drwxr-xr-x 2 noam root 0 Dec 28 13:26 008
drwxr-xr-x 2 noam root 0 Dec 28 13:26 009
drwxr-xr-x 2 noam root 0 Dec 28 13:26 010
drwxr-xr-x 2 noam root 0 Dec 28 13:26 011
drwxr-xr-x 2 noam root 0 Dec 28 13:26 012
drwxr-xr-x 2 noam root 0 Dec 28 13:26 013
drwxr-xr-x 2 noam root 0 Dec 28 13:26 014
drwxr-xr-x 2 noam root 0 Dec 28 13:26 015
drwxr-xr-x 2 noam root 0 Dec 28 13:26 016
drwxr-xr-x 2 noam root 0 Dec 28 13:26 017
drwxr-xr-x 2 noam root 0 Dec 28 13:26 018
drwxr-xr-x 2 noam root 0 Dec 28 13:26 019
drwxr-xr-x 2 noam root 0 Dec 28 13:26 020
drwxr-xr-x 2 noam root 0 Dec 28 13:26 021
-rwxr-xr-x 1 noam root 684753 Dec 12 11:58 _det__grouped.json
-rwxr-xr-x 1 noam root 7604 Dec 12 11:58 dent_detections_3d.ply
-rwxr-xr-x 1 noam root 89902 Dec 12 11:58 dent_detections_debug.json
-rwxr-xr-x 1 noam root 377863 Dec 12 11:58 dent_spread_debug.png
-rwxr-xr-x 1 noam root 24 Dec 12 11:58 paint_chip_detections_debug.json
-rwxr-xr-x 1 noam root 362525 Dec 12 11:58 paint_chip_spread_debug.png
EDIT2 with the information that a race-condition is the problem EDIT2 显示竞争条件是问题的信息
Relevant code chunk that creates the folder:创建文件夹的相关代码块:
if os.path.exists(cluster_folder_path):
shutil.rmtree(cluster_folder_path)
os.mkdir(cluster_folder_path)
Changing the code in EDIT2 to将 EDIT2 中的代码更改为
while os.path.exists(cluster_folder_path):
shutil.rmtree(cluster_folder_path)
os.mkdir(cluster_folder_path)
forced the folder to actually be deleted before moving on to create it, thus preventing the race condition.强制在继续创建文件夹之前实际删除该文件夹,从而防止竞争条件。
I was not able to understand why this happens only for a single folder, or why this one and not others.我无法理解为什么这只发生在一个文件夹中,或者为什么这个文件夹而不是其他文件夹。 I was also not able to understand why this kept happening after Python was already not running.
我也无法理解为什么在 Python 已经没有运行之后这种情况一直发生。
Will accept an answer that manages to explain that.将接受一个能够解释这一点的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.