diff --git a/src/library/library.cr b/src/library/library.cr index a3f2baa..86375be 100644 --- a/src/library/library.cr +++ b/src/library/library.cr @@ -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 diff --git a/src/library/title.cr b/src/library/title.cr index 6c873b8..44464c9 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -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