From 0dee38a2000d67ff268651c78deac9d49281bbe6 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sun, 4 Aug 2019 06:05:18 +0000
Subject: [PATCH] Revamp the 0-byte inbound bundle handling: - Don't ever try
 to unpack a 0-byte file. - Don't log anything or try delete if the file is <
 24 hours old. - Try to delete the file if it's >= 24 hours old (and log a
 msg, INFO-level).

---
 src/sbbs3/sbbsecho.c | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/src/sbbs3/sbbsecho.c b/src/sbbs3/sbbsecho.c
index 6556813b5b..8c2d04f5ff 100644
--- a/src/sbbs3/sbbsecho.c
+++ b/src/sbbs3/sbbsecho.c
@@ -2743,28 +2743,31 @@ bool unpack_bundle(const char* inbound)
 		if(gi<g.gl_pathc) {
 			SAFECOPY(fname,g.gl_pathv[gi]);
 			gi++;
-			lprintf(LOG_INFO,"Unpacking bundle: %s (%1.1fKB)", fname, flength(fname)/1024.0);
-			if(unpack(fname, inbound)) {	/* failure */
-				lprintf(LOG_ERR, "!Unpack failure: %s", fname);
-				if(fdate(fname)+(48L*60L*60L)<time(NULL)) {
-					/* If bundle file older than 48 hours, give up */
-					if(flength(fname) < 1) {
-						delfile(fname, __LINE__);	/* Delete it if it's a 0-byte file */
-						continue;
-					}
-					/* rename to "*.?_?" or (if it exists) "*.?-?" */
-					SAFECOPY(str,fname);
-					str[strlen(str)-2]='_';
-					if(fexistcase(str))
-						str[strlen(str)-2]='-';
-					if(fexistcase(str))
-						delfile(str, __LINE__);
-					if(rename(fname,str))
-						lprintf(LOG_ERR,"ERROR line %d renaming %s to %s"
-							,__LINE__,fname,str);
+			off_t length = flength(fname);
+			if(length < 1) {
+				if(fdate(fname) < time(NULL) + (24*60*60))
+					lprintf(LOG_DEBUG, "Ignoring %ld-byte file (less than 24-hours old): ", (long)length, fname);
+				else {
+					lprintf(LOG_INFO, "Deleting %ld-byte file (more than 24-hours old): ", (long)length, fname);
+					delfile(fname, __LINE__);	/* Delete it if it's a 0-byte file */
 				}
 				continue;
 			}
+			lprintf(LOG_INFO,"Unpacking bundle: %s (%1.1fKB)", fname, length/1024.0);
+			if(unpack(fname, inbound) != 0) {	/* failure */
+				lprintf(LOG_ERR, "!Unpack failure: %s", fname);
+				/* rename to "*.?_?" or (if it exists) "*.?-?" */
+				SAFECOPY(str,fname);
+				str[strlen(str)-2]='_';
+				if(fexistcase(str))
+					str[strlen(str)-2]='-';
+				if(fexistcase(str))
+					delfile(str, __LINE__);
+				if(rename(fname,str))
+					lprintf(LOG_ERR,"ERROR line %d renaming %s to %s"
+						,__LINE__,fname,str);
+				continue;
+			}
 			delfile(fname, __LINE__);	/* successful, so delete bundle */
 			bundles_unpacked++;
 			return(true);
-- 
GitLab