aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config/cookie.nim12
-rw-r--r--src/config/history.nim6
-rw-r--r--src/local/pager.nim2
3 files changed, 13 insertions, 7 deletions
diff --git a/src/config/cookie.nim b/src/config/cookie.nim
index 5a3d9243..dacbfa0f 100644
--- a/src/config/cookie.nim
+++ b/src/config/cookie.nim
@@ -399,12 +399,16 @@ proc write*(map: CookieJarMap; file: string): bool =
buf &= cookie.name & '\t'
buf &= cookie.value & '\n'
inc i
- if buf.len > 0:
- if not ps.writeDataLoop(buf):
- ps.sclose()
- return false
+ if not ps.writeDataLoop(buf):
+ ps.sclose()
+ return false
if i == 0:
discard unlink(cstring(tmp))
discard unlink(cstring(file))
+ ps.sclose()
return true
+ if fsync(ps.fd) != 0:
+ ps.sclose()
+ return false
+ ps.sclose()
return c_rename(cstring(tmp), file) == 0
diff --git a/src/config/history.nim b/src/config/history.nim
index 40cc33aa..2a2cfb97 100644
--- a/src/config/history.nim
+++ b/src/config/history.nim
@@ -81,7 +81,7 @@ proc c_rename(oldname, newname: cstring): cint {.importc: "rename",
header: "<stdio.h>".}
# Consumes `ps'.
-proc write*(hist: History; ps: PosixStream; reverse = false): bool =
+proc write*(hist: History; ps: PosixStream; sync, reverse: bool): bool =
var buf = ""
var entry = if reverse: hist.last else: hist.first
var res = true
@@ -99,6 +99,8 @@ proc write*(hist: History; ps: PosixStream; reverse = false): bool =
entry = entry.next
if buf.len > 0 and not ps.writeDataLoop(buf):
res = false
+ if sync and res:
+ res = fsync(ps.fd) == 0
ps.sclose()
return res
@@ -122,6 +124,6 @@ proc write*(hist: History; file: string): bool =
# another filesystem.
let tmp = file & '~'
let ps = newPosixStream(tmp, O_WRONLY or O_CREAT, 0o600)
- if ps != nil and hist.write(ps):
+ if ps != nil and hist.write(ps, sync = true, reverse = false):
return c_rename(cstring(tmp), file) == 0
return false
diff --git a/src/local/pager.nim b/src/local/pager.nim
index b623a951..4139e337 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -2041,7 +2041,7 @@ proc getHistoryURL(pager: Pager): URL {.jsfunc.} =
pager.loader.passFd(url.pathname, pins.fd)
pins.sclose()
let hist = pager.lineHist[lmLocation]
- if not hist.write(pouts, reverse = true):
+ if not hist.write(pouts, sync = false, reverse = true):
pager.alert("failed to write history")
return url