pkgsrc-wip/nzbget/patches/patch-ad

81 lines
2.1 KiB
Text

$NetBSD: patch-ad,v 1.1 2005/12/21 10:28:27 martijnb Exp $
--- Coordinator.cpp.orig 2005-09-02 09:00:41.000000000 +0200
+++ Coordinator.cpp
@@ -35,6 +35,7 @@
#include "DownloadJob.h"
#include "MultiServerPool.h"
#include "Frontend.h"
+#include <libgen.h>
extern Frontend* g_pFrontend;
@@ -124,7 +125,8 @@ void Coordinator::Start()
break;
}
- usleep(1000*1000);
+ // usleep(1000*1000);
+ sleep(1);
}
}
@@ -135,8 +137,27 @@ void Coordinator::GetDestinationDir( cha
if( !strcmp( m_pOptions->getOption( OPTION_APPENDDIR, NULL ), "yes" ) )
{
char postname[1024];
- const char* szBaseName = basename( szFileName );
+
+ // const char *szBaseName = basename(szFileName);
+
+ // basename can (and will) modify the memory pointed at
+ // by its argument, so it is not safe to use. A simple
+ // strrchr will do just fine, anyway.
+
+ const char *szBaseName = strrchr(szFileName,'/');
+ if (szBaseName == NULL)
+ {
+ // No slashes - probably a base name already
+ szBaseName = szFileName;
+ }
+ else
+ {
+ // strrchr returns pointer to the last occurrence,
+ // advance so we have the *real* basename..
+ szBaseName++;
+ }
+
// if .nzb file has a certain structure, try to strip out certain elements
if (sscanf(szBaseName,"msgid_%*d_%1023s", postname) == 1)
{
@@ -144,12 +165,18 @@ void Coordinator::GetDestinationDir( cha
char* tmp2;
// wipe out ".nzb"
- memset(rindex(postname, '.'), 0, postname+strlen(postname)-rindex(postname, '.'));
+ //memset(rindex(postname, '.'), 0, postname+strlen(postname)-rindex(postname, '.'));
+
+ tmp1 = strrchr(postname,'.');
+ if (tmp1 && strncasecmp(tmp1, ".nzb", 4) == 0)
+ {
+ *tmp1 = 0;
+ }
tmp1 = m_pOptions->getOption(OPTION_REALDESTDIR, ".");
int slen = strlen(tmp1) + 1 + strlen(postname) + 3;
tmp2 = (char*) malloc(slen);
- memset(tmp2, 0, slen);
+
if (tmp1[strlen(tmp1) - 1] != '/')
{
strcpy(tmp2, tmp1);
@@ -162,6 +189,8 @@ void Coordinator::GetDestinationDir( cha
strcat(tmp2, postname);
}
strcpy( szBuffer, tmp2);
+
+ free (tmp2);
}
else
{