Closed t-w closed 7 months ago
Probably have to start from putting diagnostics on everything possible - in many cases return status of the functions is not checked...
File (object) state management seems overcomplex, hard to debug and make robust:
posInDataBlk
- to calculate from pos
But... if there will be no reasonable way to untangle and simplify it, it may be necessary to redesign and rewrite the whole adf_file
module...
File size in file header in set only in adfFlushFile in the following way:
file->fileHdr->byteSize = file->pos;
meaning:
Invalidating current data block buffer (.currentData
in struct adfFile
) seems best to be done by setting .curDataPtr
to 0 (no data block can be stored in sector/block 0).
Otherwise eg. a new var. will have to be introduced (but this increases amount of things to keep consistent as state...).
Should seek operations read/write data?
If seek will not read/write data:
If going for the second (dropping any data operations when seeking):
To decide... (dropping data ops seems simpler -> more robust -> better?).
So, after a few approaches decided to go back to what was there. Mentioned above things (dropping data operation when seeking etc. would require deep redesign (maybe even rewriting most) of the file api module. So in the end - keeping original way - current datablock always in the buffer (unless no data - an empty file)
Maybe some future revision or a fork/rewrite will change this. For now - it works well enough.
One thing is missing - seeking while writing (after a write operation) should write current buffer (can be modified). The trouble is that there is no info whether the buffer was modified... Just adding writing the buffer would write on every seek operation (in write mode)... No sure what to do with it, yet...
(but to implement somehow - with a test).
Plenty to fix (see also lclevy/ADFlib#30). I will put some notes on this here.