From 8952c4487df286bddc1ec44cfd8b08d65d0a4d28 Mon Sep 17 00:00:00 2001 From: Barinade Date: Wed, 21 Dec 2022 16:50:57 -0600 Subject: [PATCH] always try to delete decompressed inputdata after reading in not doing this properly was causing a huge waste of space by duplicating the compressed and decompressed files --- src/Etterna/Models/HighScore/Replay.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Etterna/Models/HighScore/Replay.cpp b/src/Etterna/Models/HighScore/Replay.cpp index 838d2e7f45..4c041582a0 100644 --- a/src/Etterna/Models/HighScore/Replay.cpp +++ b/src/Etterna/Models/HighScore/Replay.cpp @@ -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"); @@ -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; } @@ -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; } @@ -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; } @@ -719,6 +734,7 @@ Replay::LoadInputData(const std::string& replayDir) -> bool GetScoreKey().c_str(), tokens.size(), line); + deleteDecompressedData(); return false; } @@ -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;