🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
2 messages
2 total messages Started by Heiko W.Rupp Fri, 18 Jul 1997 00:00
INN 1.5.1 -- patch for directory structure
#19385
Author: Heiko W.Rupp
Date: Fri, 18 Jul 1997 00:00
361 lines
10546 bytes
Hi,

below you will find a patch that modifies innd to write articles in
the form /path/to/group/x/yy/nnnnnn. This is to get the "large
directory problem" smaller. I have taken the idea from Joe Greco's
cancel-patch (see http://www.nntp.sol.net/patches/) and modified
to not produce 10.000 directories (100 * 100), but only 200 per
group and also added code for nnrpd and ctlinnd renumber.
Old style directories are still accepted.

I have this code running here on NetBSD 1.1, but I can't promise,
that it will do anything usefull for you. It can even crash your computer,
ruin your life buy you beer (ok, kidding on the last).

USE IT AT YOUR OWN RISK !!!

I am interested in feedback though.

  Heiko

-----------------cut here----------------------------------------------

*** nnrpd/article.c.original	Fri Jul 18 15:24:18 1997
--- nnrpd/article.c	Fri Jul 18 18:12:41 1997
***************
*** 165,170 ****
--- 165,173 ----
      static ARTNUM	save_artnum;
      static char		save_artid[BIG_BUFFER];
      struct stat		Sb;
+ 	char namebuffer[SPOOLNAMEBUFF+5];
+ 
+ 	ARTNUM num;
  
      /* Re-use article if it's the same one. */
      if (ARTqp != NULL) {
***************
*** 175,194 ****
  	}
  	QIOclose(ARTqp);
      }
! 
      /* Open it, make sure it's a regular file. */
!     if ((ARTqp = QIOopen(name, QIO_BUFFER)) == NULL)
! 	return FALSE;
!     if (fstat(QIOfileno(ARTqp), &Sb) < 0 || !S_ISREG(Sb.st_mode)) {
! 	QIOclose(ARTqp);
! 	ARTqp = NULL;
! 	return FALSE;
!     }
!     CloseOnExec(QIOfileno(ARTqp), TRUE);
! 
!     save_artnum = atol(name);
!     ARTgetmsgid(ARTqp, save_artid);
!     (void)strcpy(id, save_artid);
      return TRUE;
  }
  
--- 178,203 ----
  	}
  	QIOclose(ARTqp);
      }
! 	/* try new scheme */
! 	num=atol(name);	
! 	sprintf(namebuffer,"%01d/%02d/%lu",num % 10,
! 			(num / 20 ) % 20 , num);
! 	if ((ARTqp = QIOopen(namebuffer,QIO_BUFFER)) == NULL) {
      /* Open it, make sure it's a regular file. */
! 	    if ((ARTqp = QIOopen(name, QIO_BUFFER)) == NULL)
! 		return FALSE;
! 	} else {
! 	    if (fstat(QIOfileno(ARTqp), &Sb) < 0 || !S_ISREG(Sb.st_mode)) {
! 			QIOclose(ARTqp);
! 			ARTqp = NULL;
! 			return FALSE;
!    	 }
!    	 CloseOnExec(QIOfileno(ARTqp), TRUE);
! 	
!    	 save_artnum = atol(name);
!    	 ARTgetmsgid(ARTqp, save_artid);
!    	 (void)strcpy(id, save_artid);
! 	}
      return TRUE;
  }
  
*** nnrpd/group.c.original	Fri Jul 18 10:58:57 1997
--- nnrpd/group.c	Fri Jul 18 15:21:15 1997
***************
*** 187,192 ****
--- 187,236 ----
      return *i1 - *i2;
  }
  
