Compare commits

...

2 Commits

Author SHA1 Message Date
midnight
eb85e6a71f
Merge e9dc16194b47921ea6c5453e71c5c97b9232ba8c into cd8089c20baaaee329cbf7951195953a9f86d7cf 2025-03-16 17:15:59 +01:00
midnight
e9dc16194b correct the linearize-data script (minor)
this clips off unwanted final data in event of reorg and fixes the file open
mode to prevent the truncation of files reopened

small patch being passed around which I did not write but thought would be
helpful to the community at large
2025-02-19 02:03:15 -08:00

View File

@ -134,6 +134,7 @@ class BlockDataCopier:
def writeBlock(self, inhdr, blk_hdr, rawblock):
blockSizeOnDisk = len(inhdr) + len(blk_hdr) + len(rawblock)
if not self.fileOutput and ((self.outsz + blockSizeOnDisk) > self.maxOutSz):
os.ftruncate(self.outF.fileno(), self.outF.tell())
self.outF.close()
if self.setFileTime:
os.utime(self.outFname, (int(time.time()), self.highTS))
@ -147,6 +148,7 @@ class BlockDataCopier:
print("New month " + blkDate.strftime("%Y-%m") + " @ " + self.hash_str)
self.lastDate = blkDate
if self.outF:
os.ftruncate(self.outF.fileno(), self.outF.tell())
self.outF.close()
if self.setFileTime:
os.utime(self.outFname, (int(time.time()), self.highTS))
@ -161,7 +163,10 @@ class BlockDataCopier:
else:
self.outFname = os.path.join(self.settings['output'], "blk%05d.dat" % self.outFn)
print("Output file " + self.outFname)
self.outF = open(self.outFname, "wb")
try:
self.outF = open(self.outFname, "xb+")
except FileExistsError:
self.outF = open(self.outFname, "rb+")
self.outF.write(inhdr)
self.outF.write(blk_hdr)