forked from madMAx43v3r/chia-plotter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from stotiks/path-to-redemption
Path to redemption
- Loading branch information
Showing
61 changed files
with
2,558 additions
and
34,898 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "lib/bls-signatures"] | ||
path = lib/bls-signatures | ||
url = https://github.com/Chia-Network/bls-signatures.git | ||
[submodule "lib/BLAKE3"] | ||
path = lib/BLAKE3 | ||
url = https://github.com/BLAKE3-team/BLAKE3.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* copy.h | ||
* | ||
* Created on: Jun 8, 2021 | ||
* Author: mad | ||
*/ | ||
|
||
#ifndef INCLUDE_CHIA_COPY_H_ | ||
#define INCLUDE_CHIA_COPY_H_ | ||
|
||
#include <chia/stdiox.hpp> | ||
#include <chia/settings.h> | ||
|
||
#include <string> | ||
#include <vector> | ||
#include <stdexcept> | ||
|
||
#include <cstdio> | ||
#include <cstdint> | ||
|
||
|
||
inline | ||
uint64_t copy_file(const std::string& src_path, const std::string& dst_path) | ||
{ | ||
FILE* src = FOPEN(src_path.c_str(), "rb"); | ||
if(!src) { | ||
throw std::runtime_error("fopen() failed"); | ||
} | ||
FILE* dst = FOPEN(dst_path.c_str(), "wb"); | ||
if(!dst) { | ||
throw std::runtime_error("fopen() failed"); | ||
} | ||
uint64_t total_bytes = 0; | ||
std::vector<uint8_t> buffer(g_read_chunk_size); | ||
while(true) { | ||
const auto num_bytes = fread(buffer.data(), 1, buffer.size(), src); | ||
if(fwrite(buffer.data(), 1, num_bytes, dst) != num_bytes) { | ||
throw std::runtime_error("fwrite() failed"); | ||
} | ||
total_bytes += num_bytes; | ||
if(num_bytes < buffer.size()) { | ||
break; | ||
} | ||
} | ||
if(fclose(dst)) { | ||
throw std::runtime_error("fclose() failed"); | ||
} | ||
fclose(src); | ||
return total_bytes; | ||
} | ||
|
||
inline | ||
uint64_t final_copy(const std::string& src_path, const std::string& dst_path) | ||
{ | ||
if(src_path == dst_path) { | ||
return 0; | ||
} | ||
const std::string tmp_dst_path = dst_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); | ||
} | ||
remove(src_path.c_str()); | ||
rename(tmp_dst_path.c_str(), dst_path.c_str()); | ||
return total_bytes; | ||
} | ||
|
||
|
||
#endif /* INCLUDE_CHIA_COPY_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.