Tag Parser
6.2.2
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
|
Helps to create and restore backup files when rewriting files to apply changed tag information. More...
Functions | |
TAG_PARSER_EXPORT std::string & | backupDirectory () |
Returns the directory used to store backup files. More... | |
TAG_PARSER_EXPORT void | restoreOriginalFileFromBackupFile (const std::string &originalPath, const std::string &backupPath, IoUtilities::NativeFileStream &originalStream, IoUtilities::NativeFileStream &backupStream) |
TAG_PARSER_EXPORT void | createBackupFile (const std::string &originalPath, std::string &backupPath, IoUtilities::NativeFileStream &originalStream, IoUtilities::NativeFileStream &backupStream) |
TAG_PARSER_EXPORT void | handleFailureAfterFileModified (MediaFileInfo &mediaFileInfo, const std::string &backupPath, IoUtilities::NativeFileStream &outputStream, IoUtilities::NativeFileStream &backupStream, const std::string &context="making file") |
void | restoreOriginalFileFromBackupFile (const std::string &originalPath, const std::string &backupPath, NativeFileStream &originalStream, NativeFileStream &backupStream) |
Restores the original file from the specified backup file. More... | |
void | createBackupFile (const std::string &originalPath, std::string &backupPath, NativeFileStream &originalStream, NativeFileStream &backupStream) |
Creates a backup file for the specified file. More... | |
void | handleFailureAfterFileModified (MediaFileInfo &fileInfo, const std::string &backupPath, NativeFileStream &outputStream, NativeFileStream &backupStream, const std::string &context) |
Handles a failure/abort which occured after the file has been modified. More... | |
Helps to create and restore backup files when rewriting files to apply changed tag information.
Methods in this namespace are internally used eg. in implementations of AbstractContainer::internalMake().
string & Media::BackupHelper::backupDirectory | ( | ) |
Returns the directory used to store backup files.
Setting this value allows creation of backup files in a custom location instead of the directory of the file being modified.
Definition at line 41 of file backuphelper.cpp.
TAG_PARSER_EXPORT void Media::BackupHelper::createBackupFile | ( | const std::string & | originalPath, |
std::string & | backupPath, | ||
IoUtilities::NativeFileStream & | originalStream, | ||
IoUtilities::NativeFileStream & | backupStream | ||
) |
void Media::BackupHelper::createBackupFile | ( | const std::string & | originalPath, |
std::string & | backupPath, | ||
NativeFileStream & | originalStream, | ||
NativeFileStream & | backupStream | ||
) |
Creates a backup file for the specified file.
originalPath | Specifies the path of the file to be backuped. |
backupPath | Contains the path of the created backup file when this function returns. |
originalStream | Specifies a std::fstream for the original file. |
backupStream | Specifies a std::fstream for creating the backup file. |
This helper function is used by MediaFileInfo and container implementations to create a backup file when applying changes. The path of the created backup file is set to backup path. The specified backupStream will be closed if currently open. Then it is used to open the backup file using the flags ios_base::in and ios_base::binary.
The specified originalStream is closed before performing the move operation.
If moving isn't possible (eg. originalPath and backupPath refer to different partitions) the backup file will be created by copying.
The original file can now be rewritten to apply changes. When this operation fails the created backup file can be restored using restoreOriginalFileFromBackupFile().
Throws | std::ios_base::failure on failure. |
Definition at line 121 of file backuphelper.cpp.
TAG_PARSER_EXPORT void Media::BackupHelper::handleFailureAfterFileModified | ( | MediaFileInfo & | mediaFileInfo, |
const std::string & | backupPath, | ||
IoUtilities::NativeFileStream & | outputStream, | ||
IoUtilities::NativeFileStream & | backupStream, | ||
const std::string & | context = "making file" |
||
) |
void Media::BackupHelper::handleFailureAfterFileModified | ( | MediaFileInfo & | fileInfo, |
const std::string & | backupPath, | ||
NativeFileStream & | outputStream, | ||
NativeFileStream & | backupStream, | ||
const std::string & | context | ||
) |
Handles a failure/abort which occured after the file has been modified.
fileInfo | Specifies the MediaFileInfo instace which has been modified. |
backupPath | Specifies the path of the backup file; might be empty if none has been created. |
outputStream | Specifies the stream used to write the output file. This is usually just the stream of fileInfo, but is specified here explicitly for higher flexibility. |
backupStream | Specifies the stream assembled using createBackupFile(); might be a default fstream if no backup file has been created. |
context | Specifies the context used to add notifications. |
Definition at line 255 of file backuphelper.cpp.
TAG_PARSER_EXPORT void Media::BackupHelper::restoreOriginalFileFromBackupFile | ( | const std::string & | originalPath, |
const std::string & | backupPath, | ||
IoUtilities::NativeFileStream & | originalStream, | ||
IoUtilities::NativeFileStream & | backupStream | ||
) |
void Media::BackupHelper::restoreOriginalFileFromBackupFile | ( | const std::string & | originalPath, |
const std::string & | backupPath, | ||
NativeFileStream & | originalStream, | ||
NativeFileStream & | backupStream | ||
) |
Restores the original file from the specified backup file.
originalPath | Specifies the path to the original file. |
backupPath | Specifies the path to the backup file. |
originalStream | Specifies a std::fstream instance for the original file. |
backupStream | Specifies a std::fstream instance for the backup file. |
This helper function is used by MediaFileInfo and container implementations to restore the original file from the specified backup file in the case a Failure or an IO error occurs. The specified streams will be closed if currently open.
If moving isn't possible (eg. originalPath and backupPath refer to different partitions) the backup file will be restored by copying.
Throws | std::ios_base::failure on failure. |
Definition at line 64 of file backuphelper.cpp.