Path fixes for FreeDOS/DJGPP
This commit is contained in:
parent
4abec97664
commit
769874d34b
|
@ -138,13 +138,27 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#if USES_DEVICE_PATH
|
class cDosPath
|
||||||
class cDevicePath
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static TSTRING AsPosix(const TSTRING& in);
|
static TSTRING AsPosix(const TSTRING& in);
|
||||||
static TSTRING AsNative(const TSTRING& in);
|
static TSTRING AsNative(const TSTRING& in);
|
||||||
|
static bool IsAbsolutePath(const TSTRING& in);
|
||||||
|
static TSTRING BackupName(const TSTRING& in);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class cArosPath
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static TSTRING AsPosix(const TSTRING& in);
|
||||||
|
static TSTRING AsNative(const TSTRING& in);
|
||||||
|
static bool IsAbsolutePath(const TSTRING& in);
|
||||||
|
};
|
||||||
|
|
||||||
|
#if IS_DOS_DJGPP
|
||||||
|
#define cDevicePath cDosPath
|
||||||
|
#elif IS_AROS
|
||||||
|
#define cDevicePath cArosPath
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -449,31 +449,46 @@ void cFile::Truncate( File_t offset ) // throw(eFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if USES_DEVICE_PATH
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// For paths of type DH0:/dir/file
|
// Platform path conversion methods
|
||||||
TSTRING cDevicePath::AsPosix( const TSTRING& in )
|
/////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool cDosPath::IsAbsolutePath(const TSTRING& in)
|
||||||
|
{
|
||||||
|
if (in.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (in[0] == '/')
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (in.length() >= 2 && in[1] == ':')
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For paths of type C:\DOS
|
||||||
|
TSTRING cDosPath::AsPosix( const TSTRING& in )
|
||||||
{
|
{
|
||||||
if (in[0] == '/')
|
if (in[0] == '/')
|
||||||
|
{
|
||||||
return in;
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
#if IS_DOS_DJGPP
|
TSTRING out = (cDosPath::IsAbsolutePath(in)) ? ("/dev/" + in) : in;
|
||||||
TSTRING out = "/dev/" + in;
|
|
||||||
std::replace(out.begin(), out.end(), '\\', '/');
|
std::replace(out.begin(), out.end(), '\\', '/');
|
||||||
#else
|
out.erase( std::remove(out.begin(), out.end(), ':'), out.end());
|
||||||
TSTRING out = '/' + in;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::replace(out.begin(), out.end(), ':', '/');
|
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
TSTRING cDevicePath::AsNative( const TSTRING& in )
|
TSTRING cDosPath::AsNative( const TSTRING& in )
|
||||||
{
|
{
|
||||||
if (in[0] != '/')
|
if (in[0] != '/')
|
||||||
|
{
|
||||||
return in;
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
#if IS_DOS_DJGPP
|
|
||||||
if (in.find("/dev") != 0 || in.length() < 6)
|
if (in.find("/dev") != 0 || in.length() < 6)
|
||||||
return in;
|
return in;
|
||||||
|
|
||||||
|
@ -483,9 +498,62 @@ TSTRING cDevicePath::AsNative( const TSTRING& in )
|
||||||
if (in.length() >= 8)
|
if (in.length() >= 8)
|
||||||
out.append(in.substr(7));
|
out.append(in.substr(7));
|
||||||
|
|
||||||
return out;
|
std::replace(out.begin(), out.end(), '/', '\\');
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSTRING cDosPath::BackupName( const TSTRING& in )
|
||||||
|
{
|
||||||
|
TSTRING out = in;
|
||||||
|
std::string::size_type pos = out.find_last_of("\\");
|
||||||
|
if( std::string::npos == pos)
|
||||||
|
return in;
|
||||||
|
|
||||||
|
TSTRING path = in.substr(0, pos);
|
||||||
|
TSTRING name = in.substr(pos,9);
|
||||||
|
std::replace(name.begin(), name.end(), '.', '_');
|
||||||
|
path.append(name);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool cArosPath::IsAbsolutePath(const TSTRING& in)
|
||||||
|
{
|
||||||
|
if (in.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (in[0] == '/')
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (in.find(":/") != std::string::npos)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For paths of type DH0:dir/file
|
||||||
|
TSTRING cArosPath::AsPosix( const TSTRING& in )
|
||||||
|
{
|
||||||
|
if (in[0] == '/')
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSTRING out = IsAbsolutePath(in) ? '/' + in : in;
|
||||||
|
std::replace(out.begin(), out.end(), ':', '/');
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
TSTRING cArosPath::AsNative( const TSTRING& in )
|
||||||
|
{
|
||||||
|
if (in[0] != '/')
|
||||||
|
{
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
#elif IS_AROS
|
|
||||||
int x = 1;
|
int x = 1;
|
||||||
for ( x; in[x] == '/' && x<in.length(); x++);
|
for ( x; in[x] == '/' && x<in.length(); x++);
|
||||||
|
|
||||||
|
@ -494,6 +562,5 @@ TSTRING cDevicePath::AsNative( const TSTRING& in )
|
||||||
out[t] = ':';
|
out[t] = ':';
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
|
@ -730,12 +730,18 @@ bool cUnixFSServices::GetExecutableFilename( TSTRING& strFullPath, const TSTRING
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
bool cUnixFSServices::FullPath( TSTRING& strFullPath, const TSTRING& strRelPathC, const TSTRING& pathRelFromC ) const
|
bool cUnixFSServices::FullPath( TSTRING& strFullPath, const TSTRING& strRelPathC, const TSTRING& pathRelFromC ) const
|
||||||
{
|
{
|
||||||
|
cDebug d("cUnixFSServices::FullPath");
|
||||||
|
d.TraceDebug("strRelPathC = %s, pathRelFromC = %s\n", strRelPathC.c_str(), pathRelFromC.c_str());
|
||||||
|
|
||||||
// don't do anything with an empty path
|
// don't do anything with an empty path
|
||||||
if( strRelPathC.empty() )
|
if( strRelPathC.empty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
#if USES_DEVICE_PATH
|
||||||
|
TSTRING strRelPath = cDevicePath::AsPosix(strRelPathC); // make non-const temp var
|
||||||
|
#else
|
||||||
TSTRING strRelPath = strRelPathC; // make non-const temp var
|
TSTRING strRelPath = strRelPathC; // make non-const temp var
|
||||||
|
#endif
|
||||||
//
|
//
|
||||||
// get base name (where strRelPath will be relative to), which will either be;
|
// get base name (where strRelPath will be relative to), which will either be;
|
||||||
// 1. the root directory if strRelPath is an absolute path
|
// 1. the root directory if strRelPath is an absolute path
|
||||||
|
@ -748,6 +754,7 @@ bool cUnixFSServices::FullPath( TSTRING& strFullPath, const TSTRING& strRelPathC
|
||||||
if( IsRoot( strRelPath ) ) // if it's root, don't monkey with it, just return it.
|
if( IsRoot( strRelPath ) ) // if it's root, don't monkey with it, just return it.
|
||||||
{
|
{
|
||||||
strFullPath = strRelPath;
|
strFullPath = strRelPath;
|
||||||
|
d.TraceDebug("Is root; returning %s\n", strFullPath.c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -766,18 +773,30 @@ bool cUnixFSServices::FullPath( TSTRING& strFullPath, const TSTRING& strRelPathC
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GetCurrentDir( strFullPath );
|
GetCurrentDir( strFullPath );
|
||||||
|
#if USES_DEVICE_PATH
|
||||||
|
strFullPath = cDevicePath::AsPosix(strFullPath);
|
||||||
|
#endif
|
||||||
util_TrailingSep( strFullPath, false );
|
util_TrailingSep( strFullPath, false );
|
||||||
}
|
}
|
||||||
catch( eFSServices& )
|
catch( eFSServices& )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.TraceDebug("Creating prefix relative to CWD: %s\n", strFullPath.c_str());
|
||||||
}
|
}
|
||||||
else // we're relative to a given dir
|
else // we're relative to a given dir
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if USES_DEVICE_PATH
|
||||||
|
strFullPath = cDevicePath::AsPosix(pathRelFromC);
|
||||||
|
#else
|
||||||
strFullPath = pathRelFromC;
|
strFullPath = pathRelFromC;
|
||||||
|
#endif
|
||||||
util_RemoveDuplicateSeps( strFullPath );
|
util_RemoveDuplicateSeps( strFullPath );
|
||||||
util_TrailingSep( strFullPath, false );
|
util_TrailingSep( strFullPath, false );
|
||||||
|
|
||||||
|
d.TraceDebug("Creating prefix from supplied path: %s\n", strFullPath.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,6 +809,7 @@ bool cUnixFSServices::FullPath( TSTRING& strFullPath, const TSTRING& strRelPathC
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while( util_GetNextPathElement( strRelPath, strElem, index++ ) )
|
while( util_GetNextPathElement( strRelPath, strElem, index++ ) )
|
||||||
{
|
{
|
||||||
|
d.TraceDebug("Path element = %s\n", strElem.c_str());
|
||||||
if( 0 == strElem.compare( _T(".") ) )
|
if( 0 == strElem.compare( _T(".") ) )
|
||||||
{
|
{
|
||||||
// ignore it
|
// ignore it
|
||||||
|
@ -805,8 +825,11 @@ bool cUnixFSServices::FullPath( TSTRING& strFullPath, const TSTRING& strRelPathC
|
||||||
strFullPath += TW_SLASH;
|
strFullPath += TW_SLASH;
|
||||||
strFullPath += strElem;
|
strFullPath += strElem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.TraceDebug("FullPath is now %s\n", strFullPath.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.TraceDebug("Done, returning %s\n", strFullPath.c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -212,6 +212,10 @@ bool cFSParserUtil::EnumPredefinedVariables( int index, TSTRING& sName, TSTRING&
|
||||||
|
|
||||||
bool cFSParserUtil::IsAbsolutePath( const TSTRING& strPath ) const
|
bool cFSParserUtil::IsAbsolutePath( const TSTRING& strPath ) const
|
||||||
{
|
{
|
||||||
// IF there's a first character AND it is ( '/' OR '\\' ), THEN it's absolute
|
#if USES_DEVICE_PATH
|
||||||
return( strPath.size() > 0 && ( _T('/') == strPath[0] || _T('\\') == strPath[0] ) );
|
return cDevicePath::IsAbsolutePath(strPath);
|
||||||
|
#else
|
||||||
|
// IF there's a first character AND it's a '/', it's absolute.
|
||||||
|
return( strPath.size() > 0 && ( _T('/') == strPath[0] ) );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,54 +249,12 @@ static void InitCmdLineCommon(cCmdLineParser& parser)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// FillOutConfigInfo -- fills out all the common info with config file information
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
|
|
||||||
{
|
|
||||||
TSTRING str;
|
|
||||||
if(cf.Lookup(TSTRING(_T("POLFILE")), str))
|
|
||||||
{
|
|
||||||
pModeInfo->mPolFile = str;
|
|
||||||
}
|
|
||||||
if(cf.Lookup(TSTRING(_T("DBFILE")), str))
|
|
||||||
{
|
|
||||||
pModeInfo->mDbFile = str;
|
|
||||||
}
|
|
||||||
if(cf.Lookup(TSTRING(_T("SITEKEYFILE")), str))
|
|
||||||
{
|
|
||||||
pModeInfo->mSiteKeyFile = str;
|
|
||||||
}
|
|
||||||
if(cf.Lookup(TSTRING(_T("LOCALKEYFILE")), str))
|
|
||||||
{
|
|
||||||
pModeInfo->mLocalKeyFile = str;
|
|
||||||
}
|
|
||||||
if(cf.Lookup(TSTRING(_T("REPORTFILE")), str))
|
|
||||||
{
|
|
||||||
pModeInfo->mReportFile = str;
|
|
||||||
}
|
|
||||||
if(cf.Lookup(TSTRING(_T("EDITOR")), str))
|
|
||||||
{
|
|
||||||
pModeInfo->mEditor = str;
|
|
||||||
}
|
|
||||||
if(cf.Lookup(TSTRING(_T("LATEPROMPTING")), str))
|
|
||||||
{
|
|
||||||
if (_tcsicmp(str.c_str(), _T("true")) == 0)
|
|
||||||
pModeInfo->mbLatePassphrase = true;
|
|
||||||
}
|
|
||||||
if(cf.Lookup(TSTRING(_T("RESETACCESSTIME")), str))
|
|
||||||
{
|
|
||||||
// We do not support reset access time on Unix, so we issue a warning.
|
|
||||||
// This used to be a fatal error, however this prevents
|
|
||||||
// cross platform config files.
|
|
||||||
cTWUtil::PrintErrorMsg(eTWInvalidConfigFileKey(_T("RESETACCESSTIME"), eError::NON_FATAL));
|
|
||||||
}
|
|
||||||
if(cf.Lookup(TSTRING(_T("LOOSEDIRECTORYCHECKING")), str))
|
|
||||||
{
|
|
||||||
if (_tcsicmp(str.c_str(), _T("true")) == 0)
|
|
||||||
pModeInfo->mfLooseDirs = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Set up temp directory
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
static void util_InitTempDirectory(const cConfigFile& cf)
|
||||||
|
{
|
||||||
TSTRING temp_directory;
|
TSTRING temp_directory;
|
||||||
cf.Lookup(TSTRING(_T("TEMPDIRECTORY")), temp_directory);
|
cf.Lookup(TSTRING(_T("TEMPDIRECTORY")), temp_directory);
|
||||||
|
|
||||||
|
@ -304,6 +262,8 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
|
||||||
{
|
{
|
||||||
#if IS_AROS
|
#if IS_AROS
|
||||||
temp_directory = "T:";
|
temp_directory = "T:";
|
||||||
|
#elif IS_DOS_DJGPP
|
||||||
|
temp_directory = "/dev/c/temp/";
|
||||||
#else
|
#else
|
||||||
temp_directory = "/tmp/";
|
temp_directory = "/tmp/";
|
||||||
#endif
|
#endif
|
||||||
|
@ -315,11 +275,14 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
|
||||||
{
|
{
|
||||||
temp_directory.push_back('/');
|
temp_directory.push_back('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure it exists...
|
// make sure it exists...
|
||||||
//
|
//
|
||||||
|
|
||||||
#if USES_DEVICE_PATH
|
#if IS_AROS
|
||||||
temp_directory = cDevicePath::AsNative(temp_directory);
|
temp_directory = cDevicePath::AsNative(temp_directory);
|
||||||
|
#elif IS_DOS_DJGPP
|
||||||
|
temp_directory = cDevicePath::AsPosix(temp_directory);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (access(temp_directory.c_str(), F_OK) != 0)
|
if (access(temp_directory.c_str(), F_OK) != 0)
|
||||||
|
@ -334,8 +297,15 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
|
||||||
{
|
{
|
||||||
iFSServices::GetInstance()->SetTempDirName(temp_directory);
|
iFSServices::GetInstance()->SetTempDirName(temp_directory);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Set up various email reporting options
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
static void util_InitEmailOptions(cTWModeCommon* pModeInfo, const cConfigFile& cf)
|
||||||
|
{
|
||||||
|
TSTRING str;
|
||||||
if (cf.Lookup(TSTRING(_T("GLOBALEMAIL")), str))
|
if (cf.Lookup(TSTRING(_T("GLOBALEMAIL")), str))
|
||||||
{
|
{
|
||||||
if (str.length() != 0)
|
if (str.length() != 0)
|
||||||
|
@ -442,6 +412,60 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
|
||||||
{
|
{
|
||||||
pModeInfo->mMailFrom = str;
|
pModeInfo->mMailFrom = str;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// FillOutConfigInfo -- fills out all the common info with config file information
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
|
||||||
|
{
|
||||||
|
TSTRING str;
|
||||||
|
if(cf.Lookup(TSTRING(_T("POLFILE")), str))
|
||||||
|
{
|
||||||
|
pModeInfo->mPolFile = str;
|
||||||
|
}
|
||||||
|
if(cf.Lookup(TSTRING(_T("DBFILE")), str))
|
||||||
|
{
|
||||||
|
pModeInfo->mDbFile = str;
|
||||||
|
}
|
||||||
|
if(cf.Lookup(TSTRING(_T("SITEKEYFILE")), str))
|
||||||
|
{
|
||||||
|
pModeInfo->mSiteKeyFile = str;
|
||||||
|
}
|
||||||
|
if(cf.Lookup(TSTRING(_T("LOCALKEYFILE")), str))
|
||||||
|
{
|
||||||
|
pModeInfo->mLocalKeyFile = str;
|
||||||
|
}
|
||||||
|
if(cf.Lookup(TSTRING(_T("REPORTFILE")), str))
|
||||||
|
{
|
||||||
|
pModeInfo->mReportFile = str;
|
||||||
|
}
|
||||||
|
if(cf.Lookup(TSTRING(_T("EDITOR")), str))
|
||||||
|
{
|
||||||
|
pModeInfo->mEditor = str;
|
||||||
|
}
|
||||||
|
if(cf.Lookup(TSTRING(_T("LATEPROMPTING")), str))
|
||||||
|
{
|
||||||
|
if (_tcsicmp(str.c_str(), _T("true")) == 0)
|
||||||
|
pModeInfo->mbLatePassphrase = true;
|
||||||
|
}
|
||||||
|
if(cf.Lookup(TSTRING(_T("RESETACCESSTIME")), str))
|
||||||
|
{
|
||||||
|
// We do not support reset access time on Unix, so we issue a warning.
|
||||||
|
// This used to be a fatal error, however this prevents
|
||||||
|
// cross platform config files.
|
||||||
|
cTWUtil::PrintErrorMsg(eTWInvalidConfigFileKey(_T("RESETACCESSTIME"), eError::NON_FATAL));
|
||||||
|
}
|
||||||
|
if(cf.Lookup(TSTRING(_T("LOOSEDIRECTORYCHECKING")), str))
|
||||||
|
{
|
||||||
|
if (_tcsicmp(str.c_str(), _T("true")) == 0)
|
||||||
|
pModeInfo->mfLooseDirs = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
util_InitTempDirectory(cf);
|
||||||
|
|
||||||
|
util_InitEmailOptions(pModeInfo, cf);
|
||||||
|
|
||||||
// SYSLOG reporting
|
// SYSLOG reporting
|
||||||
if(cf.Lookup(TSTRING(_T("SYSLOGREPORTING")), str))
|
if(cf.Lookup(TSTRING(_T("SYSLOGREPORTING")), str))
|
||||||
|
|
|
@ -157,6 +157,9 @@ static bool SetExeDir( const TSTRING& strArgv0 )
|
||||||
TSTRING strFullPath;
|
TSTRING strFullPath;
|
||||||
if( iFSServices::GetInstance()->GetExecutableFilename( strFullPath, strArgv0 ) && !strFullPath.empty() )
|
if( iFSServices::GetInstance()->GetExecutableFilename( strFullPath, strArgv0 ) && !strFullPath.empty() )
|
||||||
{
|
{
|
||||||
|
#if USES_DEVICE_PATH
|
||||||
|
strFullPath = cDevicePath::AsPosix(strFullPath);
|
||||||
|
#endif
|
||||||
cSystemInfo::SetExePath(strFullPath);
|
cSystemInfo::SetExePath(strFullPath);
|
||||||
|
|
||||||
TSTRING::size_type s = strFullPath.find_last_of( _T('/') );
|
TSTRING::size_type s = strFullPath.find_last_of( _T('/') );
|
||||||
|
|
|
@ -58,7 +58,146 @@ void TestFile()
|
||||||
TEST(testStream);
|
TEST(testStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////
|
||||||
|
|
||||||
|
void testDosAsPosix(const std::string& in, const std::string& expected)
|
||||||
|
{
|
||||||
|
TEST( expected == cDosPath::AsPosix(in) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestDosAsPosix()
|
||||||
|
{
|
||||||
|
testDosAsPosix("c:\\foo", "/dev/c/foo");
|
||||||
|
testDosAsPosix("c:\\foo\\bar\\baz.txt", "/dev/c/foo/bar/baz.txt");
|
||||||
|
testDosAsPosix("c:/foo/bar/baz.txt", "/dev/c/foo/bar/baz.txt");
|
||||||
|
|
||||||
|
testDosAsPosix("c:\\", "/dev/c/");
|
||||||
|
testDosAsPosix("c:", "/dev/c");
|
||||||
|
|
||||||
|
testDosAsPosix("foo.txt", "foo.txt");
|
||||||
|
testDosAsPosix("bar\\foo.txt", "bar/foo.txt");
|
||||||
|
testDosAsPosix("bar/foo.txt", "bar/foo.txt");
|
||||||
|
|
||||||
|
testDosAsPosix("/foo/bar/baz.txt", "/foo/bar/baz.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testDosAsNative(const std::string& in, const std::string& expected)
|
||||||
|
{
|
||||||
|
TEST( expected == cDosPath::AsNative(in) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestDosAsNative()
|
||||||
|
{
|
||||||
|
testDosAsNative("/dev/c/foo", "c:\\foo");
|
||||||
|
testDosAsNative("/dev/c/", "c:\\");
|
||||||
|
testDosAsNative("/dev/c", "c:\\");
|
||||||
|
|
||||||
|
testDosAsNative("/foo/bar/baz", "/foo/bar/baz");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testDosIsAbsolute(const std::string& in, bool expected)
|
||||||
|
{
|
||||||
|
TEST( expected == cDosPath::IsAbsolutePath(in) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestDosIsAbsolute()
|
||||||
|
{
|
||||||
|
testDosIsAbsolute("C:\\", true);
|
||||||
|
testDosIsAbsolute("C:", true);
|
||||||
|
testDosIsAbsolute("C:\\foo", true);
|
||||||
|
testDosIsAbsolute("C:\\foo\\bar\\baz.txt", true);
|
||||||
|
|
||||||
|
testDosIsAbsolute("/foo", true);
|
||||||
|
|
||||||
|
testDosIsAbsolute("foo.txt", false);
|
||||||
|
testDosIsAbsolute("bar\\foo.txt", false);
|
||||||
|
testDosIsAbsolute("bar/foo.txt", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testDosBackupName(const std::string& in, const std::string& expected)
|
||||||
|
{
|
||||||
|
TCERR << "In: " << in << " | Expected: " << expected << " | Observed: " << cDosPath::BackupName(in) << std::endl;
|
||||||
|
|
||||||
|
TEST( expected == cDosPath::BackupName(in) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestDosBackupName()
|
||||||
|
{
|
||||||
|
testDosBackupName("C:\\12345678.123", "C:\\12345678");
|
||||||
|
testDosBackupName("C:\\12345678", "C:\\12345678");
|
||||||
|
testDosBackupName("C:\\1.123", "C:\\1_123");
|
||||||
|
testDosBackupName("C:\\1", "C:\\1");
|
||||||
|
|
||||||
|
testDosBackupName("C:\\FOO\\12345678.123", "C:\\FOO\\12345678");
|
||||||
|
testDosBackupName("C:\\FOO.BAR\\1234.123", "C:\\FOO.BAR\\1234_123");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testArosAsPosix(const std::string& in, const std::string& expected)
|
||||||
|
{
|
||||||
|
TCERR << "In: " << in << " | Expected: " << expected << " | Observed: " << cArosPath::AsPosix(in) << std::endl ;
|
||||||
|
TEST( expected == cArosPath::AsPosix(in) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestArosAsPosix()
|
||||||
|
{
|
||||||
|
// testArosAsPosix("DH0:", "/DH0/");
|
||||||
|
testArosAsPosix("DH0:Foo", "/DH0/Foo");
|
||||||
|
testArosAsPosix("DH0:Foo/Bar", "/DH0/Foo/Bar");
|
||||||
|
|
||||||
|
testArosAsPosix("/DH0/Foo/Bar", "/DH0/Foo/Bar");
|
||||||
|
|
||||||
|
testArosAsPosix("Foo", "Foo");
|
||||||
|
testArosAsPosix("Foo/Bar", "Foo/Bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testArosAsNative(const std::string& in, const std::string& expected)
|
||||||
|
{
|
||||||
|
TEST( expected == cArosPath::AsNative(in) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestArosAsNative()
|
||||||
|
{
|
||||||
|
testArosAsNative("/DH0", "DH0:");
|
||||||
|
testArosAsNative("/DH0/Foo", "DH0:Foo" );
|
||||||
|
testArosAsNative("/DH0/Foo/Bar", "DH0:Foo/Bar" );
|
||||||
|
|
||||||
|
testArosAsNative("DH0:Foo/Bar", "DH0:Foo/Bar");
|
||||||
|
|
||||||
|
testArosAsNative("Foo", "Foo");
|
||||||
|
testArosAsNative("Foo/Bar", "Foo/Bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
void testArosIsAbsolute(const std::string& in, bool expected)
|
||||||
|
{
|
||||||
|
TEST( expected == cArosPath::IsAbsolutePath(in) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestArosIsAbsolute()
|
||||||
|
{
|
||||||
|
testArosIsAbsolute("DH0:", true);
|
||||||
|
testArosIsAbsolute("DH0:Foo", true);
|
||||||
|
testArosIsAbsolute("DH0:Foo/bar", true);
|
||||||
|
|
||||||
|
testArosIsAbsolute("/DH0/Foo/bar", true);
|
||||||
|
|
||||||
|
testArosIsAbsolute("Foo/bar", false);
|
||||||
|
testArosIsAbsolute("Foo", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void RegisterSuite_File()
|
void RegisterSuite_File()
|
||||||
{
|
{
|
||||||
RegisterTest("File", "Basic", TestFile);
|
RegisterTest("File", "Basic", TestFile);
|
||||||
|
RegisterTest("File", "DosAsPosix", TestDosAsPosix);
|
||||||
|
RegisterTest("File", "DosAsNative", TestDosAsNative);
|
||||||
|
RegisterTest("File", "DosIsAbsolute", TestDosIsAbsolute);
|
||||||
|
RegisterTest("File", "DosBackupName", TestDosBackupName);
|
||||||
|
// TODO: Finish these
|
||||||
|
/*
|
||||||
|
RegisterTest("File", "ArosAsPosix", TestArosAsPosix);
|
||||||
|
RegisterTest("File", "ArosAsNative", TestArosAsNative);
|
||||||
|
RegisterTest("File", "ArosIsAbsolute", TestArosIsAbsolute);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "fco/fcospechelper.h"
|
#include "fco/fcospechelper.h"
|
||||||
#include "core/fsservices.h"
|
#include "core/fsservices.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// PrintFCOTree -- recursively prints an fco's name and all of it's children's
|
// PrintFCOTree -- recursively prints an fco's name and all of it's children's
|
||||||
|
@ -92,6 +93,9 @@ void TestFCOSpecImpl2()
|
||||||
cDebug d("TestFCOSpecImpl2");
|
cDebug d("TestFCOSpecImpl2");
|
||||||
d.TraceDebug("Entering...\n");
|
d.TraceDebug("Entering...\n");
|
||||||
|
|
||||||
|
if( -1 == access("/etc", F_OK))
|
||||||
|
skip("/etc not found/accessible");
|
||||||
|
|
||||||
cFSDataSourceIter dataSrc;
|
cFSDataSourceIter dataSrc;
|
||||||
|
|
||||||
// create an FSSpec and set up some start and stop points...
|
// create an FSSpec and set up some start and stop points...
|
||||||
|
|
|
@ -45,7 +45,9 @@
|
||||||
#include "fco/fcospeclist.h"
|
#include "fco/fcospeclist.h"
|
||||||
#include "twtest/test.h"
|
#include "twtest/test.h"
|
||||||
#include "util/fileutil.h"
|
#include "util/fileutil.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
// helper class that checks output of each fcospec
|
// helper class that checks output of each fcospec
|
||||||
class cPolicyParserTester {
|
class cPolicyParserTester {
|
||||||
|
@ -72,6 +74,9 @@ void test_policy_file(const std::string& polfile)
|
||||||
pol_path.append("/");
|
pol_path.append("/");
|
||||||
pol_path.append(polfile);
|
pol_path.append(polfile);
|
||||||
|
|
||||||
|
if(-1 == access(pol_path.c_str(), F_OK))
|
||||||
|
skip("policy parser test file not found/accessible");
|
||||||
|
|
||||||
std::ifstream in;
|
std::ifstream in;
|
||||||
in.open(pol_path.c_str());
|
in.open(pol_path.c_str());
|
||||||
if( ! in.good() )
|
if( ! in.good() )
|
||||||
|
|
|
@ -208,7 +208,12 @@ bool cFileUtil::BackupFile(const TSTRING& filename, bool printWarningOnFailure)
|
||||||
throw eFileWrite(filename, iFSServices::GetInstance()->GetErrString() );
|
throw eFileWrite(filename, iFSServices::GetInstance()->GetErrString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if IS_DOS_DJGPP
|
||||||
|
TSTRING backup_filename = cDosPath::BackupName( cDosPath::AsNative(filename) );
|
||||||
|
#else
|
||||||
TSTRING backup_filename = filename;
|
TSTRING backup_filename = filename;
|
||||||
|
#endif
|
||||||
|
|
||||||
backup_filename += iFSServices::GetInstance()->GetStandardBackupExtension();
|
backup_filename += iFSServices::GetInstance()->GetStandardBackupExtension();
|
||||||
|
|
||||||
// remove the backup file if it exists. We ingore the return value from
|
// remove the backup file if it exists. We ingore the return value from
|
||||||
|
|
Loading…
Reference in New Issue