From e71023730e61115af49180e9ddb1c67c98ffce42 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Fri, 1 Apr 2016 18:01:59 -0700 Subject: [PATCH] Add Posix<-->Native path conversion, and handle absence of Unix unlinked-but-open tempfile trick on AROS --- src/core/file.h | 14 +++++++++++-- src/core/file_unix.cpp | 41 ++++++++++++++++++++++++++++++++++++- src/core/unixfsservices.cpp | 15 +++++++++++++- src/fs/fsparserutil.cpp | 5 +++++ src/tripwire/twcmdline.cpp | 6 ++++++ 5 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/core/file.h b/src/core/file.h index 29f0630..3289660 100644 --- a/src/core/file.h +++ b/src/core/file.h @@ -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 diff --git a/src/core/file_unix.cpp b/src/core/file_unix.cpp index d63ed5f..94b92db 100644 --- a/src/core/file_unix.cpp +++ b/src/core/file_unix.cpp @@ -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 &v, bool bFullPaths) const throw(eFSServices) { +#else +void cUnixFSServices::ReadDir(const TSTRING& strFilenameC, std::vector& 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; diff --git a/src/fs/fsparserutil.cpp b/src/fs/fsparserutil.cpp index 0c08e50..163fc76 100644 --- a/src/fs/fsparserutil.cpp +++ b/src/fs/fsparserutil.cpp @@ -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& l, cFCOName& nam for( std::list::const_iterator i = l.begin(); i != l.end(); i++ ) strT += *i; +#ifdef __AROS__ + strT = cArosPath::AsPosix(strT); +#endif + // let cFCOName handle interpretation nameOut = strT; } diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index 6d50bf3..cfccb72 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -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: ");