Skip to content

Commit 4117d06

Browse files
committed
Move final file if in same file system, not only in same directory
1 parent ce6ccc2 commit 4117d06

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ build
2525
.mypy_cache
2626
*.whl
2727
venv
28+
/.vs

src/plotter_disk.hpp

+23-13
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,31 @@ class DiskPlotter {
382382
}
383383
} else {
384384
if (!bCopied) {
385-
fs::copy(
386-
tmp_2_filename, final_2_filename, fs::copy_options::overwrite_existing, ec);
385+
fs::rename(tmp_2_filename, final_filename, ec);
387386
if (ec.value() != 0) {
388-
std::cout << "Could not copy " << tmp_2_filename << " to "
389-
<< final_2_filename << ". Error " << ec.message()
390-
<< ". Retrying in five minutes." << std::endl;
387+
fs::copy(
388+
tmp_2_filename,
389+
final_2_filename,
390+
fs::copy_options::overwrite_existing,
391+
ec);
392+
if (ec.value() != 0) {
393+
std::cout << "Could not copy " << tmp_2_filename << " to "
394+
<< final_2_filename << ". Error " << ec.message()
395+
<< ". Retrying in five minutes." << std::endl;
396+
} else {
397+
std::cout << "Copied final file from " << tmp_2_filename << " to "
398+
<< final_2_filename << std::endl;
399+
copy.PrintElapsed("Copy time =");
400+
bCopied = true;
401+
402+
bool removed_2 = fs::remove(tmp_2_filename);
403+
std::cout << "Removed temp2 file " << tmp_2_filename << "? "
404+
<< removed_2 << std::endl;
405+
}
391406
} else {
392-
std::cout << "Copied final file from " << tmp_2_filename << " to "
393-
<< final_2_filename << std::endl;
394-
copy.PrintElapsed("Copy time =");
395-
bCopied = true;
396-
397-
bool removed_2 = fs::remove(tmp_2_filename);
398-
std::cout << "Removed temp2 file " << tmp_2_filename << "? " << removed_2
399-
<< std::endl;
407+
bRenamed = true;
408+
std::cout << "Renamed final file from " << tmp_2_filename << " to "
409+
<< final_filename << std::endl;
400410
}
401411
}
402412
if (bCopied && (!bRenamed)) {

0 commit comments

Comments
 (0)