Skip to content

Commit

Permalink
Create output directory if string contains slash + fix typo affecting…
Browse files Browse the repository at this point in the history
… building with older compilers
  • Loading branch information
bepaald committed Jun 28, 2021
1 parent e8ed688 commit f3db274
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion autoversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
#ifndef VERSION_H_
#define VERSION_H_

#define VERSIONDATE "20210611.164219"
#define VERSIONDATE "20210628.222742"

#endif
1 change: 1 addition & 0 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ int main(int argc, char *argv[])
return 1;
}

// check output exists (file exists OR dir is not empty)
if (!arg.output().empty() && bepaald::fileOrDirExists(arg.output()) &&
((!bepaald::isDir(arg.output()) || (bepaald::isDir(arg.output()) && !bepaald::isEmpty(arg.output()))) &&
!arg.overwrite()))
Expand Down
2 changes: 1 addition & 1 deletion signalbackup/exporttodir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool SignalBackup::exportBackupToDir(std::string const &directory, bool overwrit
for (int count = 1; auto const &kvframe : d_keyvalueframes)
#else
count = 1;
for (auto const &fvframe : d_keyvalueframes)
for (auto const &kvframe : d_keyvalueframes)
#endif
if (!writeRawFrameDataToFile(directory + "/KeyValue_" + bepaald::toString(count++) + ".sbf", kvframe))
return false;
Expand Down
17 changes: 17 additions & 0 deletions signalbackup/signalbackup.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,25 @@ inline SignalBackup::SignalBackup(std::string const &filename, std::string const
inline bool SignalBackup::exportBackup(std::string const &filename, std::string const &passphrase, bool overwrite,
bool keepattachmentdatainmemory, bool onlydb)
{
// if output is existing directory
if (bepaald::fileOrDirExists(filename) && bepaald::isDir(filename))
return exportBackupToDir(filename, overwrite, keepattachmentdatainmemory, onlydb);

// if output does not exist, but ends in directory delimiter
if (!bepaald::fileOrDirExists(filename) &&
(filename.back() == '/' || filename.back() == std::filesystem::path::preferred_separator))
{
// create dir
std::error_code ec;
if (!std::filesystem::create_directory(filename, ec))
{
std::cout << "Error: Failed to create directory \"" << filename << "\"" << std::endl;
return false;
}
return exportBackupToDir(filename, overwrite, keepattachmentdatainmemory, onlydb);
}

// export to file
return exportBackupToFile(filename, passphrase, overwrite, keepattachmentdatainmemory);
}

Expand Down

0 comments on commit f3db274

Please sign in to comment.