mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -04:00
Ignore invalid zip files in library
This commit is contained in:
parent
e8c365b7a1
commit
5abdca24c2
@ -70,8 +70,10 @@ class Title
|
|||||||
@encoded_title = URI.encode @title
|
@encoded_title = URI.encode @title
|
||||||
@entries = (Dir.entries dir)
|
@entries = (Dir.entries dir)
|
||||||
.select { |path| [".zip", ".cbz"].includes? File.extname path }
|
.select { |path| [".zip", ".cbz"].includes? File.extname path }
|
||||||
|
.map { |path| File.join dir, path }
|
||||||
|
.select { |path| valid_zip path }
|
||||||
.map { |path|
|
.map { |path|
|
||||||
Entry.new File.join(dir, path), @title, @id, storage
|
Entry.new path, @title, @id, storage
|
||||||
}
|
}
|
||||||
.select { |e| e.pages > 0 }
|
.select { |e| e.pages > 0 }
|
||||||
.sort { |a, b| a.title <=> b.title }
|
.sort { |a, b| a.title <=> b.title }
|
||||||
@ -79,6 +81,19 @@ class Title
|
|||||||
mtimes += @entries.map{|e| e.mtime}
|
mtimes += @entries.map{|e| e.mtime}
|
||||||
@mtime = mtimes.max
|
@mtime = mtimes.max
|
||||||
end
|
end
|
||||||
|
# When downloading from MangaDex, the zip/cbz file would not be valid
|
||||||
|
# before the download is completed. If we scan the zip file,
|
||||||
|
# Entry.new would throw, so we use this method to check before
|
||||||
|
# constructing Entry
|
||||||
|
private def valid_zip(path : String)
|
||||||
|
begin
|
||||||
|
file = Zip::File.new path
|
||||||
|
file.close
|
||||||
|
return true
|
||||||
|
rescue
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
def get_entry(eid)
|
def get_entry(eid)
|
||||||
@entries.find { |e| e.id == eid }
|
@entries.find { |e| e.id == eid }
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user