adji

Adji's a Decisive and Joyful Internet browser
git clone https://noxz.tech/git/adji.git
adji

commit: 2d591e76234a78b7c415ae53cab46b0eda97109d
parent: a5bdb3ea9ea9ad475a14f0ea7af1c50132e92097
author: Chris Noxz <chris@noxz.tech>
date:   Sat, 17 Jun 2023 14:45:35 +0200
try to create state file if it doesn't exist
Mbrowser.c9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/browser.c b/browser.c
@@ -711,7 +711,12 @@ load_state(void)
 		return;
 
 	if ((fp = fopen(CFG_S(StateFile), "r")) == NULL) {
-		perror(__NAME__": Error opening state file");
+		/* fail if file exists as it cannot be accessed, else remove state lock
+		 * to see if saving the state will create it (ie. the parent exists) */
+		if (access(CFG_S(StateFile), F_OK) == 0)
+			perror(__NAME__": Error opening state file");
+		else
+			gl.state_lock = FALSE;
 		return;
 	}
 
@@ -1020,7 +1025,7 @@ save_state(void)
 	if (CFG_S(StateFile) == NULL || gl.ipc != IPC_HOST || gl.state_lock)
 		return;
 
-	if ((fp = fopen(CFG_S(StateFile), "w+")) == NULL) {
+	if ((fp = fopen(CFG_S(StateFile), "w")) == NULL) {
 		perror(__NAME__": Error opening state file");
 		return;
 	}