diff --git a/README.adoc b/README.adoc index e43a0e1d..018b3e42 100644 --- a/README.adoc +++ b/README.adoc @@ -2185,6 +2185,28 @@ File.open('testfile') do |f| end ---- +Atomic File Operations [[atomic-file-operations]] + +When file operations after confirming the existence check of a file, frequent parallel file operations may cause problems that are difficult to reproduce. +Therefore, it is prefer to use atomic file operations. + +[source,ruby] +---- +# bad +unless File.exist?(path) + FileUtils.makedirs(path) +end + +if File.exist?(path) + FileUtils.remove(path) +end + +# good +FileUtils.mkdir_p(path) + +FileUtils.rm_rf(path) +---- + === Standard Exceptions [[standard-exceptions]] Prefer the use of exceptions from the standard library over introducing new exception classes.