Is rm_rf ruby ​​asynchronous?

if i do

rm_rf('somewhere') mkdir('somewhere') 

every so often, mkdir issues a Permission Denined . Is this because rm_rf works asynchronously and sometimes does not complete directory deletion before mkdir is executed?

How do I make a block before it is complete?

Run this on a Windows computer.

thanks

+4
source share
3 answers

Sounds like an NTFS feature, see Microsoft Suppport :

This file is in a state known as pending removal. This file has been deleted, but the descriptors are still open. NTFS will wait for all descriptors of this file to close before updating the index. If you try to access the file, however, NTFS will refuse to try. Since the file is listed in the index, but you can efficiently view the file, but you cannot access it.

And looking at the solutions, I don’t think there is anything to do but wait and repeat.

+4
source

rm_rf synchronous , like any other ordinary ruby ​​method.

and if it was'nt, then you will probably get the Errno::EEXIST , but you will get a "permission denied".

as a workaround, try inserting a slight delay, such as sleep(0.1) between rm_rf and mkdir

+3
source

I also ran into this error and first renamed it a workaround:

  build_dir.directory? && build_dir.rename(old_build_dir) && FileUtils.rm_rf(old_build_dir) build_dir.mkdir 

( build_dir and old_build_dir are Pathname objects)

Not perfect, but better than random sleep .

0
source

Source: https://habr.com/ru/post/1386069/


All Articles