Skip to content

Commit

Permalink
Make dequeuing posts also delete the backup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kansattica committed Mar 5, 2021
1 parent 4a4aca6 commit 7dcc308
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 8 additions & 1 deletion lib/queue/queues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
20 changes: 13 additions & 7 deletions tests/queues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -326,9 +328,11 @@ SCENARIO("Queues correctly enqueue and dequeue posts.")

dequeue(api_route::post, accountdir, std::vector<std::string> { 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.")
Expand Down Expand Up @@ -426,9 +430,11 @@ SCENARIO("Queues correctly enqueue and dequeue posts.")

dequeue(api_route::post, accountdir, std::vector<std::string> { 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.")
Expand Down

0 comments on commit 7dcc308

Please sign in to comment.