Tag Parser  7.0.3
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Functions
TagParser::BackupHelper Namespace Reference

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, Diagnostics &diag, 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, Diagnostics &diag, const std::string &context)
 Handles a failure/abort which occured after the file has been modified. More...
 

Function Documentation

◆ backupDirectory()

string & TagParser::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.

Todo:
Add this as member variable to MediaFileInfo to avoid global.

Definition at line 44 of file backuphelper.cpp.

◆ createBackupFile() [1/2]

TAG_PARSER_EXPORT void TagParser::BackupHelper::createBackupFile ( const std::string &  originalPath,
std::string &  backupPath,
IoUtilities::NativeFileStream &  originalStream,
IoUtilities::NativeFileStream &  backupStream 
)

◆ createBackupFile() [2/2]

void TagParser::BackupHelper::createBackupFile ( const std::string &  originalPath,
std::string &  backupPath,
NativeFileStream &  originalStream,
NativeFileStream &  backupStream 
)

Creates a backup file for the specified file.

Parameters
originalPathSpecifies the path of the file to be backuped.
backupPathContains the path of the created backup file when this function returns.
originalStreamSpecifies a std::fstream for the original file.
backupStreamSpecifies 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 specified backupPath is set to the path of the created backup file. 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().

Exceptions
Throwsstd::ios_base::failure on failure.
Todo:
Implement callback for progress updates (copy).

Definition at line 135 of file backuphelper.cpp.

◆ handleFailureAfterFileModified() [1/2]

TAG_PARSER_EXPORT void TagParser::BackupHelper::handleFailureAfterFileModified ( MediaFileInfo mediaFileInfo,
const std::string &  backupPath,
IoUtilities::NativeFileStream &  outputStream,
IoUtilities::NativeFileStream &  backupStream,
Diagnostics diag,
const std::string &  context = "making file" 
)

◆ handleFailureAfterFileModified() [2/2]

void TagParser::BackupHelper::handleFailureAfterFileModified ( MediaFileInfo fileInfo,
const std::string &  backupPath,
NativeFileStream &  outputStream,
NativeFileStream &  backupStream,
Diagnostics diag,
const std::string &  context 
)

Handles a failure/abort which occured after the file has been modified.

  • Restores the backup file using restoreOriginalFileFromBackupFile() if one has been created.
  • Adds appropriate notifications to the specified fileInfo.
  • Re-throws the exception.
Remarks
Must only be called when an exception derived from Failure or ios_base::failure has been catched; this method uses the "exception dispatcher" idiom.
Parameters
fileInfoSpecifies the MediaFileInfo instace which has been modified.
backupPathSpecifies the path of the backup file; might be empty if none has been created.
outputStreamSpecifies the stream used to write the output file. This is usually just the stream of fileInfo, but is specified here explicitly for higher flexibility.
backupStreamSpecifies the stream assembled using createBackupFile(); might be a default fstream if no backup file has been created.
contextSpecifies the context used to add notifications.

Definition at line 250 of file backuphelper.cpp.

◆ restoreOriginalFileFromBackupFile() [1/2]

TAG_PARSER_EXPORT void TagParser::BackupHelper::restoreOriginalFileFromBackupFile ( const std::string &  originalPath,
const std::string &  backupPath,
IoUtilities::NativeFileStream &  originalStream,
IoUtilities::NativeFileStream &  backupStream 
)

◆ restoreOriginalFileFromBackupFile() [2/2]

void TagParser::BackupHelper::restoreOriginalFileFromBackupFile ( const std::string &  originalPath,
const std::string &  backupPath,
NativeFileStream &  originalStream,
NativeFileStream &  backupStream 
)

Restores the original file from the specified backup file.

Parameters
originalPathSpecifies the path to the original file.
backupPathSpecifies the path to the backup file.
originalStreamSpecifies a std::fstream instance for the original file.
backupStreamSpecifies 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.

Exceptions
Throwsstd::ios_base::failure on failure.
Todo:
Implement callback for progress updates (copy).

Definition at line 68 of file backuphelper.cpp.