OpendTect
6.6
|
Protects file IO when you can't afford to have partly written things after write errors or have a file garbled by multiple access. More...
Public Member Functions | |
SafeFileIO (const char *, bool locked=false) | |
~SafeFileIO () | |
void | closeFail (bool keeplock=false) |
bool | closeSuccess (bool keeplock=false) |
const char * | errMsg () const |
const char * | fileName () const |
od_istream & | istrm () |
bool | open (bool forread, bool ignorelock=false) |
od_ostream & | ostrm () |
bool | remove () |
Public Attributes | |
bool | allowlockremove_ |
int | lockretries_ |
default=10 More... | |
double | lockwaitincr_ |
default=0.5 (seconds) More... | |
bool | removebakonsuccess_ |
default=false More... | |
bool | usebakwhenmissing_ |
default=true More... | |
Protected Member Functions | |
bool | commitWrite () |
bool | doClose (bool, bool) |
bool | haveLock () const |
void | mkLock (bool) |
bool | openRead (bool) |
bool | openWrite (bool) |
void | rmLock () |
bool | waitForLock () const |
Protected Attributes | |
const BufferString | bakfnm_ |
BufferString | errmsg_ |
const BufferString | filenm_ |
const bool | locked_ |
const BufferString | lockfnm_ |
const BufferString | newfnm_ |
od_stream * | strm_ |
Protects file IO when you can't afford to have partly written things after write errors or have a file garbled by multiple access.
Use the locking only when multiple processes can concurrently write to the same file. For most purposes, you won't need the locking, which is kind of expensive, too.
Note that you can either read or write the file, not both at the same time. At the end, one of closeFail() or closeSuccess() is absolutely mandatory. Thus, when something goes wrong during writing, use closeFail(), otherwise use closeSuccess(). For writing, these do different things, and closeSuccess() can fail.
When you write, you write to a new file, which will be renamed to the target filename on success (after the previous version is renamed to .bak). Note that success during writing (i.e. the integrity of the newly written file) is something you determine yourself.
When you use locking, you sometimes need to re-read the original file before writing. In that case, you need to keep the lock that was made for the reading. There is where you want to use the 'ignorelock' and 'keeplock' flags. Otherwise, don't specify these.
<>
SafeFileIO::SafeFileIO | ( | const char * | , |
bool | locked = false |
||
) |
SafeFileIO::~SafeFileIO | ( | ) |
|
inline |
|
inline |
|
protected |
|
protected |
|
inline |
|
inline |
|
protected |
od_istream& SafeFileIO::istrm | ( | ) |
|
protected |
bool SafeFileIO::open | ( | bool | forread, |
bool | ignorelock = false |
||
) |
|
protected |
|
protected |
od_ostream& SafeFileIO::ostrm | ( | ) |
bool SafeFileIO::remove | ( | ) |
|
protected |
|
protected |
bool SafeFileIO::allowlockremove_ |
default=true when true, will remove the lock after retries i.e. we'll assume the lock is phony then this is –safety but ++robustness
|
protected |
|
mutableprotected |
|
protected |
|
protected |
|
protected |
int SafeFileIO::lockretries_ |
default=10
double SafeFileIO::lockwaitincr_ |
default=0.5 (seconds)
|
protected |
bool SafeFileIO::removebakonsuccess_ |
default=false
|
protected |
bool SafeFileIO::usebakwhenmissing_ |
default=true
Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2022