Allow ebook-metadata to work with read-only files when no options are specified to change metadata. Fixes #1504345 [ebook-meta does not work on read-only files](https://bugs.launchpad.net/calibre/+bug/1504345)

This commit is contained in:
Kovid Goyal 2015-10-09 07:44:22 +05:30
parent bc0c3d90a6
commit ecd94450e9

View File

@ -165,7 +165,6 @@ def main(args=sys.argv):
prints(_('No file specified'), file=sys.stderr)
return 1
path = args[1]
stream = open(path, 'r+b')
stream_type = os.path.splitext(path)[1].replace('.', '').lower()
trying_to_set = False
@ -175,6 +174,7 @@ def main(args=sys.argv):
if getattr(opts, pref.name) is not None:
trying_to_set = True
break
with open(path, 'rb') as stream:
mi = get_metadata(stream, stream_type, force_read_metadata=True)
if trying_to_set:
prints(_('Original metadata')+'::')
@ -184,7 +184,7 @@ def main(args=sys.argv):
prints(metadata, safe_encode=True)
if trying_to_set:
stream.seek(0)
with open(path, 'r+b') as stream:
do_set_metadata(opts, mi, stream, stream_type)
stream.seek(0)
stream.flush()