17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/core_ex/file_utils.rb', line 17
def remove_dir (dir, force = false) dir = dir.sub(%r</\z>, '')
first_time_p = true
begin
Dir.foreach(dir) do |file|
next if /\A\.\.?\z/ =~ file
path = "#{dir}/#{file.untaint}"
if File.symlink?(path)
remove_file path, force
elsif File.directory?(path)
remove_dir path, force
else
remove_file path, force
end
end
begin
Dir.rmdir dir
rescue Errno::ENOENT
raise unless force
end
rescue
if first_time_p
first_time_p = false
File.chmod 0777, dir
retry
end
raise
end
end
|