From 4d34cf63ac200cf7b6963956aee110b922f76ec3 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Thu, 14 Feb 2008 08:17:29 +0000 Subject: [PATCH] Re-use text.dat entry NoErrorLogExists for reporting DirectoryDoesNotExist and changed FileNotThere text.dat entry to FileDoesNotExist which displays the file path. Now check if the directory exists before checking the available disk space before allowing file uploads and report the correct error (using DirectoryDoesNotExist) if the directory is missing (a common mistake). Overhaul viewfilecontents() - wow, I can't wait to re-write all of this moldy filebase code! --- src/sbbs3/execfunc.cpp | 4 ++-- src/sbbs3/listfile.cpp | 4 ++-- src/sbbs3/text.h | 6 +++--- src/sbbs3/tmp_xfer.cpp | 20 +++++++++++++++++--- src/sbbs3/upload.cpp | 8 +++++++- src/sbbs3/viewfile.cpp | 43 ++++++++++++++++++++++-------------------- 6 files changed, 54 insertions(+), 31 deletions(-) diff --git a/src/sbbs3/execfunc.cpp b/src/sbbs3/execfunc.cpp index a80c265a20..94b7e262c7 100644 --- a/src/sbbs3/execfunc.cpp +++ b/src/sbbs3/execfunc.cpp @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -274,7 +274,7 @@ int sbbs_t::exec_function(csi_t *csi) if(!noyes(text[DeleteErrorLogQ])) remove(str); } else - bputs(text[NoErrorLogExists]); + bprintf(text[FileDoesNotExist],str); for(i=1;i<=cfg.sys_nodes;i++) { getnodedat(i,&node,0); if(node.errors) diff --git a/src/sbbs3/listfile.cpp b/src/sbbs3/listfile.cpp index b40cbd45b1..2caf8758c8 100644 --- a/src/sbbs3/listfile.cpp +++ b/src/sbbs3/listfile.cpp @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -1067,7 +1067,7 @@ int sbbs_t::listfileinfo(uint dirnum, char *filespec, long mode) case 'F': /* delete file only */ sprintf(str,"%s%s",dirpath,fname); if(!fexistcase(str)) - bputs(text[FileNotThere]); + bprintf(text[FileDoesNotExist],str); else { if(!noyes(text[AreYouSureQ])) { if(remove(str)) diff --git a/src/sbbs3/text.h b/src/sbbs3/text.h index 6f355dc768..b55b884fd6 100644 --- a/src/sbbs3/text.h +++ b/src/sbbs3/text.h @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -202,7 +202,7 @@ enum { ,Unused156 ,ErrorLogHdr ,DeleteErrorLogQ - ,NoErrorLogExists + ,DirectoryDoesNotExist ,ClearErrCounter ,InvalidNode ,SendingTelegramToUser @@ -286,7 +286,7 @@ enum { ,CloseFileRecordQ ,SysopRemoveFilePrompt ,UserRemoveFilePrompt - ,FileNotThere + ,FileDoesNotExist ,CouldntRemoveFile ,DeleteFileQ ,AddToOfflineDirQ diff --git a/src/sbbs3/tmp_xfer.cpp b/src/sbbs3/tmp_xfer.cpp index 4e8b21a072..a1996b193d 100644 --- a/src/sbbs3/tmp_xfer.cpp +++ b/src/sbbs3/tmp_xfer.cpp @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2007 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -105,6 +105,12 @@ void sbbs_t::temp_xfer() logch(ch,0); switch(ch) { case 'A': /* add to temp file */ + if(!isdir(cfg.temp_dir)) { + bprintf(text[DirectoryDoesNotExist], cfg.temp_dir); + SAFEPRINTF(str,"Temp directory does not exist: %s", cfg.temp_dir); + errorlog(str); + break; + } /* free disk space */ space=getfreediskspace(cfg.temp_dir,1024); if(space<(ulong)cfg.min_dspace) { @@ -283,6 +289,13 @@ void sbbs_t::extract(uint dirnum) if(!strcmp(cfg.dir[dirnum]->code,"TEMP")) intmp=1; + if(!isdir(cfg.temp_dir)) { + bprintf(text[DirectoryDoesNotExist], cfg.temp_dir); + SAFEPRINTF(str,"Temp directory does not exist: %s", cfg.temp_dir); + errorlog(str); + return; + } + /* get free disk space */ space=getfreediskspace(cfg.temp_dir,1024); if(space<(ulong)cfg.min_dspace) { @@ -367,8 +380,9 @@ void sbbs_t::extract(uint dirnum) SAFECOPY(temp_uler,f.uler); SAFECOPY(temp_file,f.name); } /* padded filename */ if(!fexistcase(path)) { - bputs(text[FileNotThere]); /* not on disk */ - return; } + bprintf(text[FileDoesNotExist],path); /* not on disk */ + return; + } done=0; while(online && !done) { mnemonics(text[ExtractFilesPrompt]); diff --git a/src/sbbs3/upload.cpp b/src/sbbs3/upload.cpp index 4ff7f6b48c..b3fae9781b 100644 --- a/src/sbbs3/upload.cpp +++ b/src/sbbs3/upload.cpp @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -283,6 +283,12 @@ bool sbbs_t::upload(uint dirnum) else strcpy(path,cfg.dir[dirnum]->path); + if(!isdir(path)) { + bprintf(text[DirectoryDoesNotExist], path); + SAFEPRINTF(str,"File directory does not exist: %s", path); + errorlog(str); + return(false); + } /* get free disk space */ space=getfreediskspace(path,1024); diff --git a/src/sbbs3/viewfile.cpp b/src/sbbs3/viewfile.cpp index 084030c6bc..052321b3d3 100644 --- a/src/sbbs3/viewfile.cpp +++ b/src/sbbs3/viewfile.cpp @@ -8,7 +8,7 @@ * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -110,28 +110,31 @@ void sbbs_t::viewfiles(uint dirnum, char *fspec) /****************************************************************************/ void sbbs_t::viewfilecontents(file_t* f) { - char str[128],cmd[128]; - char tmp[512]; + char cmd[128]; + char path[MAX_PATH+1]; + char* ext; int i; - if(f->size<=0L) { - bputs(text[FileNotThere]); - return; } + getfilepath(&cfg, f, path); - sprintf(str,"%s%s",f->altpath > 0 && f->altpath<=cfg.altpaths - ? cfg.altpath[f->altpath-1] : cfg.dir[f->dir]->path - ,unpadfname(f->name,tmp)); - strcpy(tmp,f->name); - truncsp(tmp); - for(i=0;i<cfg.total_fviews;i++) { - if(!stricmp(tmp+9,cfg.fview[i]->ext) - && chk_ar(cfg.fview[i]->ar,&useron)) { - strcpy(cmd,cfg.fview[i]->cmd); - break; } } - if(i==cfg.total_fviews) - bprintf(text[NonviewableFile],tmp+9); + if(f->size<=0L) { + bprintf(text[FileDoesNotExist],path); + return; + } + if((ext=getfext(path))!=NULL) { + ext++; + for(i=0;i<cfg.total_fviews;i++) { + if(!stricmp(ext,cfg.fview[i]->ext) + && chk_ar(cfg.fview[i]->ar,&useron)) { + strcpy(cmd,cfg.fview[i]->cmd); + break; + } + } + } + if(ext==NULL || i==cfg.total_fviews) + bprintf(text[NonviewableFile],ext); else - if((i=external(cmdstr(cmd,str,str,NULL) + if((i=external(cmdstr(cmd,path,path,NULL) ,EX_OUTL|EX_OUTR|EX_INR))!=0) - errormsg(WHERE,ERR_EXEC,cmdstr(cmd,str,str,NULL),i); + errormsg(WHERE,ERR_EXEC,cmdstr(cmd,path,path,NULL),i); } -- GitLab