Add Posix<-->Native path conversion, and handle absence of Unix unlinked-but-open tempfile trick on AROS

This commit is contained in:
Brian Cox 2016-04-01 18:01:59 -07:00
parent ec90cdc0a5
commit e71023730e
5 changed files with 77 additions and 4 deletions

View File

@ -73,8 +73,7 @@ class cFile
{
public:
#if IS_UNIX
typedef off_t File_t;
typedef off_t File_t;
#else //WIN32
typedef int64 File_t;
@ -140,5 +139,16 @@ public:
bool isWritable;
};
#ifdef __AROS__
class cArosPath
{
public:
static TSTRING AsPosix(const TSTRING& in);
static TSTRING AsNative(const TSTRING& in);
};
#endif
#endif //__FILE_H

View File

@ -119,8 +119,15 @@ cFile::~cFile()
///////////////////////////////////////////////////////////////////////////////
// Open
///////////////////////////////////////////////////////////////////////////////
#ifndef __AROS
void cFile::Open( const TSTRING& sFileName, uint32 flags )
{
#else
void cFile::Open( const TSTRING& sFileNameC, uint32 flags )
{
TSTRING sFileName = cArosPath::AsNative(sFileNameC);
#endif
mode_t openmode = 0664;
if ( mpData->mpCurrStream != NULL )
Close();
@ -161,6 +168,7 @@ void cFile::Open( const TSTRING& sFileName, uint32 flags )
if ( flags & OPEN_CREATE )
perm |= O_CREAT;
//
// actually open the file
//
@ -169,6 +177,8 @@ void cFile::Open( const TSTRING& sFileName, uint32 flags )
{
throw( eFileOpen( sFileName, iFSServices::GetInstance()->GetErrString() ) );
}
#ifndef __AROS__
if( flags & OPEN_LOCKED_TEMP )
{
// unlink this file
@ -176,9 +186,10 @@ void cFile::Open( const TSTRING& sFileName, uint32 flags )
{
// we weren't able to unlink file, so close handle and fail
close( fh );
throw( eFileOpen( sFileName, iFSServices::GetInstance()->GetErrString() ) );
throw( eFileOpen( sFileName, iFSServices::GetInstance()->GetErrString() ) );
}
}
#endif
//
// turn the file handle into a FILE*
@ -369,3 +380,31 @@ void cFile::Truncate( File_t offset ) // throw(eFile)
throw( eFileTrunc( mpData->mFileName, iFSServices::GetInstance()->GetErrString() ) );
}
#ifdef __AROS__
TSTRING cArosPath::AsPosix( const TSTRING& in )
{
if (in[0] == '/')
return in;
TSTRING out = '/' + in;
std::replace(out.begin(), out.end(), ':', '/');
return out;
}
TSTRING cArosPath::AsNative( const TSTRING& in )
{
if (in[0] != '/')
return in;
int x;
for (x=1; in[x] == '/' && x<in.length(); x++);
TSTRING out = in.substr(x);
TSTRING::size_type t = out.find_first_of('/');
out[t] = ':';
return out;
}
#endif

View File

@ -37,6 +37,7 @@
#include "core/stdcore.h"
#include "core/corestrings.h"
#include "core/file.h"
#if !IS_UNIX //encase this all in an ifdef so it won't cause compile errors
#error Must be unix for unixfsservices
@ -177,9 +178,15 @@ TCHAR cUnixFSServices::GetPathSeparator() const
return '/';
}
#ifndef __AROS__
void cUnixFSServices::ReadDir(const TSTRING& strFilename, std::vector<TSTRING> &v, bool bFullPaths) const throw(eFSServices)
{
#else
void cUnixFSServices::ReadDir(const TSTRING& strFilenameC, std::vector<TSTRING>& v, bool bFullPaths) const throw(eFSServices)
{
TSTRING strFilename = cArosPath::AsNative(strFilenameC);
#endif
//Get all the filenames
DIR* dp;
dp = opendir( strFilename.c_str() );
@ -326,8 +333,14 @@ void cUnixFSServices::SetTempDirName(TSTRING& tmpPath) {
}
#ifndef __AROS__
void cUnixFSServices::Stat( const TSTRING& strName, cFSStatArgs &stat ) const throw(eFSServices)
{
#else
void cUnixFSServices::Stat( const TSTRING& strNameC, cFSStatArgs& stat) const throw(eFSServices)
{
TSTRING strName = cArosPath::AsNative(strNameC);
#endif
//local variable for obtaining info on file.
struct stat statbuf;

View File

@ -41,6 +41,7 @@
#include "fsparserutil.h"
#include "core/fsservices.h"
#include "core/file.h"
#include "fspropset.h"
#include "fsstrings.h"
#include "fco/fcopropvector.h"
@ -136,6 +137,10 @@ void cFSParserUtil::InterpretFCOName( const std::list<TSTRING>& l, cFCOName& nam
for( std::list<TSTRING>::const_iterator i = l.begin(); i != l.end(); i++ )
strT += *i;
#ifdef __AROS__
strT = cArosPath::AsPosix(strT);
#endif
// let cFCOName handle interpretation
nameOut = strT;
}

View File

@ -304,6 +304,12 @@ static void FillOutConfigInfo(cTWModeCommon* pModeInfo, const cConfigFile& cf)
// make sure it exists...
//
#ifdef __AROS__
str = cArosPath::AsNative(str);
#endif
if (access(str.c_str(), F_OK) != 0) {
TSTRING errStr = TSS_GetString( cCore, core::STR_BAD_TEMPDIRECTORY );
TSTRING tmpStr = _T("Directory: ");