Skip to content

Commit 21892b8

Browse files
staticfloatIanButterworth
authored andcommitted
Catch errors during recursive_dir_size() (#2345)
* Catch errors during `recursive_dir_size()` While trying to clean up artifacts on Yggdrasil's CI bots, we found that some malformed artifacts (that had things like extremely-deeply-nested directories) would cause `ENAMETOOLONG` in a `stat()` within `walkdir()` itself. Let's catch these kinds of issues and report them to the user properly. (cherry picked from commit a832dca)
1 parent cb090a1 commit 21892b8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/API.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,19 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
769769

770770
function recursive_dir_size(path)
771771
size = 0
772-
for (root, dirs, files) in walkdir(path)
773-
for file in files
774-
path = joinpath(root, file)
775-
try
776-
size += lstat(path).size
777-
catch
778-
@warn "Failed to calculate size of $path"
772+
try
773+
for (root, dirs, files) in walkdir(path)
774+
for file in files
775+
path = joinpath(root, file)
776+
try
777+
size += lstat(path).size
778+
catch ex
779+
@error("Failed to calculate size of $path", exception=ex)
780+
end
779781
end
780782
end
783+
catch ex
784+
@error("Failed to calculate size of $path", exception=ex)
781785
end
782786
return size
783787
end

0 commit comments

Comments
 (0)