🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #68663

Re: [slrn] slrnpull & compressing files

#68663
From: Johannes Zellner
Date: Thu, 07 Dec 2000 00:00
534 lines
15394 bytes
In article <slrn92trme.rs8.johannes@kristine.zellner.org>, Johannes Zellner wrote:
>In article <GGyX5.119116$U46.3961944@news1.sttls1.wa.home.com>, Keith wrote:
>>On 6 Dec 2000 15:00:06 GMT, Johannes Zellner <johannes@zellner.org> wrote:
>>> Hi,
>>> 
>>> using slrnpull (on Linux), is it possible to have all the
>>> files gzipped ? -- I guess I'd
>>> 
>>>     1) first tell slrn how to unzip the files when reading
>>>     2) tell slrnpull not to download 5370 if 5370.gz is already there
>>> 
>>> does anybody know if (and how) this is possible ?
>>> 
>>> -- 
>>>    Johannes
>>
>>slrnpull keeps a record in the .minmax files so if you don't remove those then
>>you will not have problems.
>
>so it was just patching slrn to handle ".gz" or ".bz2". The
>patch is attached if someone is interested.  Applies to a
>vanilla 0.9.6.3.  You've to define WITH_LOCAL_COMPRESSION
>somwhere, I tried to make it an configure switch, but
>obviously some m4 files are missing so I couldn't use
>autoconf.

err. I had also to patch slrnpull.c so that it handles
compressed files when creating .minmax / .overview.
The complete patch (including the patch for slrn) is
below. Compile with -DWITH_LOCAL_COMPRESSION.

The compression can be done in a script, e.g.

#v+
slrnpull -h `cat /etc/news/server` >/dev/null
find /var/spool/slrnpull/news -type f -regex '.*/[0-9]+$' -exec gzip -9 {} \; &
#v-

Is there a chance to get something like this included
into the official source ?

-- 
   Johannes


#v+

diff -rcw slrn-0.9.6.3.orig/src/slrnfeat.h slrn-0.9.6.3/src/slrnfeat.h
*** slrn-0.9.6.3.orig/src/slrnfeat.h	Mon Sep 18 00:35:25 2000
--- slrn-0.9.6.3/src/slrnfeat.h	Thu Dec  7 19:54:44 2000
***************
*** 134,147 ****
   */
  
    /* Root directory names */
! # define SLRN_SPOOL_ROOT	"/var/spool/news"
    /* SLRN_NOV_ROOT gives the root directory for overview files
     * if you don't have overview files, leave as SLRN_SPOOL_ROOT for now */
  # define SLRN_SPOOL_NOV_ROOT	SLRN_SPOOL_ROOT
    /* SLRN_NOV_FILE gives filename for overview file in each directory */
  # define SLRN_SPOOL_NOV_FILE	".overview"
  
! # define SLRN_SPOOL_INNROOT	"/var/lib/news"
    /* If the following filenames are relative ones, they are considered to be
     * relative to SLRN_SPOOL_INNROOT.
     */
--- 134,147 ----
   */
  
    /* Root directory names */
! # define SLRN_SPOOL_ROOT	"/var/spool/slrnpull/news"
    /* SLRN_NOV_ROOT gives the root directory for overview files
     * if you don't have overview files, leave as SLRN_SPOOL_ROOT for now */
  # define SLRN_SPOOL_NOV_ROOT	SLRN_SPOOL_ROOT
    /* SLRN_NOV_FILE gives filename for overview file in each directory */
  # define SLRN_SPOOL_NOV_FILE	".overview"
  
! # define SLRN_SPOOL_INNROOT	"/var/spool/slrnpull"
    /* If the following filenames are relative ones, they are considered to be
     * relative to SLRN_SPOOL_INNROOT.
     */
***************
*** 235,241 ****
  /* The rest of the files apply to slrnpull. */
  
  /* This must be set to an absolute pathname. */
