Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit 5645f27

Browse files
committed
When an invalid zip file is found, instead of ignoring it silently, log
a warning message
1 parent dc3bbd1 commit 5645f27

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/library.cr

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ end
6161

6262
class Title
6363
JSON.mapping dir: String, entries: Array(Entry), title: String,
64-
id: String, encoded_title: String, mtime: Time
64+
id: String, encoded_title: String, mtime: Time, logger: MLogger
6565

66-
def initialize(dir : String, storage)
66+
def initialize(dir : String, storage, @logger : MLogger)
6767
@dir = dir
6868
@id = storage.get_id @dir, true
6969
@title = File.basename dir
@@ -91,6 +91,8 @@ class Title
9191
file.close
9292
return true
9393
rescue
94+
@logger.warn "File #{path} is corrupted or is not a valid zip "\
95+
"archive. Ignoring it."
9496
return false
9597
end
9698
end
@@ -200,7 +202,7 @@ class Library
200202
end
201203
@titles = (Dir.entries @dir)
202204
.select { |path| File.directory? File.join @dir, path }
203-
.map { |path| Title.new File.join(@dir, path), @storage }
205+
.map { |path| Title.new File.join(@dir, path), @storage, @logger }
204206
.select { |title| !title.entries.empty? }
205207
.sort { |a, b| a.title <=> b.title }
206208
@logger.debug "Scan completed"

0 commit comments

Comments
 (0)