From 15a0119248dd5f29666f8dde89d5cd9da731eb93 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Sun, 18 Feb 2018 22:23:50 +0900 Subject: [PATCH 1/2] run remove_entry_secure twice to avoid strange behavior in Windows, Closes #941 --- lib/review/epubmaker.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index e056547cb..d24f6cb05 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -135,7 +135,11 @@ def produce(yamlfile, bookname = nil) @producer.produce("#{bookname}.epub", basetmpdir, epubtmpdir) log('Finished.') ensure - FileUtils.remove_entry_secure basetmpdir unless @config['debug'] + unless @config['debug'] + FileUtils.remove_entry_secure(basetmpdir, true) + # XXX: workaround strange behavior in Windows + FileUtils.remove_entry_secure(basetmpdir) if File.exist?(basetmpdir) + end end end From 060592e883e6b3dcabf76f07325efc777539f5e2 Mon Sep 17 00:00:00 2001 From: Kenshi Muto Date: Tue, 20 Feb 2018 23:47:10 +0900 Subject: [PATCH 2/2] use explicit open/close for Document.parse_stream to avoid Windows's behavior. --- lib/review/epubmaker.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/review/epubmaker.rb b/lib/review/epubmaker.rb index d24f6cb05..941c4b3c8 100644 --- a/lib/review/epubmaker.rb +++ b/lib/review/epubmaker.rb @@ -135,11 +135,7 @@ def produce(yamlfile, bookname = nil) @producer.produce("#{bookname}.epub", basetmpdir, epubtmpdir) log('Finished.') ensure - unless @config['debug'] - FileUtils.remove_entry_secure(basetmpdir, true) - # XXX: workaround strange behavior in Windows - FileUtils.remove_entry_secure(basetmpdir) if File.exist?(basetmpdir) - end + FileUtils.remove_entry_secure(basetmpdir) unless @config['debug'] end end @@ -368,7 +364,8 @@ def detect_properties(path) def write_info_body(basetmpdir, _id, filename, ispart = nil, chaptype = nil) headlines = [] path = File.join(basetmpdir, filename) - Document.parse_stream(File.new(path), ReVIEWHeaderListener.new(headlines)) + htmlio = File.new(path) + Document.parse_stream(htmlio, ReVIEWHeaderListener.new(headlines)) properties = detect_properties(path) prop_str = '' prop_str = ',properties=' + properties.join(' ') if properties.present? @@ -382,6 +379,7 @@ def write_info_body(basetmpdir, _id, filename, ispart = nil, chaptype = nil) first = nil end end + htmlio.close end def push_contents(_basetmpdir)