Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If tmp2 and final files are in same filesystem, rename() not copy() #314

Merged
merged 5 commits into from Jan 29, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/plotter_disk.hpp
Expand Up @@ -23,6 +23,7 @@

#include <math.h>
#include <stdio.h>
#include <sys/stat.h>

#include <algorithm>
#include <fstream>
Expand Down Expand Up @@ -370,7 +371,13 @@ class DiskPlotter {
Timer copy;
do {
std::error_code ec;
if (tmp_2_filename.parent_path() == final_filename.parent_path()) {
struct stat tmp2_stat, final_stat;
int rc;
rc = ::stat(reinterpret_cast<const char *>(tmp_2_filename.c_str()), &tmp2_stat);
if (rc == 0)
rc = ::stat(reinterpret_cast<const char *>(final_filename.parent_path().c_str()), &final_stat);
if ((rc == 0 && tmp2_stat.st_dev == final_stat.st_dev) ||
tmp_2_filename.parent_path() == final_filename.parent_path()) {
fs::rename(tmp_2_filename, final_filename, ec);
if (ec.value() != 0) {
std::cout << "Could not rename " << tmp_2_filename << " to " << final_filename
Expand Down