Skip to content

Commit

Permalink
Move final file if in same file system, not only in same directory
Browse files Browse the repository at this point in the history
  • Loading branch information
aydreas committed Apr 26, 2021
1 parent ce6ccc2 commit 4117d06
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build
.mypy_cache
*.whl
venv
/.vs
36 changes: 23 additions & 13 deletions src/plotter_disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,31 @@ class DiskPlotter {
}
} else {
if (!bCopied) {
fs::copy(
tmp_2_filename, final_2_filename, fs::copy_options::overwrite_existing, ec);
fs::rename(tmp_2_filename, final_filename, ec);
if (ec.value() != 0) {
std::cout << "Could not copy " << tmp_2_filename << " to "
<< final_2_filename << ". Error " << ec.message()
<< ". Retrying in five minutes." << std::endl;
fs::copy(
tmp_2_filename,
final_2_filename,
fs::copy_options::overwrite_existing,
ec);
if (ec.value() != 0) {
std::cout << "Could not copy " << tmp_2_filename << " to "
<< final_2_filename << ". Error " << ec.message()
<< ". Retrying in five minutes." << std::endl;
} else {
std::cout << "Copied final file from " << tmp_2_filename << " to "
<< final_2_filename << std::endl;
copy.PrintElapsed("Copy time =");
bCopied = true;

bool removed_2 = fs::remove(tmp_2_filename);
std::cout << "Removed temp2 file " << tmp_2_filename << "? "
<< removed_2 << std::endl;
}
} else {
std::cout << "Copied final file from " << tmp_2_filename << " to "
<< final_2_filename << std::endl;
copy.PrintElapsed("Copy time =");
bCopied = true;

bool removed_2 = fs::remove(tmp_2_filename);
std::cout << "Removed temp2 file " << tmp_2_filename << "? " << removed_2
<< std::endl;
bRenamed = true;
std::cout << "Renamed final file from " << tmp_2_filename << " to "
<< final_filename << std::endl;
}
}
if (bCopied && (!bRenamed)) {
Expand Down

0 comments on commit 4117d06

Please sign in to comment.