Skip to content

Commit

Permalink
always try to delete decompressed inputdata after reading in
Browse files Browse the repository at this point in the history
not doing this properly was causing a huge waste of space by duplicating the compressed and decompressed files
  • Loading branch information
poco0317 committed Dec 21, 2022
1 parent bc75d6e commit 8952c44
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Etterna/Models/HighScore/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,18 @@ Replay::LoadInputData(const std::string& replayDir) -> bool
return true;
}
*/

// delete the decompressed inputdata file to not waste space
// the original compressed file should still be there
auto deleteDecompressedData = [this, &path]() {
if (RetriedRemove(path)) {
Locator::getLogger()->trace("Deleted uncompressed input data");
} else {
Locator::getLogger()->warn(
"Failed to delete uncompressed input data");
}
};

// human readable compression read-in
try {
gzFile infile = gzopen(path_z.c_str(), "rb");
Expand Down Expand Up @@ -612,6 +624,7 @@ Replay::LoadInputData(const std::string& replayDir) -> bool
if (!inputStream) {
Locator::getLogger()->debug("Failed to load input data at {}",
path.c_str());
deleteDecompressedData();
return false;
}

Expand All @@ -631,6 +644,7 @@ Replay::LoadInputData(const std::string& replayDir) -> bool
"Bad input data header detected: {} - Header: {}",
path_z.c_str(),
line);
deleteDecompressedData();
return false;
}

Expand All @@ -653,6 +667,7 @@ Replay::LoadInputData(const std::string& replayDir) -> bool
path_z.c_str(),
INPUT_DATA_VERSION,
std::stoi(tokens[7]));
deleteDecompressedData();
return false;
}

Expand Down Expand Up @@ -719,6 +734,7 @@ Replay::LoadInputData(const std::string& replayDir) -> bool
GetScoreKey().c_str(),
tokens.size(),
line);
deleteDecompressedData();
return false;
}

Expand Down Expand Up @@ -754,17 +770,13 @@ Replay::LoadInputData(const std::string& replayDir) -> bool

inputStream.close();

if (RetriedRemove(path)) {
Locator::getLogger()->trace("Deleted uncompressed input data");
} else {
Locator::getLogger()->warn(
"Failed to delete uncompressed input data");
}
deleteDecompressedData();
} catch (std::runtime_error& e) {
Locator::getLogger()->warn(
"Failed to load input data at {} due to runtime exception: {}",
path.c_str(),
e.what());
deleteDecompressedData();
return false;
}
return true;
Expand Down

0 comments on commit 8952c44

Please sign in to comment.