From 6e178ab230f2bb47b488cc21f7f02598aa02a413 Mon Sep 17 00:00:00 2001 From: reubes Date: Tue, 22 Jun 2021 20:51:12 +0900 Subject: [PATCH 1/6] Update copy.h check available destination space before copy --- include/chia/copy.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/chia/copy.h b/include/chia/copy.h index d5054b4a..1964aae4 100644 --- a/include/chia/copy.h +++ b/include/chia/copy.h @@ -17,10 +17,17 @@ #include #include +#include +namespace fs = std::filesystem; inline uint64_t copy_file(const std::string& src_path, const std::string& dst_path) { + int plotsize = 109000000000 + fs::space_info tmp = fs::space(dst_path); + if(tmp.available < plotsize) { + throw std::runtime_error("Destination does not have enough available disk space left"); + } FILE* src = fopen(src_path.c_str(), "rb"); if(!src) { throw std::runtime_error("fopen() failed"); From 8f5f0f753e1c3d5fbb65dc010bcece4973315e83 Mon Sep 17 00:00:00 2001 From: reubes Date: Wed, 23 Jun 2021 21:01:15 +0900 Subject: [PATCH 2/6] Update copy.h --- include/chia/copy.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/include/chia/copy.h b/include/chia/copy.h index 1964aae4..8a0b5f6a 100644 --- a/include/chia/copy.h +++ b/include/chia/copy.h @@ -17,17 +17,22 @@ #include #include -#include -namespace fs = std::filesystem; +#ifdef __linux__ + #include + namespace fs = std::filesystem; +#endif inline uint64_t copy_file(const std::string& src_path, const std::string& dst_path) { - int plotsize = 109000000000 - fs::space_info tmp = fs::space(dst_path); - if(tmp.available < plotsize) { - throw std::runtime_error("Destination does not have enough available disk space left"); - } + #ifdef __linux__ + int plotsize = 109000000000 + fs::space_info tmp = fs::space(dst_path); + if(tmp.available < plotsize) { + throw std::runtime_error("Destination does not have enough available disk space left"); + // some code to switch to alternative destination dirs could be here + } + #endif FILE* src = fopen(src_path.c_str(), "rb"); if(!src) { throw std::runtime_error("fopen() failed"); From d266b8da33dacb040755fdb1dcf7a93597dda8ce Mon Sep 17 00:00:00 2001 From: reubes Date: Wed, 23 Jun 2021 21:15:57 +0900 Subject: [PATCH 3/6] Update copy.h --- include/chia/copy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/chia/copy.h b/include/chia/copy.h index 8a0b5f6a..de3065f4 100644 --- a/include/chia/copy.h +++ b/include/chia/copy.h @@ -26,7 +26,7 @@ inline uint64_t copy_file(const std::string& src_path, const std::string& dst_path) { #ifdef __linux__ - int plotsize = 109000000000 + const uint64_t plotsize = 109000000000 // rough plot size placeholder fs::space_info tmp = fs::space(dst_path); if(tmp.available < plotsize) { throw std::runtime_error("Destination does not have enough available disk space left"); From 2d607a86f1d658d178b275d7984e70fba25a5cc9 Mon Sep 17 00:00:00 2001 From: reubes Date: Wed, 23 Jun 2021 21:33:33 +0900 Subject: [PATCH 4/6] Update copy.h add room for alternate destination directory --- include/chia/copy.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/chia/copy.h b/include/chia/copy.h index de3065f4..aa638d89 100644 --- a/include/chia/copy.h +++ b/include/chia/copy.h @@ -23,14 +23,18 @@ #endif inline -uint64_t copy_file(const std::string& src_path, const std::string& dst_path) +uint64_t copy_file(const std::string& src_path, const std::string& dst_path, const std::string& dst2_path) { #ifdef __linux__ - const uint64_t plotsize = 109000000000 // rough plot size placeholder + const uint64_t plotsize = 109000000000 // rough plot size placeholder, later pass real size through fs::space_info tmp = fs::space(dst_path); if(tmp.available < plotsize) { - throw std::runtime_error("Destination does not have enough available disk space left"); - // some code to switch to alternative destination dirs could be here + fs::space_info tmp2 = fs::space(dst_path2); + if(tmp2.available < plotsize) { + throw std::runtime_error("All destinations have run out of disk space"); + } + dst_path = dst2_path; + throw std::runtime_error("Destination does not have enough available disk space left, switching to alternate destination"); } #endif FILE* src = fopen(src_path.c_str(), "rb"); From d9c3de6e94826937c25a60f6d3bae86a6f0eb6c0 Mon Sep 17 00:00:00 2001 From: reubes Date: Wed, 23 Jun 2021 21:48:15 +0900 Subject: [PATCH 5/6] Update copy.h --- include/chia/copy.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/chia/copy.h b/include/chia/copy.h index aa638d89..7629550a 100644 --- a/include/chia/copy.h +++ b/include/chia/copy.h @@ -65,19 +65,20 @@ uint64_t copy_file(const std::string& src_path, const std::string& dst_path, con } inline -uint64_t final_copy(const std::string& src_path, const std::string& dst_path) +uint64_t final_copy(const std::string& src_path, const std::string& dst_path, const std::string& dst2_path) { if(src_path == dst_path) { return 0; } const std::string tmp_dst_path = dst_path + ".tmp"; + const std::string tmp_dst2_path = dst2_path + ".tmp"; uint64_t total_bytes = 0; if(rename(src_path.c_str(), tmp_dst_path.c_str())) { // try manual copy - total_bytes = copy_file(src_path, tmp_dst_path); + total_bytes = copy_file(src_path, tmp_dst_path, tmp_dst2_path); } remove(src_path.c_str()); - rename(tmp_dst_path.c_str(), dst_path.c_str()); + rename(tmp_dst_path.c_str(), dst_path.c_str(), tmp_dst2_path.c_str(), dst2_path.c_str()); return total_bytes; } From 120b43bd57688c83ceb6c857813ea5cda7bc2a9c Mon Sep 17 00:00:00 2001 From: reubes Date: Wed, 23 Jun 2021 21:52:49 +0900 Subject: [PATCH 6/6] Update copy.h --- include/chia/copy.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/chia/copy.h b/include/chia/copy.h index 7629550a..d4b9dee6 100644 --- a/include/chia/copy.h +++ b/include/chia/copy.h @@ -78,7 +78,8 @@ uint64_t final_copy(const std::string& src_path, const std::string& dst_path, co total_bytes = copy_file(src_path, tmp_dst_path, tmp_dst2_path); } remove(src_path.c_str()); - rename(tmp_dst_path.c_str(), dst_path.c_str(), tmp_dst2_path.c_str(), dst2_path.c_str()); + rename(tmp_dst_path.c_str(), dst_path.c_str()); + rename(tmp_dst2_path.c_str(), dst2_path.c_str()); return total_bytes; }