Skip to content

Commit

Permalink
Fix for an Issue #532
Browse files Browse the repository at this point in the history
  • Loading branch information
stamparm committed Sep 30, 2013
1 parent 1f2e5a9 commit 45c88b3
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/core/dump.py
Expand Up @@ -525,18 +525,21 @@ def dbTableValues(self, tableValues):
self._write("| %s%s" % (value, blank), newline=False, console=console)

if len(value) > MIN_BINARY_DISK_DUMP_SIZE and r'\x' in value:
mimetype = magic.from_buffer(value, mime=True)
if any(mimetype.startswith(_) for _ in ("application", "image")):
if not os.path.isdir(dumpDbPath):
os.makedirs(dumpDbPath, 0755)

filepath = os.path.join(dumpDbPath, "%s-%d.bin" % (unsafeSQLIdentificatorNaming(column), randomInt(8)))
warnMsg = "writing binary ('%s') content to file '%s' " % (mimetype, filepath)
logger.warn(warnMsg)

with open(filepath, "wb") as f:
_ = safechardecode(value, True)
f.write(_)
try:
mimetype = magic.from_buffer(value, mime=True)
if any(mimetype.startswith(_) for _ in ("application", "image")):
if not os.path.isdir(dumpDbPath):
os.makedirs(dumpDbPath, 0755)

filepath = os.path.join(dumpDbPath, "%s-%d.bin" % (unsafeSQLIdentificatorNaming(column), randomInt(8)))
warnMsg = "writing binary ('%s') content to file '%s' " % (mimetype, filepath)
logger.warn(warnMsg)

with open(filepath, "wb") as f:
_ = safechardecode(value, True)
f.write(_)
except magic.MagicException, err:
logger.debug(str(err))

if conf.dumpFormat == DUMP_FORMAT.CSV:
if field == fields:
Expand Down

0 comments on commit 45c88b3

Please sign in to comment.