summaryrefslogtreecommitdiff
path: root/tool/lib
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-04-19 23:07:58 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2024-04-19 23:17:23 +0900
commitcd95f6b87fbe15712406054a31b8411ae82180f6 (patch)
tree493f738e0fe8a4cc603ab6df1f19421bedad692a /tool/lib
parentc789e4c493cfd8abde2268b1ca2a0656851e0772 (diff)
Show left files info
Diffstat (limited to 'tool/lib')
-rw-r--r--tool/lib/_tmpdir.rb36
1 files changed, 35 insertions, 1 deletions
diff --git a/tool/lib/_tmpdir.rb b/tool/lib/_tmpdir.rb
index ddc263b563..c74db70786 100644
--- a/tool/lib/_tmpdir.rb
+++ b/tool/lib/_tmpdir.rb
@@ -13,7 +13,41 @@ end
pid = $$
END {
if pid == $$
- FileUtils.rm_rf(tmpdir)
+ begin
+ Dir.rmdir(tmpdir)
+ rescue Errno::ENOENT
+ rescue Errno::ENOTEMPTY
+ require_relative "colorize"
+ colorize = Colorize.new
+ mode_inspect = ->(m, s) {
+ [
+ (m & 0o4 == 0 ? ?- : ?r),
+ (m & 0o2 == 0 ? ?- : ?w),
+ (m & 0o1 == 0 ? (s ? s.upcase : ?-) : (s || ?x)),
+ ]
+ }
+ filecolor = ->(st) {
+ st.directory? ? "bold;blue" : st.link? ? "bold;cyan" : st.executable? ? "bold;green" : nil
+ }
+ warn colorize.notice("Children under ")+colorize.fail(tmpdir)+":"
+ Dir.children(tmpdir).each do |child|
+ path = File.join(tmpdir, child)
+ st = File.lstat(path)
+ m = st.mode
+ m = [
+ (st.file? ? ?- : st.ftype[0]),
+ mode_inspect[m >> 6, (?s unless m & 04000 == 0)],
+ mode_inspect[m >> 3, (?s unless m & 02000 == 0)],
+ mode_inspect[m, (?t unless m & 01000 == 0)],
+ ].join("")
+ warn [
+ " ", m, st.nlink, st.size, st.mtime,
+ colorize.decorate(child, filecolor[st]),
+ (["->", colorize.cyan(File.readlink(path))] if st.symlink?),
+ ].compact.join(" ")
+ end
+ FileUtils.rm_rf(tmpdir)
+ end
end
}