Skip to content

Commit

Permalink
Final updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Dec 6, 2023
1 parent 88fec8e commit 86fba5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Converter
{
for(const auto& atomicFile : m_AtomicFiles)
{
atomicFile.commit();
atomicFile->commit();
}
}
}
Expand Down Expand Up @@ -81,12 +81,13 @@ class Converter
}

std::istringstream headerStream(origHeader, std::ios_base::in | std::ios_base::binary);
m_AtomicFiles.emplace_back((fs::absolute(m_OutputPath) / (m_FilePrefix + inputPath.filename().string())), false);
fs::path outPath = m_AtomicFiles[m_Index].tempFilePath();
m_AtomicFiles.emplace_back(std::make_unique<AtomicFile>((fs::absolute(m_OutputPath) / (m_FilePrefix + inputPath.filename().string())), false));
fs::path outPath = m_AtomicFiles[m_Index]->tempFilePath();

if(!fs::exists(inputPath.parent_path()))
// Ensure the output path exists by creating it if necessary
if(!fs::exists(m_OutputPath))
{
auto result = m_AtomicFiles[m_Index].createOutputDirectories();
auto result = m_AtomicFiles[m_Index]->createOutputDirectories();
if(result.invalid())
{
m_Valid = false;
Expand All @@ -101,11 +102,10 @@ class Converter
}

std::ofstream outFile(outPath, std::ios_base::out | std::ios_base::binary);
// Ensure the output path exists by creating it if necessary
if(!fs::exists(outPath.parent_path()))
if(!fs::exists(outPath))
{
m_Valid = false;
return MakeErrorResult(-77750, fmt::format("The parent path was not created and does not exist: {}", outPath.parent_path().string()));
return MakeErrorResult(-77750, fmt::format("The parent path was not created and does not exist: {}", outPath.string()));
}

if(!outFile.is_open())
Expand Down Expand Up @@ -228,7 +228,7 @@ class Converter
const std::atomic_bool& m_ShouldCancel;
const fs::path& m_OutputPath;
const std::string& m_FilePrefix;
std::vector<AtomicFile> m_AtomicFiles = {};
std::vector<std::unique_ptr<AtomicFile>> m_AtomicFiles = {};
usize m_Index = 0;
bool m_Valid = true;

Expand Down
5 changes: 5 additions & 0 deletions src/complex/Common/AtomicFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ fs::path AtomicFile::tempFilePath() const

void AtomicFile::commit() const
{
if(!fs::exists(m_TempFilePath))
{
throw std::runtime_error(m_TempFilePath.string() + " does not exist");
}

fs::rename(m_TempFilePath, m_FilePath);
}

Expand Down

0 comments on commit 86fba5d

Please sign in to comment.