Examine titles and recycle them

This commit is contained in:
Leeingnyo 2021-09-11 13:30:07 +09:00
parent 0a90e3b333
commit eb3e37b950
2 changed files with 13 additions and 1 deletions

View File

@ -144,14 +144,20 @@ class Library
storage = Storage.new auto_close: false
@title_ids.select! do |title_id|
title = @title_hash[title_id]
title.examine
end
remained_title_dirs = @title_ids.map { |id| title_hash[id].dir }
(Dir.entries @dir)
.select { |fn| !fn.starts_with? "." }
.map { |fn| File.join @dir, fn }
.select { |path| !(remained_title_dirs.includes? path) }
.select { |path| File.directory? path }
.map { |path| Title.new path, "" }
.select { |title| !(title.entries.empty? && title.titles.empty?) }
.sort! { |a, b| a.title <=> b.title }
.tap { |_| @title_ids.clear }
.each do |title|
@title_hash[title.id] = title
@title_ids << title.id

View File

@ -69,6 +69,12 @@ class Title
end
end
def examine : Bool
return false unless Dir.exists? @dir
signature = Dir.signature @dir
return @signature == signature
end
def to_slim_json : String
JSON.build do |json|
json.object do