From 138bca5b41944ba94816879e5ad0e2f4657eab2d Mon Sep 17 00:00:00 2001 From: mahlon Date: Fri, 13 Oct 2023 04:34:40 +0000 Subject: [PATCH] Multiple changes: - Flush logfile writes per line - Remove note re: nimble version - Start debugging kernel buffer fills -- checkpoint - Add compile-time info to the version output - Write debug info to stderr instead of stdout - Use a debug maildir destination while developing FossilOrigin-Name: 85d29852920e6ff8fa266a963fbea11379b0bec2ab4fccab348f9e51784c8d4a --- README.md | 7 ------- src/lib/logging.nim | 1 + src/lib/message.nim | 14 ++++++++++++-- src/lib/util.nim | 11 +++++++---- src/sieb.nim | 9 ++++++++- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c6bc08f..91f458b 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,6 @@ You can check out the current development source with Fossil via its Alternatively, you can download the latest version [directly](https://code.martini.nu/fossil/sieb/uv/release/sieb-latest.tar.gz). - -**NOTE**: As of Nim v0.16.4, the Nimble package manager is still at v0.13.1. -Sieb requires >= v0.14 of Nimble, you may need to update it first via: - - % nimble install nimble - - With the [nim](https://nim-lang.org/) environment installed and the Sieb repository cloned, simply type: diff --git a/src/lib/logging.nim b/src/lib/logging.nim index bca4d53..3aa3952 100644 --- a/src/lib/logging.nim +++ b/src/lib/logging.nim @@ -67,4 +67,5 @@ proc log*( msg: string ): void = ## Emit a line to the logfile. if logger.closed: return logger.fh.writeLine( msg ) + logger.fh.flushFile diff --git a/src/lib/message.nim b/src/lib/message.nim index 043938d..7a93300 100644 --- a/src/lib/message.nim +++ b/src/lib/message.nim @@ -179,21 +179,31 @@ proc filter*( orig_msg: Message, cmd: seq[string] ): Message = # Read from the original message, write to the filter # process in chunks. # - orig_msg.open + "*** STARTING PIPE TO PROCESS".debug + var t = 0 + + + # FIXME: I think I'm a victim of the kernel buffer filling up + # with large messages. There are numerous posts regarding this. + # Might need to go lower level than "streams" with the child process. + # while not orig_msg.stream.atEnd: buf = orig_msg.stream.readStr( BUFSIZE ) + t = t + BUFSIZE process.inputStream.write( buf ) process.inputStream.flush + echo "wrote ", t + "*** DONE PIPING TO PROCESS".debug # FIXME: hangs on large messages # Read from the filter process until EOF, send to the # new message in chunks. # process.inputStream.close + process.errorStream.close let new_msg = newMessage( orig_msg.dir ) while not process.outputStream.atEnd: buf = process.outputStream.readStr( BUFSIZE ) new_msg.stream.write( buf ) - new_msg.stream.flush let exitcode = process.waitForExit "Filter exited: $#".debug( exitcode ) diff --git a/src/lib/util.nim b/src/lib/util.nim index d0c7616..368fc2e 100644 --- a/src/lib/util.nim +++ b/src/lib/util.nim @@ -17,11 +17,14 @@ import logging + #------------------------------------------------------------ # C O N S T A N T S #------------------------------------------------------------ const + PLATFORM = staticExec( "uname -mo" ) + COMPILEDATE = staticExec( "date '+%F'" ) VERSION = "v0.1.0" ## The current Sieb version USAGE = """ ./sieb [-c] [-d] [-h] [-v] @@ -153,11 +156,11 @@ proc deferral*( msg: string ) = proc debug*( msg: string, args: varargs[string, `$`] ) = - ## Emit `msg` if debug mode is enabled, coercing arguments into a string for - ## formatting. + ## Emit `msg` to stderr if debug mode is enabled, coercing arguments + ## into a string for formatting. if opts.debug or not logger.closed: var str = msg % args - if opts.debug: echo str + if opts.debug: stderr.writeLine( str ) if not logger.closed: str.log @@ -201,7 +204,7 @@ proc parseCmdline*() = opts.logfile = val of "version", "v": - echo "Sieb " & VERSION + echo "Sieb " & VERSION & ", compiled for " & PLATFORM & " on " & COMPILEDATE quit( 0 ) else: discard diff --git a/src/sieb.nim b/src/sieb.nim index 2a60ad4..b634b74 100644 --- a/src/sieb.nim +++ b/src/sieb.nim @@ -18,6 +18,13 @@ import lib/util +#------------------------------------------------------------ +# C O N S T A N T S +#------------------------------------------------------------ + +const MAILDIR = if defined( debug ): "Maildir-Sieb-DEBUG" else: "Maildir" + + #------------------------------------------------------------ # S E T U P #------------------------------------------------------------ @@ -31,7 +38,7 @@ parseCmdline() let home = getHomeDir() - default = newMaildir( joinPath( home, "Maildir" ) ) + default = newMaildir( joinPath( home, MAILDIR ) ) # Open the optional log file. if opts.logfile != "": createLogger( default.path, opts.logfile )