history: fix: store entries only once
This commit is contained in:
@@ -11,9 +11,14 @@ from ..async_cmd import CmdOut, runforcli
|
|||||||
async def add_flake(path: Path) -> Dict[str, CmdOut]:
|
async def add_flake(path: Path) -> Dict[str, CmdOut]:
|
||||||
user_history_file().parent.mkdir(parents=True, exist_ok=True)
|
user_history_file().parent.mkdir(parents=True, exist_ok=True)
|
||||||
# append line to history file
|
# append line to history file
|
||||||
# TODO: Is this atomic?
|
# TODO: Make this atomic
|
||||||
with open(user_history_file(), "a+") as f:
|
lines: set = set()
|
||||||
f.write(f"{path}\n")
|
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 {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user