// GetTempDir //------------------------------------------------------------------------------ /*static*/ bool FileIO::GetTempDir( AString & output ) { #if defined( __WINDOWS__ ) char buffer[ MAX_PATH ]; DWORD len = GetTempPath( MAX_PATH, buffer ); if ( len != 0 ) { output = buffer; // Ensure slash terminated const bool slashTerminated = ( output.EndsWith( '/' ) || output.EndsWith( '\\' ) ); if ( !slashTerminated ) { output += '\\'; } return true; } #elif defined( __LINUX__ ) || defined( __APPLE__ ) output = "/tmp/"; return true; #else #error Unknown platform #endif return false; }
// CONSTRUCTOR //------------------------------------------------------------------------------ FileNode::FileNode( const AString & fileName, uint32_t controlFlags ) : Node( fileName, Node::FILE_NODE, controlFlags ) { ASSERT( fileName.EndsWith( "\\" ) == false ); ASSERT( ( fileName.FindLast( ':' ) == nullptr ) || ( fileName.FindLast( ':' ) == ( fileName.Get() + 1 ) ) ); m_LastBuildTimeMs = 1; // very little work required }
/*--------------------------------------------------------------------------------*/ AString PostgresDatabase::GetErrorMessage(PGconn *conn, bool full) { AString msg; if (conn) { msg = AString(PQerrorMessage(conn)).SearchAndReplace("\r", "").SearchAndReplace("\n\n", ", "); if (msg.EndsWith(", ")) msg = msg.Left(msg.len() - 2); if (!full) msg = msg.Line(0); } else msg = "No connection!"; return msg; }
// FormatName //------------------------------------------------------------------------------ /*static*/ void DirectoryListNode::FormatName( const AString & path, const Array< AString > * patterns, bool recursive, const Array< AString > & excludePaths, const Array< AString > & excludeFiles, AString & result ) { ASSERT( path.EndsWith( NATIVE_SLASH ) ); AStackString<> patternString; if ( patterns ) { const size_t numPatterns = patterns->GetSize(); for ( size_t i=0; i<numPatterns; ++i ) { if ( i > 0 ) { patternString += '<'; } patternString += (*patterns)[ i ]; } } result.Format( "%s|%s|%s|", path.Get(), patternString.Get(), recursive ? "true" : "false" ); const AString * const end = excludePaths.End(); for ( const AString * it = excludePaths.Begin(); it!=end; ++it ) { const AString & excludePath = *it; ASSERT( excludePath.EndsWith( NATIVE_SLASH ) ); result += excludePath; result += '<'; } if ( !excludeFiles.IsEmpty() ) { result += '|'; const AString * const endFiles = excludeFiles.End(); for ( const AString * itFiles = excludeFiles.Begin(); itFiles != endFiles; ++itFiles ) { const AString & excludedFile = *itFiles; result += excludedFile; result += '<'; } } }
// CONSTRUCTOR //------------------------------------------------------------------------------ DirectoryListNode::DirectoryListNode( const AString & name, const AString & path, const Array< AString > * patterns, bool recursive, const Array< AString > & excludePaths, const Array< AString > & filesToExclude ) : Node( name, Node::DIRECTORY_LIST_NODE, Node::FLAG_NONE ) , m_Path( path ) , m_Patterns() , m_ExcludePaths( excludePaths ) , m_FilesToExclude( filesToExclude ) , m_Recursive( recursive ) , m_Files( 4096, true ) { if ( patterns ) { m_Patterns = *patterns; } // ensure name is correctly formatted // path|[patterns]|recursive|[excludePath] ASSERT( name.BeginsWith( path ) ); ASSERT( name[ path.GetLength() ] == '|' ); ASSERT( m_Patterns.IsEmpty() || ( name.Find( m_Patterns[ 0 ].Get() ) == name.Get() + path.GetLength() + 1 ) ); ASSERT( ( recursive && name.Find( "|true|" ) ) || ( !recursive && name.Find( "|false|" ) ) ); // paths must have trailing slash ASSERT( path.EndsWith( NATIVE_SLASH ) ); // make sure exclusion path has trailing slash if provided #ifdef DEBUG const AString * const end = excludePaths.End(); for ( const AString * it=excludePaths.Begin(); it != end; ++it ) { ASSERT( ( *it ).EndsWith( NATIVE_SLASH ) ); } #endif }