Make sure cFile_i is constructed & destructed cleanly; clean up GetSymLinkStr a bit more; improve Debug/Basic & UnixFSServices/GetExecutableFilename unit tests
This commit is contained in:
parent
a4ae3af444
commit
7545beb0e6
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -90,7 +90,7 @@ bool cFSPropCalc::GetSymLinkStr(const TSTRING& strName, cArchive& arch, size_t s
|
|||
std::vector<char> 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;
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#include "twtest/test.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
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));
|
||||
|
|
Loading…
Reference in New Issue