diff --git a/application/main.cpp b/application/main.cpp index c8af213..3142703 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -55,6 +55,7 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg) : forceRewriteArg("force-rewrite", '\0', "forces the file to rewritten from the scratch which ensures a backup is created and the preferred padding is used"), valuesArg("values", 'n', "specifies the values to be set"), outputFilesArg("output-files", 'o', "specifies the output files; if present, the files specified with --files will not be modified"), + backupDirArg("temp-dir", '\0', "specifies the directory for temporary/backup files", {"path"}), setTagInfoArg("set", 's', "sets the specified tag information and attachments") { docTitleArg.setCombinable(true); @@ -150,7 +151,7 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg) : setTagInfoArg.setSubArguments({&valuesArg, &filesArg, &docTitleArg, &removeOtherFieldsArg, &treatUnknownFilesAsMp3FilesArg, &id3v1UsageArg, &id3v2UsageArg, &id3InitOnCreateArg, &id3TransferOnRemovalArg, &mergeMultipleSuccessiveTagsArg, &id3v2VersionArg, &encodingArg, &removeTargetArg, &addAttachmentArg, &updateAttachmentArg, &removeAttachmentArg, &removeExistingAttachmentsArg, &minPaddingArg, &maxPaddingArg, &prefPaddingArg, &tagPosArg, - &indexPosArg, &forceRewriteArg, &verboseArg, &outputFilesArg}); + &indexPosArg, &forceRewriteArg, &backupDirArg, &verboseArg, &outputFilesArg}); } } diff --git a/cli/mainfeatures.cpp b/cli/mainfeatures.cpp index 0772714..2aed726 100644 --- a/cli/mainfeatures.cpp +++ b/cli/mainfeatures.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef TAGEDITOR_JSON_EXPORT # include @@ -446,6 +447,11 @@ void setTagInfo(const SetTagInfoArgs &args) fileInfo.setForceIndexPosition(args.forceIndexPosArg.isPresent()); fileInfo.setForceRewrite(args.forceRewriteArg.isPresent()); + // set backup path + if(args.backupDirArg.isPresent()) { + BackupHelper::backupDirectory() = args.backupDirArg.values().front(); + } + // iterate through all specified files unsigned int fileIndex = 0; static const string context("setting tags"); @@ -498,14 +504,12 @@ void setTagInfo(const SetTagInfoArgs &args) denotedValues.relevantValues.clear(); unsigned int currentFileIndex = 0; for(FieldValue &denotatedValue : denotedValues.allValues) { - if(denotatedValue.fileIndex <= fileIndex) { - if(relevantDenotedValues.empty() || (denotatedValue.fileIndex >= currentFileIndex)) { - if(currentFileIndex != denotatedValue.fileIndex) { - currentFileIndex = denotatedValue.fileIndex; - relevantDenotedValues.clear(); - } - relevantDenotedValues.push_back(&denotatedValue); + if((denotatedValue.fileIndex <= fileIndex) && (relevantDenotedValues.empty() || (denotatedValue.fileIndex >= currentFileIndex))) { + if(currentFileIndex != denotatedValue.fileIndex) { + currentFileIndex = denotatedValue.fileIndex; + relevantDenotedValues.clear(); } + relevantDenotedValues.push_back(&denotatedValue); } } } diff --git a/cli/mainfeatures.h b/cli/mainfeatures.h index 72f0ef2..032bc2d 100644 --- a/cli/mainfeatures.h +++ b/cli/mainfeatures.h @@ -41,6 +41,7 @@ struct SetTagInfoArgs ApplicationUtilities::Argument forceRewriteArg; ApplicationUtilities::Argument valuesArg; ApplicationUtilities::Argument outputFilesArg; + ApplicationUtilities::ConfigValueArgument backupDirArg; ApplicationUtilities::Argument setTagInfoArg; }; diff --git a/tests/cli.cpp b/tests/cli.cpp index d056581..a495133 100644 --- a/tests/cli.cpp +++ b/tests/cli.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ class CliTests : public TestFixture CPPUNIT_TEST(testEncodingOption); CPPUNIT_TEST(testMultipleFiles); CPPUNIT_TEST(testOutputFile); + CPPUNIT_TEST(testBackupDir); CPPUNIT_TEST(testMultipleValuesPerField); CPPUNIT_TEST(testHandlingAttachments); CPPUNIT_TEST(testDisplayingInfo); @@ -63,6 +65,7 @@ public: void testEncodingOption(); void testMultipleFiles(); void testOutputFile(); + void testBackupDir(); void testMultipleValuesPerField(); void testHandlingAttachments(); void testDisplayingInfo(); @@ -492,6 +495,34 @@ void CliTests::testOutputFile() remove("/tmp/test1.mkv"), remove("/tmp/test2.mkv"); } +/*! + * \brief Tests the "--temp-dir /some/path" option of the set operation. + */ +void CliTests::testBackupDir() +{ + cout << "\nSpecifying a backup/temp dir for set operation" << endl; + string stdout, stderr; + const string mkvFileName("matroska_wave1/test1.mkv"); + const auto mkvFile(workingCopyPath(mkvFileName)); + CPPUNIT_ASSERT(mkvFile.size() >= mkvFileName.size()); + const auto backupDir(mkvFile.substr(0, mkvFile.size() - mkvFileName.size())); + + const char *const args1[] = {"tageditor", "set", "target-level=30", "title=test1","-f", mkvFile.data(), "--temp-dir", "..", nullptr}; + TESTUTILS_ASSERT_EXEC(args1); + + // specified output file contains new title + const char *const args2[] = {"tageditor", "get", "-f", mkvFile.data(), nullptr}; + TESTUTILS_ASSERT_EXEC(args2); + CPPUNIT_ASSERT(testContainsSubstrings(stdout, { + " - \e[1mMatroska tag targeting \"level 30 'track, song, chapter'\"\e[0m\n" + " Title test1\n", + })); + + CPPUNIT_ASSERT_EQUAL(0, remove(mkvFile.data())); + CPPUNIT_ASSERT_EQUAL(0, remove((backupDir + "test1.mkv").data())); + CPPUNIT_ASSERT(remove((mkvFile + ".bak").c_str())); +} + /*! * \brief Tests tagging multiple values per field. */