Add minimal error handling.
This commit is contained in:
parent
654aa1df78
commit
3be9413d68
1 changed files with 13 additions and 0 deletions
13
bin/cbr2cbz
13
bin/cbr2cbz
|
@ -2,6 +2,9 @@
|
|||
|
||||
require 'fileutils'
|
||||
|
||||
class UnrarError < RuntimeError ; end
|
||||
class ZipError < RuntimeError ; end
|
||||
|
||||
where = Dir.pwd
|
||||
|
||||
ARGV.each do |arg|
|
||||
|
@ -12,11 +15,21 @@ ARGV.each do |arg|
|
|||
|
||||
name = File.basename(arg).dup
|
||||
name.gsub!(/\.cbr/i,'')
|
||||
if File.exists? name then
|
||||
FileUtils.rm_rf name
|
||||
end
|
||||
FileUtils.mkdir_p name
|
||||
Dir.chdir name
|
||||
system "unrar e \"#{cbr_path}\""
|
||||
if not $?.success? then
|
||||
raise UnrarError
|
||||
end
|
||||
|
||||
Dir.chdir where
|
||||
system "zip -r \"#{cbz_path}\" \"#{name}\""
|
||||
if not $?.success? then
|
||||
raise ZipError
|
||||
end
|
||||
FileUtils.rm_rf name
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue