Scan DirectoryEntry when init and examine

This commit is contained in:
Leeingnyo 2022-05-15 15:31:11 +09:00
parent 55ccd928a2
commit 3b3a0738e8

View File

@ -49,9 +49,14 @@ class Title
path = File.join dir, fn path = File.join dir, fn
if File.directory? path if File.directory? path
title = Title.new path, @id, cache title = Title.new path, @id, cache
next if title.entries.size == 0 && title.titles.size == 0 unless title.entries.size == 0 && title.titles.size == 0
Library.default.title_hash[title.id] = title Library.default.title_hash[title.id] = title
@title_ids << title.id @title_ids << title.id
end
if DirectoryEntry.validate_directory_entry path
entry = DirectoryEntry.new path, self
@entries << entry if entry.pages > 0 || entry.err_msg
end
next next
end end
if is_supported_file path if is_supported_file path
@ -132,7 +137,7 @@ class Title
context["deleted_entry_ids"] << entry.id unless existence context["deleted_entry_ids"] << entry.id unless existence
existence existence
end end
remained_entry_zip_paths = @entries.map &.path remained_entry_paths = @entries.map &.path
is_titles_added = false is_titles_added = false
is_entries_added = false is_entries_added = false
@ -140,28 +145,42 @@ class Title
next if fn.starts_with? "." next if fn.starts_with? "."
path = File.join dir, fn path = File.join dir, fn
if File.directory? path if File.directory? path
unless remained_entry_paths.includes? path
if DirectoryEntry.validate_directory_entry path
entry = DirectoryEntry.new path, self
if entry.pages > 0 || entry.err_msg
@entries << entry
is_entries_added = true
context["deleted_entry_ids"].select! do |deleted_entry_id|
entry.id != deleted_entry_id
end
end
end
end
next if remained_title_dirs.includes? path next if remained_title_dirs.includes? path
title = Title.new path, @id, context["cached_contents_signature"] title = Title.new path, @id, context["cached_contents_signature"]
next if title.entries.size == 0 && title.titles.size == 0 unless title.entries.size == 0 && title.titles.size == 0
Library.default.title_hash[title.id] = title Library.default.title_hash[title.id] = title
@title_ids << title.id @title_ids << title.id
is_titles_added = true is_titles_added = true
# We think they are removed, but they are here! # We think they are removed, but they are here!
# Cancel reserved jobs # Cancel reserved jobs
revival_title_ids = [title.id] + title.deep_titles.map &.id revival_title_ids = [title.id] + title.deep_titles.map &.id
context["deleted_title_ids"].select! do |deleted_title_id| context["deleted_title_ids"].select! do |deleted_title_id|
!(revival_title_ids.includes? deleted_title_id) !(revival_title_ids.includes? deleted_title_id)
end end
revival_entry_ids = title.deep_entries.map &.id revival_entry_ids = title.deep_entries.map &.id
context["deleted_entry_ids"].select! do |deleted_entry_id| context["deleted_entry_ids"].select! do |deleted_entry_id|
!(revival_entry_ids.includes? deleted_entry_id) !(revival_entry_ids.includes? deleted_entry_id)
end
end end
next next
end end
if is_supported_file path if is_supported_file path
next if remained_entry_zip_paths.includes? path next if remained_entry_paths.includes? path
entry = ZippedEntry.new path, self entry = ZippedEntry.new path, self
if entry.pages > 0 || entry.err_msg if entry.pages > 0 || entry.err_msg
@entries << entry @entries << entry