From 9f63f725d395e36d25e63b84308de00635e4dc81 Mon Sep 17 00:00:00 2001 From: DavHau Date: Mon, 20 Nov 2023 11:29:57 +0700 Subject: [PATCH] history: fix: store entries only once --- pkgs/clan-cli/clan_cli/flakes/add.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/flakes/add.py b/pkgs/clan-cli/clan_cli/flakes/add.py index b745ef490..27be29a49 100644 --- a/pkgs/clan-cli/clan_cli/flakes/add.py +++ b/pkgs/clan-cli/clan_cli/flakes/add.py @@ -11,9 +11,14 @@ from ..async_cmd import CmdOut, runforcli async def add_flake(path: Path) -> Dict[str, CmdOut]: user_history_file().parent.mkdir(parents=True, exist_ok=True) # append line to history file - # TODO: Is this atomic? - with open(user_history_file(), "a+") as f: - f.write(f"{path}\n") + # TODO: Make this atomic + lines: set = set() + if user_history_file().exists(): + with open(user_history_file(), "r") as f: + lines = set(f.readlines()) + lines.add(str(path)) + with open(user_history_file(), "w") as f: + f.writelines(lines) return {}