From 7dcc3081cafad3a45383491f527bc683597fde4e Mon Sep 17 00:00:00 2001 From: Grace Lovelace Date: Fri, 5 Mar 2021 10:26:37 -0800 Subject: [PATCH] Make dequeuing posts also delete the backup. --- lib/queue/queues.cpp | 9 ++++++++- tests/queues.cpp | 20 +++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/queue/queues.cpp b/lib/queue/queues.cpp index 96af372e..c234c018 100644 --- a/lib/queue/queues.cpp +++ b/lib/queue/queues.cpp @@ -258,7 +258,14 @@ void enqueue(const api_route toenqueue, const fs::path& user_account_dir, std::v void dequeue_post(const fs::path& queuedir, const fs::path& filename) { - if (!fs::remove(queuedir / filename)) + auto todelete = queuedir / filename; + if (!fs::remove(todelete)) + { + pl() << "Could not delete " << filename << ", could not find it in " << to_utf8(queuedir) << '\n'; + } + + todelete.concat(".bak"); + if (!fs::remove(todelete)) { pl() << "Could not delete " << filename << ", could not find it in " << to_utf8(queuedir) << '\n'; } diff --git a/tests/queues.cpp b/tests/queues.cpp index 842db787..2f6757ad 100644 --- a/tests/queues.cpp +++ b/tests/queues.cpp @@ -185,9 +185,11 @@ SCENARIO("Queues correctly enqueue and dequeue posts.") dequeue(api_route::post, accountdir, std::move(toq)); CAPTURE(justfilename); - THEN("msync's copy of the post is deleted") + THEN("msync's copy and backup of the post are deleted") { - REQUIRE_FALSE(fs::exists(file_queue_dir / justfilename)); + auto filepath = file_queue_dir / justfilename; + REQUIRE_FALSE(fs::exists(filepath)); + REQUIRE_FALSE(fs::exists(filepath.concat(".bak"))); } THEN("the original copy of the post is fine") @@ -326,9 +328,11 @@ SCENARIO("Queues correctly enqueue and dequeue posts.") dequeue(api_route::post, accountdir, std::vector { thisfile }); - THEN("msync's copy of the dequeued file is deleted.") + THEN("msync's copy and backup of the dequeued file are deleted.") { - REQUIRE_FALSE(fs::exists(file_queue_dir / thisfile)); + auto filepath = file_queue_dir / thisfile; + REQUIRE_FALSE(fs::exists(filepath)); + REQUIRE_FALSE(fs::exists(filepath.concat(".bak"))); } THEN("msync's copy of the other file is still there.") @@ -426,9 +430,11 @@ SCENARIO("Queues correctly enqueue and dequeue posts.") dequeue(api_route::post, accountdir, std::vector { thisfile }); - THEN("msync's copy of the dequeued file is deleted.") - { - REQUIRE_FALSE(fs::exists(file_queue_dir / thisfile)); + THEN("msync's copy of the dequeued file and its backup are deleted.") + { + auto filepath = file_queue_dir / thisfile; + REQUIRE_FALSE(fs::exists(filepath)); + REQUIRE_FALSE(fs::exists(filepath.concat(".bak"))); } THEN("msync's copy of the other file is still there.")