--- alexandria-book-collection-manager-0.7.5/lib/alexandria/library_store.rb.broken_yaml 2020-05-11 16:39:20.000000000 +0900 +++ alexandria-book-collection-manager-0.7.5/lib/alexandria/library_store.rb 2020-10-17 16:07:44.600805994 +0900 @@ -48,8 +48,23 @@ module Alexandria Dir["*" + Library::EXT[:book]].sort.each do |filename| test[1] = filename if (test[0]).zero? + book_valid_p = true + unless File.size? test[1] log.warn { "Book file #{test[1]} was empty" } + book_valid_p = false + end + + if book_valid_p + begin + book = regularize_book_from_yaml(test[1]) + rescue Psych::SyntaxError => e + log.warn "Book file #{test[1]} could not be parsed" + book_valid_p = false + end + end + + if not book_valid_p md = /([\dxX]{10,13})#{Library::EXT[:book]}/.match(filename) if md file_isbn = md[1] @@ -60,7 +75,7 @@ module Alexandria end next end - book = regularize_book_from_yaml(test[1]) + old_isbn = book.isbn old_pub_year = book.publishing_year begin @@ -181,6 +196,8 @@ module Alexandria private def regularize_book_from_yaml(name) + require 'syck/encoding' + text = IO.read(name) # Code to remove the mystery string in books imported from Amazon @@ -203,7 +220,7 @@ module Alexandria end # TODO: Ensure book loading passes through Book#initialize - book = YAML.safe_load(text, permitted_classes: [Book, Time]) + book = YAML.safe_load(Syck::unescape(text), permitted_classes: [Book, Time]) unless book.isbn.class == String # HACK