! #define SLRNPULL_ROOT_DIR	"/var/spool/news/slrnpull"
  
  /* The remaing variables are specified as relative names with respect to the
   * SLRNPULL_ROOT_DIR.
--- 235,241 ----
  /* The rest of the files apply to slrnpull. */
  
  /* This must be set to an absolute pathname. */
! #define SLRNPULL_ROOT_DIR	"/var/spool/slrnpull"
  
  /* The remaing variables are specified as relative names with respect to the
   * SLRNPULL_ROOT_DIR.
diff -rcw slrn-0.9.6.3.orig/src/slrnpull.c slrn-0.9.6.3/src/slrnpull.c
*** slrn-0.9.6.3.orig/src/slrnpull.c	Mon Sep 18 00:35:31 2000
--- slrn-0.9.6.3/src/slrnpull.c	Thu Dec  7 21:00:27 2000
***************
*** 143,148 ****
--- 143,151 ----
  
  #define CREATE_OVERVIEW 1
  
+ #if defined(WITH_LOCAL_COMPRESSION) && defined(HAVE_UNISTD_H)
+ #   define ALLOW_LOCAL_COMPRESSED
+ #endif
  
  static int handle_interrupts (void);
  
***************
*** 2207,2219 ****
  
  /*}}}*/
  
! static char *read_header_from_file (char *file)
  {
     FILE *fp;
     char line [NNTP_BUFFER_SIZE];
     char *mbuf;
     unsigned int buffer_len, buffer_len_max;
     
     if (NULL == (fp = fopen (file, "r")))
       return NULL;
  
--- 2210,2235 ----
  
  /*}}}*/
  
! static char *read_header_from_file (char *file
! #ifdef ALLOW_LOCAL_COMPRESSED
!     , const char* unzip_cmd
! #endif
!     )
  {
     FILE *fp;
     char line [NNTP_BUFFER_SIZE];
     char *mbuf;
     unsigned int buffer_len, buffer_len_max;
     
+ #ifdef ALLOW_LOCAL_COMPRESSED
+    if (unzip_cmd) {
+      char shell_cmd[32 + SLRN_MAX_PATH_LEN];
+      strcpy(shell_cmd, unzip_cmd);
+      strcat(shell_cmd, file);
+      if (NULL == (fp = popen (shell_cmd, "r")))
+        return NULL;
+    } else
+ #endif
     if (NULL == (fp = fopen (file, "r")))
       return NULL;
  
***************
*** 2249,2254 ****
--- 2265,2280 ----
  	buffer_len += len;
       }
     
+ #ifdef ALLOW_LOCAL_COMPRESSED
+    if (unzip_cmd) {
+      while (NULL != fgets (line, sizeof(line), fp))
+        /* EMPTY: read the rest of the gunziped file
+ 	* so that gunzip -c won't complain about a
+ 	* broken pipe. */;
+      pclose (fp);
+    }
+    else
+ #endif
     fclose (fp);
     return mbuf;
  }
***************
*** 2267,2272 ****
--- 2293,2302 ----
     FILE *xov_fp;
     unsigned i;
     void (*qsort_fun) (char *, unsigned int, int, int (*)(unsigned int *, unsigned int *));
+ #ifdef ALLOW_LOCAL_COMPRESSED
+    char* unzip_cmd;
+    char file_suffix[SLRN_MAX_PATH_LEN + 1];
+ #endif
  
     log_message ("Creating Overview file for %s...", g->name);
     
***************
*** 2311,2326 ****
  	if (-1 == slrn_dircat (dir, buf, file))
  	  continue;
  	
  	if (-1 == stat (file, &st))
  	  {
  	     log_error ("Unable to stat %s.", file);
  	     continue;
  	  }
  	
  	if (0 == S_ISREG(st.st_mode))
  	  continue;
  
! 	header = read_header_from_file (file);
  	if (header == NULL)
  	  continue;
  	
--- 2341,2384 ----
  	if (-1 == slrn_dircat (dir, buf, file))
  	  continue;
  	
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ 	unzip_cmd = (char*)0;
+ #endif
  	if (-1 == stat (file, &st))
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ 	  {
+ 	     struct slrn_cmd_suffix_s* entry;
+ 	     int j;
+ 	     for (j = 0, entry = slrn_cmd_suffix_table; entry->cmd; entry++, j++) {
+ 		strcpy(file_suffix, file);
+ 		strcat(file_suffix, entry->suffix);
+ 		if (-1 != stat (file_suffix, &st)) {
+ 		    unzip_cmd = entry->cmd;
+ 		    strcpy(file, file_suffix);
+ 		    break;
+ 		}
+ 	     }
+ 	     if ((char*)0 == unzip_cmd)
+ 		{
+ 		   log_error ("Unable to stat %s.", file);
+ 		   continue;
+ 		}
+ 	  }
+ #else
  	  {
  	     log_error ("Unable to stat %s.", file);
  	     continue;
  	  }
+ #endif
  	
  	if (0 == S_ISREG(st.st_mode))
  	  continue;
  
! 	header = read_header_from_file (file
! #ifdef ALLOW_LOCAL_COMPRESSED
! 	    , unzip_cmd
! #endif
! 	    );
  	if (header == NULL)
  	  continue;
  	
***************
*** 2352,2357 ****
--- 2410,2419 ----
     char dir [SLRN_MAX_PATH_LEN + 1];
     char file [SLRN_MAX_PATH_LEN + 1];
     unsigned int *ok_names;
+ #ifdef ALLOW_LOCAL_COMPRESSED
+    unsigned int *ok_suffixes;
+    int this_suffix;
+ #endif
     unsigned int num_ok_names, max_num_ok_names;
     unsigned int min_not_expired, num_expired;
     unsigned int i, n, new_num_ok_names;
***************
*** 2372,2377 ****
--- 2434,2442 ----
       }
     
     ok_names = NULL;
+ #ifdef ALLOW_LOCAL_COMPRESSED
+    ok_suffixes = NULL;
+ #endif
     max_num_ok_names = num_ok_names = 0;
     
     while (NULL != (df = slrn_read_dir (dp)))
***************
*** 2382,2389 ****
  	
  	/* Look for names composed of digits.  Skip others. */
  	p = name;
  	while (*p && isdigit (*p)) p++;
! 	if (*p != 0) continue;
  	
  	if (1 != sscanf (name, "%u", &n))
  	  continue;		       /* hmm... I'm paranoid. */
--- 2447,2472 ----
  	
  	/* Look for names composed of digits.  Skip others. */
  	p = name;
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ 	this_suffix = -1;
+ #endif
  	while (*p && isdigit (*p)) p++;
! 	if (*p != 0)
! #ifdef ALLOW_LOCAL_COMPRESSED
! 	{
! 	   struct slrn_cmd_suffix_s* entry;
! 	   for (i = 0, entry = slrn_cmd_suffix_table; entry->cmd; entry++, i++) {
! 	       if (!strcmp(p, entry->suffix)) {
! 		   this_suffix = i;
! 		   break;
! 	       }
! 	   }
! 	   if (-1 == this_suffix)
! 	      continue;
! 	}
! #else
! 	   continue;
! #endif
  	
  	if (1 != sscanf (name, "%u", &n))
  	  continue;		       /* hmm... I'm paranoid. */
