From 2bab43393c45a8e9b25358b9ca4333844f2e0a13 Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Thu, 10 Jun 2021 11:54:28 -0700 Subject: [PATCH] mv() simplified for the non-copy case Constified function arguments. Source path is still case-insensitive, but destination is case-sensitive (hopefully that's not an issue). When a "move" (!copy) is requested, a rename() is always attempted first and if successful, job done. Otherwise, we continue on with the file-copy (and then remove). This should resolve CID 332219 (DEADCODE). --- src/sbbs3/main.cpp | 24 +++++++++--------------- src/sbbs3/sbbs.h | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp index 753592543a..b9f8bf16fd 100644 --- a/src/sbbs3/main.cpp +++ b/src/sbbs3/main.cpp @@ -3934,33 +3934,27 @@ void sbbs_t::spymsg(const char* msg) /* both 'src' and 'dest' must contain full path and filename */ /* returns 0 if successful, -1 if error */ /****************************************************************************/ -int sbbs_t::mv(char *src, char *dest, char copy) +int sbbs_t::mv(const char* path, const char* dest, bool copy) { + char src[MAX_PATH + 1]; + if(!stricmp(src,dest)) /* source and destination are the same! */ return(0); + + SAFECOPY(src, path); if(!fexistcase(src)) { bprintf("\r\n\7MV ERROR: Source doesn't exist\r\n'%s'\r\n" ,src); return(-1); } - if(!copy && fexistcase(dest)) { + if(!copy && fexist(dest)) { bprintf("\r\n\7MV ERROR: Destination already exists\r\n'%s'\r\n" ,dest); return(-1); } - if(!copy -#ifndef __unix__ /* need to determine if on same mount device */ - && ((src[1]!=':' && dest[1]!=':') || (src[1]==':' && dest[1]==':' && toupper(src[0])==toupper(dest[0]))) -#endif - ) { - if(rename(src,dest)) { /* same drive, so move */ - bprintf("\r\nMV ERROR: Error renaming '%s'" - "\r\n to '%s'\r\n\7",src,dest); - return(-1); - } - return(0); - } - if(!CopyFile(src, dest, /* fail if exists: */true)) { + if(!copy && rename(src, dest) == 0) + return 0; + if(!CopyFile(src, dest, /* fail if exists: */!copy)) { errormsg(WHERE, "CopyFile", src, 0, dest); return -1; } diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index e17a30bf28..fb41ac2217 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -1006,7 +1006,7 @@ public: ulong logonstats(void); void logoffstats(void); int nopen(char *str, int access); - int mv(char *src, char *dest, char copy); /* fast file move/copy function */ + int mv(const char *src, const char *dest, bool copy); /* fast file move/copy function */ bool chksyspass(const char* sys_pw = NULL); bool chk_ar(const uchar * str, user_t* user, client_t* client); /* checks access requirements */ bool ar_exp(const uchar ** ptrptr, user_t*, client_t*); -- GitLab