+ #define DIRENT_TYPE_DIR DT_DIR
+ 
+ STATIC void
+ GRPrscandir(dir,artasiz)
+ 	char *dir;
+ 	int *artasiz;
+ {
+ 	register char *p;
+     register DIRENTRY	*ep;
+     register DIR	*dp;
+ 	register ARTNUM i;
+ 
+     if (chdir(dir) < 0)
+ 		return;
+     dp = opendir(".");  
+ 
+     while ((ep = readdir(dp)) != NULL) {
+ 		/* Get the numeric value of the filename, if it's all digits. */
+ 		if (ep->d_name[0]=='.')  /* sikp dot directories */
+ 			continue;
+ 		if (ep->d_type==DIRENT_TYPE_DIR) {   /* dir in dir? Descend it */
+ 			GRPrscandir(ep->d_name,artasiz);
+ 			continue;
+ 		}
+ 		/* else articles */
+ 		for (p = ep->d_name, i = 0; *p; p++) {
+ 		    if (!CTYPE(isdigit, *p))
+ 				break;
+ 		    i = i * 10 + *p - '0';
+ 		}
+ 		if (*p || i == 0)
+ 		    continue;
+ 
+ 		if (ARTsize + 1 >= *artasiz) {
+ 		    *artasiz += 1024;
+ 		    RENEW(ARTnumbers, ARTNUM, *artasiz);
+ 		}
+ 
+ 		ARTnumbers[ARTsize++] = i;
+    	 }
+     (void)closedir(dp);
+ 	chdir("..");
+ 
+ }
  
  /*
  **  Fill in ARTnumbers with the numbers of the articles in the current
***************
*** 219,231 ****
      GRPcount++;
      if (chdir(dir) < 0)
  	return;
!     dp = opendir(".");
      if (dp == NULL) {
  	syslog(L_ERROR, "%s cant opendir %s %m", ClientHost, dir);
  	return;
      }
  
      while ((ep = readdir(dp)) != NULL) {
  	/* Get the numeric value of the filename, if it's all digits. */
  	for (p = ep->d_name, i = 0; *p; p++) {
  	    if (!CTYPE(isdigit, *p))
--- 263,288 ----
      GRPcount++;
      if (chdir(dir) < 0)
  	return;
!     dp = opendir(".");  
      if (dp == NULL) {
  	syslog(L_ERROR, "%s cant opendir %s %m", ClientHost, dir);
  	return;
      }
  
+ 	/* in the old days we had   /main/some/group/nxxyynnn
+        now we have              /main/some/group/xx/yy/nxxyynnn
+ 	*/
+ 
      while ((ep = readdir(dp)) != NULL) {
+ 		if (ep->d_name[0]=='.')
+ 			continue;
+ 		if (ep->d_type==DIRENT_TYPE_DIR) {  /* a directory .. */
+ 			GRPrscandir(ep->d_name,&ARTarraysize);
+ 			continue;
+ 		}
+ 
+ 	/* some leftover articles */
+ 			
  	/* Get the numeric value of the filename, if it's all digits. */
  	for (p = ep->d_name, i = 0; *p; p++) {
  	    if (!CTYPE(isdigit, *p))
***************
*** 241,247 ****
  	}
  
  	ARTnumbers[ARTsize++] = i;
!     }
      (void)closedir(dp);
  
      ARTcache = NULL;
--- 298,304 ----
  	}
  
  	ARTnumbers[ARTsize++] = i;
!     } /* while */
      (void)closedir(dp);
  
      ARTcache = NULL;
*** innd/art.c.original	Thu Jul 17 18:08:00 1997
--- innd/art.c	Fri Jul 18 18:09:58 1997
***************
*** 2,7 ****
--- 2,11 ----
  **
  **  Article-processing.
  */
+ /*
+  * 930721JG Modify control newsgroup handling to not write such big
+  * directories.
+  */
  #include <stdio.h>
  #include <sys/types.h>
  #include "configdata.h"
