HDK
|
#include <safeOutputFile.h>
Public Member Functions | |
TfSafeOutputFile ()=default | |
TfSafeOutputFile (TfSafeOutputFile &&other) | |
TfSafeOutputFile & | operator= (TfSafeOutputFile &&other) |
TF_API | ~TfSafeOutputFile () |
Destructor invokes Close(). More... | |
TF_API void | Close () |
TF_API void | Discard () |
FILE * | Get () const |
Return the opened FILE *. More... | |
TF_API FILE * | ReleaseUpdatedFile () |
TF_API bool | IsOpenForUpdate () const |
Static Public Member Functions | |
static TF_API TfSafeOutputFile | Update (std::string const &fileName) |
Open fileName for update ("r+"). More... | |
static TF_API TfSafeOutputFile | Replace (std::string const &fileName) |
Opens a file for output, either for update "r+" or to completely replace "w+". In the case of complete replacement, create a sibling temporary file to write to instead. When writing is complete, rename the temporary file over the target file. This provides some safety to other processes reading the existing file (at least on unix-like OSs). They will continue to see the existing contents of the old file. If we overwrote the file itself, then those other processes would see undefined, possibly partially updated content.
Definition at line 49 of file safeOutputFile.h.
|
default |
|
inline |
Definition at line 56 of file safeOutputFile.h.
Close the file. If the file was opened with Replace(), rename the temporary file over the target file to replace it.
Close the file. If the file was opened with Replace(), the temporary file is removed and not renamed over the target file. It is an error to call this for files opened for Update.
|
inline |
Return the opened FILE *.
Definition at line 91 of file safeOutputFile.h.
TF_API bool TfSafeOutputFile::IsOpenForUpdate | ( | ) | const |
Return true if this TfSafeOutputFile was created by a call to Update(), false otherwise.
|
inline |
Definition at line 62 of file safeOutputFile.h.
TF_API FILE* TfSafeOutputFile::ReleaseUpdatedFile | ( | ) |
If the underlying file was opened by Update(), return it. The caller takes responsibility for closing the file later. It is an error to call this for files opened for Replace.
|
static |
Arrange for fileName
to be replaced. Create a sibling temporary file and open that for writing. When Close() is called (or the destructor is run) close the temporary file and rename it over fileName
.
|
static |
Open fileName
for update ("r+").