***************
*** 2392,2398 ****
  	  {
  	     max_num_ok_names += 500;
  	     ok_names = (unsigned int *) slrn_realloc ((char *) ok_names, max_num_ok_names * sizeof (unsigned int), 1);
! 	     if (ok_names == NULL)
  	       {
  		  log_error ("malloc error. Unable to expire group %s.", g->name);
  		  slrn_close_dir (dp);
--- 2475,2488 ----
  	  {
  	     max_num_ok_names += 500;
  	     ok_names = (unsigned int *) slrn_realloc ((char *) ok_names, max_num_ok_names * sizeof (unsigned int), 1);
! #ifdef ALLOW_LOCAL_COMPRESSED
! 	     ok_suffixes = (unsigned int *) slrn_realloc ((char *) ok_suffixes, max_num_ok_names * sizeof (unsigned int), 1);
! #endif
! 	     if (ok_names == NULL
! #ifdef ALLOW_LOCAL_COMPRESSED
! 		|| ok_suffixes == NULL
! #endif
! 		)
  	       {
  		  log_error ("malloc error. Unable to expire group %s.", g->name);
  		  slrn_close_dir (dp);
***************
*** 2401,2406 ****
--- 2491,2499 ----
  	  }
  	
  	ok_names [num_ok_names] = n;
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ 	ok_suffixes [num_ok_names] = this_suffix;
+ #endif
  	num_ok_names++;
       }
     
***************
*** 2433,2439 ****
--- 2526,2537 ----
  	     continue;
  	  }
  	
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ 	sprintf (buf, "%d%s", n,
+ 	    (-1 != ok_suffixes[i]) ? slrn_cmd_suffix_table[i].suffix: "");
+ #else
  	sprintf (buf, "%d", n);
+ #endif
  	
  	if (-1 == slrn_dircat (dir, buf, file))
  	  continue;
***************
*** 2467,2472 ****
--- 2565,2571 ----
     (void) create_overview_for_dir (g, ok_names, new_num_ok_names);
     
     slrn_free ((char *) ok_names);
+    slrn_free ((char *) ok_suffixes);
     
     return 0;
  }
diff -rcw slrn-0.9.6.3.orig/src/spool.c slrn-0.9.6.3/src/spool.c
*** slrn-0.9.6.3.orig/src/spool.c	Mon Sep 18 00:35:29 2000
--- slrn-0.9.6.3/src/spool.c	Thu Dec  7 20:59:46 2000
***************
*** 85,90 ****
--- 85,98 ----
  static int spool_fakeactive_read_line(char *, int);
  static int Spool_fakeactive_newsgroups=0;
  
+ #if defined(WITH_LOCAL_COMPRESSION) && defined(HAVE_UNISTD_H)
+ #   define ALLOW_LOCAL_COMPRESSED
+ #endif
+ 
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ static int (*Spool_close)(FILE*) = fclose;
+ #endif
+ 
  #if DEBUG_SPOOL
  # include <stdarg.h>
  static void spool_debug (char *fmt, ...)
***************
*** 128,134 ****
--- 136,147 ----
     if (Spool_fh_local != NULL)
       {
  	if (Spool_fh_local != Spool_fh_nov)
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ 	  res = Spool_close(Spool_fh_local);
+ 	Spool_close = fclose;
+ #else
  	  res = fclose(Spool_fh_local);
+ #endif
  	Spool_fh_local=NULL;
       }
     return res;
***************
*** 364,377 ****
     return -1;
  }
  
- 
  static FILE *spool_open_article_num (int num)
  {
     char buf [SLRN_MAX_PATH_LEN];
     
     sprintf (buf, "%s/%d", Spool_Group, num);
     
!    return fopen (buf,"r");
  }
  
  static int spool_article_num_exists (int num)
--- 377,411 ----
     return -1;
  }
  
  static FILE *spool_open_article_num (int num)
  {
     char buf [SLRN_MAX_PATH_LEN];
+    FILE* fp = (FILE*)0;
  
     sprintf (buf, "%s/%d", Spool_Group, num);
     
!    fp = fopen (buf,"r");
! #if defined(ALLOW_LOCAL_COMPRESSED)
!    if (!fp) {
!       char shell_cmd[32 + SLRN_MAX_PATH_LEN];
!       struct slrn_cmd_suffix_s* entry;
!       for (entry = slrn_cmd_suffix_table; entry->cmd; entry++) {
! 	 strcpy(shell_cmd, buf);
! 	 strcat(shell_cmd, entry->suffix);
! 	 if (!access(shell_cmd, R_OK)) {
! 	    strcpy(shell_cmd, entry->cmd);
! 	    strcat(shell_cmd, buf);
! 	    strcat(shell_cmd, entry->suffix);
! 	    fp = popen(shell_cmd, "r");
! 	    if (fp) {
! 	       Spool_close = pclose;
! 	    }
! 	    break;
! 	 }
!       }
!    }
! #endif
!    return fp;
  }
  
  static int spool_article_num_exists (int num)