***************
*** 1714,1719 ****
--- 1718,1724 ----
  {
      static BUFFER	Files;
      static BUFFER	Header;
+     static char               ngpDir[SPOOLNAMEBUFF];
      static char		buff[SPOOLNAMEBUFF];
      register char	*p;
      register int	i;
***************
*** 2150,2160 ****
  	    continue;
  	ngp->PostCount = 0;
  
  	if (Data.Name[0] == '\0') {
  	    /* Write the article the first time. */
! 	    (void)sprintf(Data.Name, "%s/%lu", ngp->Dir, ngp->Filenum);
  	    if (ARTwrite(Data.Name, article, &Data) < 0
! 	     && (!MakeSpoolDirectory(ngp->Dir)
  	      || ARTwrite(Data.Name, article, &Data) < 0)) {
  		i = errno;
  		syslog(L_ERROR, "%s cant write %s %m", LogName, Data.Name);
--- 2155,2171 ----
  	    continue;
  	ngp->PostCount = 0;
  
+     /* Use modified directory format - breaks nnrpd, etc.,
+                 but we don't give a rip */
+     snprintf(ngpDir, sizeof(ngpDir), "%s/%01d/%02d", 
+ 		ngp->Dir, ngp->Filenum % 10, (ngp->Filenum / 20) % 20);
+ 
+ 
  	if (Data.Name[0] == '\0') {
  	    /* Write the article the first time. */
! 	    (void)sprintf(Data.Name, "%s/%lu", ngpDir, ngp->Filenum);
  	    if (ARTwrite(Data.Name, article, &Data) < 0
! 	     && (!MakeSpoolDirectory(ngpDir)
  	      || ARTwrite(Data.Name, article, &Data) < 0)) {
  		i = errno;
  		syslog(L_ERROR, "%s cant write %s %m", LogName, Data.Name);
***************
*** 2176,2184 ****
  	}
  	else {
  	    /* Link to the main article. */
! 	    (void)sprintf(linkname, "%s/%lu", ngp->Dir, ngp->Filenum);
  	    if (DoLinks && link(Data.Name, linkname) < 0
! 	     && (!MakeSpoolDirectory(ngp->Dir)
  	      || link(Data.Name, linkname) < 0)) {
  #if	defined(DONT_HAVE_SYMLINK)
  		oerrno = errno;
--- 2187,2195 ----
  	}
  	else {
  	    /* Link to the main article. */
! 	    (void)sprintf(linkname, "%s/%lu", ngpDir, ngp->Filenum);
  	    if (DoLinks && link(Data.Name, linkname) < 0
! 	     && (!MakeSpoolDirectory(ngpDir)
  	      || link(Data.Name, linkname) < 0)) {
  #if	defined(DONT_HAVE_SYMLINK)
  		oerrno = errno;
***************
*** 2190,2196 ****
  		/* Try to make a symbolic link to the full pathname. */
  		FileGlue(buff, SPOOL, '/', Data.Name);
  		if (symlink(buff, linkname) < 0
! 		 && (!MakeSpoolDirectory(ngp->Dir)
  		  || symlink(buff, linkname) < 0)) {
  		    oerrno = errno;
  		    syslog(L_ERROR, "%s cant symlink %s and %s %m",
--- 2201,2207 ----
  		/* Try to make a symbolic link to the full pathname. */
  		FileGlue(buff, SPOOL, '/', Data.Name);
  		if (symlink(buff, linkname) < 0
! 		 && (!MakeSpoolDirectory(ngpDir)
  		  || symlink(buff, linkname) < 0)) {
  		    oerrno = errno;
  		    syslog(L_ERROR, "%s cant symlink %s and %s %m",
*** innd/ng.c.original	Fri Jul 18 16:34:42 1997
--- innd/ng.c	Fri Jul 18 18:06:13 1997
***************
*** 321,326 ****
--- 321,358 ----
      return groups;
  }
  
+ #define DIRENT_TYPE_DIR DT_DIR
+ 
+ STATIC void
+ NGrscandir(char *base,char *dir,long *lo, long *hi)
+ {
+     register DIR	*dp;
+     register DIRENTRY	*ep;
+ 	register char *p;
+ 	long l;
+ 	char fname[SPOOLNAMEBUFF];
+ 	
+ 	FileGlue(fname,base,'/',dir);
+     if ((dp = opendir(fname)) != NULL) {
+ 	while ((ep = readdir(dp)) != NULL) {
+ 		if (ep->d_name[0] == '.')
+ 			continue;
+ 		if (ep->d_type==DIRENT_TYPE_DIR) {
+ 			NGrscandir(fname,ep->d_name,lo,hi);
+ 			continue;
+ 		}
+ 	    p = ep->d_name;
+ 	    if (!CTYPE(isdigit, p[0]) || strspn(p, "0123456789") != strlen(p)
+ 	     || (l = atol(p)) == 0)
+ 		continue;
+ 	    if (l < *lo)
+ 		*lo = l;
+ 	    if (l > *hi)
+ 		*hi = l;
+ 	}
+ 	(void)closedir(dp);
+ 	}
+ }
  
  /*
  **  Renumber a group.
***************
*** 364,369 ****
--- 396,407 ----
      /* Scan the directory. */
      if ((dp = opendir(ngp->Dir)) != NULL) {
  	while ((ep = readdir(dp)) != NULL) {
+ 		if(ep->d_name[0]=='.')
+ 			continue;
+ 		if(ep->d_type==DIRENT_TYPE_DIR) {
+ 			NGrscandir(ngp->Dir,ep->d_name,&lomark,&himark);
+ 			continue;
+ 		}
  	    p = ep->d_name;
  	    if (!CTYPE(isdigit, p[0]) || strspn(p, "0123456789") != strlen(p)
  	     || (l = atol(p)) == 0)
-----------------cut here----------------------------------------------


-- 
Heiko W.Rupp hwr@pilhuhn.de
  INN FAQ can be found in ftp://ftp.xlink.net/pub/news/docs/
     It is also posted regularly to news.software.{b,nntp} and news.answers.

Re: INN 1.5.1 -- patch for directory structure
#19391
Author: Joe Greco
Date: Fri, 18 Jul 1997 00:00
21 lines
1410 bytes
In news.software.nntp article <5qobgi$qof$1@snert.pilhuhn.de>, hwr@pilhuhn.de wrote:
:below you will find a patch that modifies innd to write articles in
:the form /path/to/group/x/yy/nnnnnn. This is to get the "large
:directory problem" smaller. I have taken the idea from Joe Greco's
:cancel-patch (see http://www.nntp.sol.net/patches/) and modified
:to not produce 10.000 directories (100 * 100), but only 200 per
:group and also added code for nnrpd and ctlinnd renumber.
:Old style directories are still accepted.

Hello Heiko,

This was exactly what I was hoping somebody would find the ambition
to do.  Would you be opposed to me posting this alongside my patch
(or maybe in replacement of my patch) on my patch archive?

P.S.  A big THANK YOU! for running with the ball.

... JG

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads