|
|
5cccbb5 |
--- alexandria-book-collection-manager-0.7.4/lib/alexandria/library_store.rb.broken_yaml 2019-10-25 01:20:07.000000000 +0900
|
|
|
f697213 |
+++ alexandria-book-collection-manager-0.7.4/lib/alexandria/library_store.rb 2020-01-07 14:39:45.495305334 +0900
|
|
|
5cccbb5 |
@@ -48,8 +48,23 @@ module Alexandria
|
|
|
5cccbb5 |
Dir["*" + Library::EXT[:book]].each do |filename|
|
|
|
5cccbb5 |
test[1] = filename if (test[0]).zero?
|
|
Mamoru Tasaka |
a04e982 |
|
|
Mamoru Tasaka |
a04e982 |
+ book_valid_p = true
|
|
Mamoru Tasaka |
a04e982 |
+
|
|
|
5cccbb5 |
unless File.size? test[1]
|
|
|
5cccbb5 |
log.warn { "Book file #{test[1]} was empty" }
|
|
Mamoru Tasaka |
a04e982 |
+ book_valid_p = false
|
|
Mamoru Tasaka |
a04e982 |
+ end
|
|
Mamoru Tasaka |
a04e982 |
+
|
|
Mamoru Tasaka |
a04e982 |
+ if book_valid_p
|
|
Mamoru Tasaka |
a04e982 |
+ begin
|
|
|
79794e9 |
+ book = regularize_book_from_yaml(test[1])
|
|
Mamoru Tasaka |
a04e982 |
+ rescue Psych::SyntaxError => e
|
|
Mamoru Tasaka |
a04e982 |
+ log.warn "Book file #{test[1]} could not be parsed"
|
|
Mamoru Tasaka |
a04e982 |
+ book_valid_p = false
|
|
Mamoru Tasaka |
a04e982 |
+ end
|
|
Mamoru Tasaka |
a04e982 |
+ end
|
|
Mamoru Tasaka |
a04e982 |
+
|
|
Mamoru Tasaka |
a04e982 |
+ if not book_valid_p
|
|
|
5cccbb5 |
md = /([\dxX]{10,13})#{Library::EXT[:book]}/.match(filename)
|
|
Mamoru Tasaka |
a04e982 |
if md
|
|
Mamoru Tasaka |
a04e982 |
file_isbn = md[1]
|
|
|
5cccbb5 |
@@ -60,7 +75,7 @@ module Alexandria
|
|
Mamoru Tasaka |
a04e982 |
end
|
|
Mamoru Tasaka |
a04e982 |
next
|
|
Mamoru Tasaka |
a04e982 |
end
|
|
|
5cccbb5 |
- book = regularize_book_from_yaml(test[1])
|
|
Mamoru Tasaka |
a04e982 |
+
|
|
Mamoru Tasaka |
a04e982 |
old_isbn = book.isbn
|
|
Mamoru Tasaka |
a04e982 |
old_pub_year = book.publishing_year
|
|
Mamoru Tasaka |
a04e982 |
begin
|
|
|
f697213 |
@@ -170,6 +185,8 @@ module Alexandria
|
|
|
f697213 |
private
|
|
|
f697213 |
|
|
|
f697213 |
def regularize_book_from_yaml(name)
|
|
|
f697213 |
+ require 'syck/encoding'
|
|
|
f697213 |
+
|
|
|
f697213 |
text = IO.read(name)
|
|
|
f697213 |
|
|
|
f697213 |
# Code to remove the mystery string in books imported from Amazon
|
|
|
f697213 |
@@ -192,7 +209,7 @@ module Alexandria
|
|
|
f697213 |
end
|
|
Mamoru Tasaka |
a04e982 |
|
|
|
5cccbb5 |
# TODO: Ensure book loading passes through Book#initialize
|
|
|
f697213 |
- book = YAML.safe_load(text, permitted_classes: [Book, Time])
|
|
|
f697213 |
+ book = YAML.safe_load(Syck::unescape(text), permitted_classes: [Book, Time])
|
|
Mamoru Tasaka |
a04e982 |
|
|
Mamoru Tasaka |
a04e982 |
unless book.isbn.class == String
|
|
Mamoru Tasaka |
a04e982 |
# HACK
|