w3m icon indicating copy to clipboard operation
w3m copied to clipboard

create history file if it doesn't exist

Open femnad opened this issue 1 year ago • 3 comments

When history is enabled but there is no history file, w3m logs an error message. Change that behavior to create a history file if it doesn't exists.

femnad avatar Jul 30 '23 12:07 femnad

On Sun, Jul 30, 2023 at 05:53:47AM -0700, Cihan Demirci wrote:

When history is enabled but there is no history file, w3m logs an error message. Change that behavior to create a history file if it doesn't exists.

Oops... :-)

Thanks for this fix!

Two remarks:

  1. The indentation is off.
  2. We can simplify this:
--- a/history.c
+++ b/history.c
@@ -90,9 +90,7 @@ saveHistory(Hist *hist, size_t size)
 	return;
 
     histf = rcFile(HISTORY_FILE);
-    if (stat(histf, &st) == -1)
-	goto fail;
-    if (hist->mtime != (long long)st.st_mtime) {
+    if (!stat(histf, &st) && hist->mtime != (long long)st.st_mtime) {
 	fhist = newHist();
 	if (loadHistory(fhist) || mergeHistory(fhist, hist))
 	    disp_err_message("Can't merge history", FALSE);

rkta avatar Aug 01 '23 08:08 rkta

On Sun, Jul 30, 2023 at 05:53:47AM -0700, Cihan Demirci wrote: When history is enabled but there is no history file, w3m logs an error message. Change that behavior to create a history file if it doesn't exists. Oops... :-) Thanks for this fix! Two remarks: 1. The indentation is off. 2. We can simplify this: --- a/history.c +++ b/history.c @@ -90,9 +90,7 @@ saveHistory(Hist *hist, size_t size) return; histf = rcFile(HISTORY_FILE); - if (stat(histf, &st) == -1) - goto fail; - if (hist->mtime != (long long)st.st_mtime) { + if (!stat(histf, &st) && hist->mtime != (long long)st.st_mtime) { fhist = newHist(); if (loadHistory(fhist) || mergeHistory(fhist, hist)) disp_err_message("Can't merge history", FALSE);

I see, instead of explicitly creating an empty history, this leverages the newHist() with the modified conditional, thanks!

I hope the indentation issue went away since this patch only adds one line now (and removes three).

femnad avatar Aug 01 '23 16:08 femnad

LGTM, Thanks!

rkta avatar Aug 01 '23 18:08 rkta