Packer library enhancement

Everything else that doesn't fall into one of the other PB categories.
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Packer library enhancement

Post by Bitblazer »

If you use the packer library, you do stuff like

Code: Select all

createpack()
addpackfile() / addpackmemory()
closepack()
and you always work with a "pack ID" you get by the createpack() command if you use #pb_any (unless you use a static ID).

My problem was, that if you want to reliably make sure an archive is physically written to the media, how do i achieve that? I wouldnt want to tell the user "Ok everything is fine" and instantly allow them to remove the media while actually the windows OS has the most recent change not written to the physical media, but just in a buffer/cache marked as "dirty" so at a later shutdown, it would be written to the media.

Imagine a user does a backup on a removeable media. The media could be removed before the changed cache is physically written to the media, therefore the media and archive would be in a corrupt state.

That is an old basic problem of all operating systems with removeable media. Unixes therefore "lock" the media and whoever removes the media without unlocking it first (aka ejecting it which writes all dirty cache pages physically to a media) ends up with an inconsistent logical media. PureBasic offers the flushfilebuffers command to avoid that. The problem is - the command requires a "fileid" but the packer library uses a packer library id.

So how to solve this problem officially to make the packer library reliably useable on removable media?

An official command like flushfilebuffers which works with a pack ID maybe? Alternatively an official way to get a file ID from an open packer library archive which can be used after closepack() - but that would seem a bit dirty for this usecase.
webpage - discord chat links -> purebasic GPT4All
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: Packer library enhancement

Post by Thorium »

I would assume the file is completely written to disk after closepack(). Thats usually how OS handles disk writes, buffers are written to disk after the handle for the file is closed to prevent data loss on unexpected power loss, etc.
However it's up to the OS configuration if it still buffers after the handle is closed. PB does not offer a flushwritebuffer for the packer library.
Post Reply