From c25a3be659c7bc0184bade25e5c853e1b5e7d4f1 Mon Sep 17 00:00:00 2001 From: Jeff Parsons Date: Fri, 6 Feb 2015 11:07:26 -0800 Subject: [PATCH] Fixed a fatal bug in DiskDump when using the --dir option --- modules/diskdump/lib/diskdump.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/diskdump/lib/diskdump.js b/modules/diskdump/lib/diskdump.js index 660168dbd..1be4a15f3 100644 --- a/modules/diskdump/lib/diskdump.js +++ b/modules/diskdump/lib/diskdump.js @@ -1729,6 +1729,12 @@ DiskDump.prototype.buildClusters = function(aFiles, offDisk, cbCluster, iParentC this.cWritesPending++; (function readClusters(file, cb, off) { fs.readFile(file.FILE_PATH, function doneReadClusters(err, buf) { + /* + * If cWritesPending has been prematurely zeroed, we assume that's because the buildClusters() + * caller discovered a problem (eg, the total number of clusters exceeds what can fit in the image), + * so we bail. + */ + if (!obj.cWritesPending) return; if (!err) { if (fDebug && cb != buf.length) DiskDump.logConsole(file.FILE_NAME + ": initial size (" + cb + ") does not match actual size (" + buf.length + ")"); buf.copy(obj.bufDisk, off); @@ -1777,7 +1783,7 @@ DiskDump.prototype.buildClusters = function(aFiles, offDisk, cbCluster, iParentC } } - if (iLevel) { + if (!iLevel) { if (!this.cWritesPending) done(null); } @@ -2070,11 +2076,11 @@ DiskDump.prototype.buildImageFromFiles = function(aFiles, done) if (offDisk > cbDisk) { err = new Error("too much data for disk image (" + cClusters + " clusters required)"); + this.cWritesPending = 0; done(err); return false; } - done(null); return true; };