}
SHA256_Final(hash, &sha256);
for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
- sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
+ snprintf(outputBuffer + (i * 2), 3, "%02x", hash[i]);
}
outputBuffer[64] = 0;
void cleanStep(std::string tac)
{
std::string current_tac = concatPath(__TAC_DIR, tac.substr(0, tac.find('/')));
- for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
- std::string bck_path = bck.path().string();
- if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
- if (!removeAll(bck_path)) {
- _ERR("Failed to remove of %s", bck_path.c_str());
+ try {
+ for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
+ std::string bck_path = bck.path().string();
+ if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
+ if (!removeAll(bck_path)) {
+ _ERR("Failed to remove of %s", bck_path.c_str());
+ }
+ break;
}
- break;
}
- }
- bool isExist = false;
- for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
- std::string bck_path = bck.path().string();
- if (bf::exists(bck_path) && bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") == NULL) {
- isExist = true;
- break;
+ bool isExist = false;
+ for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
+ std::string bck_path = bck.path().string();
+ if (bf::exists(bck_path) && bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") == NULL) {
+ isExist = true;
+ break;
+ }
}
- }
- if (!isExist) {
- if (!removeAll(current_tac)) {
- _ERR("Failed to remove of %s", current_tac.c_str());
+ if (!isExist) {
+ if (!removeAll(current_tac)) {
+ _ERR("Failed to remove of %s", current_tac.c_str());
+ }
}
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ return;
}
}
void undoStep(std::string tac)
{
std::string current_tac = concatPath(__TAC_DIR, tac.substr(0, tac.find('/')));
- for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
- std::string bck_path = bck.path().string();
- if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
- if (!moveFile(bck_path, bck_path.substr(0, bck_path.rfind(".bck")))) {
- _ERR("Failed to move %s", bck_path.c_str());
+ try {
+ for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
+ std::string bck_path = bck.path().string();
+ if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
+ if (!moveFile(bck_path, bck_path.substr(0, bck_path.rfind(".bck")))) {
+ _ERR("Failed to move %s", bck_path.c_str());
+ }
+ break;
}
- break;
}
+ } catch (const bf::filesystem_error& error) {
+ _ERR("Failed to recursive directory: %s", error.what());
+ return;
}
}