Skip to content

Commit 6358487

Browse files
committed
ext: dir
1 parent bd59984 commit 6358487

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/ext/dir.cr

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,21 @@
1818
# -----------------------------------------------------------------------
1919

2020
class Dir
21-
def self.safe_deleted(directory, &)
22-
return unless Dir.exists?(directory)
23-
yield
24-
FileUtils.rm_rf(directory)
25-
end
21+
def self.safe_delete(directory, &)
22+
return unless Dir.exists?(directory)
23+
yield
24+
FileUtils.rm_rf(directory)
25+
end
26+
27+
def self.tempdir(&)
28+
path =
29+
Path[tempdir, Random::Secure.hex]
2630

27-
def self.tempdir(&)
28-
path = Path[tempdir, Random::Secure.hex]
31+
begin
32+
FileUtils.mkdir_p(path)
33+
FileUtils.cd(path) { yield }
34+
ensure
35+
FileUtils.rm_rf(path)
2936
end
30-
end
37+
end
38+
end

0 commit comments

Comments
 (0)