***************
*** 905,911 ****
--- 939,950 ----
     
     if (Spool_fh_nov != NULL)
       {
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ 	Spool_close (Spool_fh_nov);
+ 	Spool_close = fclose;
+ #else
  	fclose (Spool_fh_nov);
+ #endif
  	Spool_fh_nov = NULL;
       }
     
***************
*** 952,958 ****
--- 991,1002 ----
  
     if (NULL != Spool_fh_nov)
       {
+ #ifdef ALLOW_LOCAL_COMPRESSED
+ 	Spool_close(Spool_fh_nov);
+ 	Spool_close = fclose;
+ #else
  	fclose(Spool_fh_nov);
+ #endif
  	Spool_fh_nov = NULL;
       }
     Spool_Server_Inited = 0;
diff -rcw slrn-0.9.6.3.orig/src/util.c slrn-0.9.6.3/src/util.c
*** slrn-0.9.6.3.orig/src/util.c	Mon Sep 18 00:35:31 2000
--- slrn-0.9.6.3/src/util.c	Thu Dec  7 20:14:30 2000
***************
*** 43,48 ****
--- 43,58 ----
  #include "util.h"
  #include "ttymsg.h"
  
+ #if defined WITH_LOCAL_COMPRESSION
+ /* used in spool.c, slrnpull.c */
+ struct slrn_cmd_suffix_s slrn_cmd_suffix_table[] = {
+   {"gzip -d -c ", ".gz"},
+   {"bunzip2 -c ", ".bz2"},
+   {(char*)0, (char*)0} /* terminate */
+ };
+ #endif
+    
+ 
  /* This function allows NULL as a parameter. This fact _is_ exploited */
  char *slrn_skip_whitespace (char *b) /*{{{*/
  {
diff -rcw slrn-0.9.6.3.orig/src/util.h slrn-0.9.6.3/src/util.h
*** slrn-0.9.6.3.orig/src/util.h	Mon Sep 18 00:35:31 2000
--- slrn-0.9.6.3/src/util.h	Thu Dec  7 20:15:22 2000
***************
*** 65,68 ****
--- 65,76 ----
  extern void slrn_exit_error (char *, ...);
  char *slrn_make_from_string (void);
  
+ #if defined(WITH_LOCAL_COMPRESSION)
+ struct slrn_cmd_suffix_s {
+   char* cmd;
+   char* suffix;
+ };
+ extern struct slrn_cmd_suffix_s slrn_cmd_suffix_table[]; /* defined in util.o */
+ #endif
+ 
  #endif				       /* _SLRN_UTIL_H */

#v-

Technical Details
Message-ID: <slrn92vrkd.dts.johannes@kristine.zellner.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
References: <slrn92skm1.h81.johannes@kristine.zellner.org> <GGyX5.119116$U46.3961944@news1.sttls1.wa.home.com> <slrn92trme.rs8.johannes@kristine.zellner.org>

Show Full Headers
Complete Article Headers
Message-ID: <slrn92vrkd.dts.johannes@kristine.zellner.org>
Subject: Re: [slrn] slrnpull & compressing files
Date: Thu, 07 Dec 2000 00:00:00 +0000
From: johannes@zellner.org (Johannes Zellner)
References: <slrn92skm1.h81.johannes@kristine.zellner.org> <GGyX5.119116$U46.3961944@news1.sttls1.wa.home.com> <slrn92trme.rs8.johannes@kristine.zellner.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail
X-Deja-AN: 702288774
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1
X-Complaints-To: usenet@rz.uni-karlsruhe.de
X-Trace: news.rz.uni-karlsruhe.de 976219898 17746 129.13.216.201
Organization: University of Karlsruhe, Germany
Mime-Version: 1.0
User-Agent: slrn/0.9.6.3 (Linux)
Newsgroups: news.software.readers