From 7545beb0e6192f0bc56fcd1481dba56cd3ab7ef4 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Thu, 21 Sep 2017 01:12:28 -0700 Subject: [PATCH] Make sure cFile_i is constructed & destructed cleanly; clean up GetSymLinkStr a bit more; improve Debug/Basic & UnixFSServices/GetExecutableFilename unit tests --- src/core/file_unix.cpp | 20 ++++++++++---------- src/fs/fspropcalc.cpp | 6 +++--- src/twtest/debug_t.cpp | 5 +++++ src/twtest/unixfsservices_t.cpp | 5 +++++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/core/file_unix.cpp b/src/core/file_unix.cpp index 2bda72b..ae9fed9 100644 --- a/src/core/file_unix.cpp +++ b/src/core/file_unix.cpp @@ -83,28 +83,28 @@ struct cFile_i //Ctor cFile_i::cFile_i() : - mpCurrStream(NULL) + m_fd(-1), mpCurrStream(NULL), mFlags(0) {} //Dtor cFile_i::~cFile_i() { if (mpCurrStream != NULL) + { fclose( mpCurrStream ); - mpCurrStream = NULL; + mpCurrStream = NULL; #if IS_AROS || IS_RISCOS - if( mFlags & cFile::OPEN_LOCKED_TEMP ) - { - // unlink this file - if( 0 != unlink(mFileName.c_str())) + if( mFlags & cFile::OPEN_LOCKED_TEMP ) { - throw( eFileOpen( mFileName, iFSServices::GetInstance()->GetErrString() ) ); + // unlink this file + if( 0 != unlink(mFileName.c_str())) + { + throw( eFileOpen( mFileName, iFSServices::GetInstance()->GetErrString() ) ); + } } - } #endif - - mFileName.empty(); + } } /////////////////////////////////////////////////////////////////////////// diff --git a/src/fs/fspropcalc.cpp b/src/fs/fspropcalc.cpp index 2c3fd65..9c2e8de 100644 --- a/src/fs/fspropcalc.cpp +++ b/src/fs/fspropcalc.cpp @@ -90,7 +90,7 @@ bool cFSPropCalc::GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t s std::vector data(size+1); char* buf = &data[0]; -#if defined(O_PATH) +#if defined(O_PATH) // A Linuxism that lets us read symlinks w/o bumping the access time. int fd = open(strName.c_str(), (O_PATH | O_NOFOLLOW | O_NOATIME)); int rtn = readlinkat(fd, 0, buf, size); close(fd); @@ -98,13 +98,13 @@ bool cFSPropCalc::GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t s int rtn = readlink( strName.c_str(), buf, size ); #endif - if(rtn == -1) + if(rtn < 0) { // Some OSes (like HP-UX) return ERANGE if buffer is too small. // This is nonstandard but better than the usual truncate-and-say-you-succeeded // if(ERANGE == errno) - return GetSymLinkStr(strName, arch, size*2); + return GetSymLinkStr(strName, arch, size*2); return false; } diff --git a/src/twtest/debug_t.cpp b/src/twtest/debug_t.cpp index 2b3be0f..c30e353 100644 --- a/src/twtest/debug_t.cpp +++ b/src/twtest/debug_t.cpp @@ -88,6 +88,11 @@ void TestDebug() if(oldOutTarget & cDebug::OUT_FILE) cDebug::AddOutTarget(cDebug::OUT_FILE); else cDebug::RemoveOutTarget(cDebug::OUT_FILE); d.TraceDebug("Exiting...\n"); + +#ifndef DEBUG + TEST("Should always succeed in release builds & cDebug should do nothing"); +#endif + } void RegisterSuite_Debug() diff --git a/src/twtest/unixfsservices_t.cpp b/src/twtest/unixfsservices_t.cpp index ac82a24..34a5654 100644 --- a/src/twtest/unixfsservices_t.cpp +++ b/src/twtest/unixfsservices_t.cpp @@ -42,6 +42,8 @@ #include "twtest/test.h" #endif +#include + using namespace std; @@ -177,6 +179,9 @@ void TestGetIPAddress() void TestGetExecutableFilename() { + if( -1 == access("/bin/sh", F_OK)) + skip("/bin/sh not found/accessible"); + TSTRING filename = _T("sh"); TSTRING fullpath = _T("/bin/"); TEST( iFSServices::GetInstance()->GetExecutableFilename(fullpath, filename));