// // Copyright 2000 Perforce Software. All rights reserved. // // This file is part of Perforce - the FAST SCM System. // // FstatHelper: // An object to perform synchronous fstats on a file. // ------------------------------------- // Includes // #include <p4wp4.h> #include <fstathelper.h> // // A list of all the fstat tags that can be // returned // static const char * all_fstat_names[] = { P4Tag::v_clientFile, P4Tag::v_depotFile, P4Tag::v_headAction, P4Tag::v_headChange, P4Tag::v_headRev, P4Tag::v_headType, P4Tag::v_headTime, P4Tag::v_haveRev, P4Tag::v_action, P4Tag::v_change, P4Tag::v_unresolved, P4Tag::v_otherOpen, P4Tag::v_otherLock, P4Tag::v_ourLock, NULL }; // // This can be used to map a text filetype to a enumerated one // XXX // This should be in a file somewhere in our "middle" directory!! // const struct fileTypeMap { FileSysType checkType; const char *type; } fileTypeTable[] = { FST_TEXT, "text", FST_XTEXT, "xtext", FST_BINARY, "binary", FST_XBINARY, "xbinary", FST_APPLEFILE, "apple", FST_CBINARY, "ubinary", FST_SYMLINK, "symlink", FST_RESOURCE, "resource", FST_SPECIAL, "special", FST_DIRECTORY, "directory", FST_MISSING, "missing", FST_CANTTELL, "unreadable", FST_EMPTY, "empty", FST_TEXT, 0 } ; // ------------------------------------- // Constructors and destructor. // FstatHelper::FstatHelper( StrPtr & pathSpec, ClientApi & api ) : ClientUser() { this->api = &api; this->pathSpec = pathSpec; this->results = NULL; this->fileSys = NULL; } FstatHelper::~FstatHelper() { if ( this->results ) { delete this->results; this->results = NULL; } if ( this->fileSys ) { delete this->fileSys; this->fileSys = NULL; } } int FstatHelper::IsTextFile() { FileSysType filetype = GetFileType(); switch ( filetype ) { case FST_TEXT: case FST_XTEXT: case FST_RTEXT: case FST_RXTEXT: case FST_ATEXT: return 1; default: return 0; } } int FstatHelper::FileTypeUnknown() { FileSysType filetype = GetFileType(); return ( filetype == FST_CANTTELL ? 1 : 0 ); } FileSysType FstatHelper::GetFileType() { StrDict * result = GetResults(); if ( result ) { StrPtr * temp = result->GetVar( P4Tag::v_headType ); if( !temp ) return FST_CANTTELL; const fileTypeMap * entry = fileTypeTable; while ( entry->type ) { if ( !strcmp( temp->Text(), entry->type ) ) { return entry->checkType; } entry++; } return FST_TEXT; } else { return FST_CANTTELL; } } FileSys * FstatHelper::GetLocalFile() { StrPtr * localPath = GetLocalPath(); if ( (!this->fileSys) && localPath ) { this->fileSys = FileSys::Create( GetFileType() ); this->fileSys->Set( localPath->Text() ); } return (this->fileSys); } StrPtr * FstatHelper::GetLocalPath() { // // Get the fstat information // StrDict * result = GetResults(); if ( result ) { // // Get the local file on the drive // return result->GetVar( P4Tag::v_clientFile ); } return NULL; } StrPtr * FstatHelper::GetAction() { // // Get the fstat information // StrDict * result = GetResults(); if ( result ) { // // Get the client's action // return result->GetVar( P4Tag::v_action ); } return NULL; } StrDict * FstatHelper::GetResults() { // // Check to see if results were already retrieved // if not, get them // if ( !results ) { char * temp[] = { pathSpec.Text() }; this->api->SetArgv( 1, temp ); this->api->Run( P4Tag::u_fstat, this ); } return results; } void FstatHelper::OutputStat( StrDict * varList ) { this->results = new StrBufDict(); // // Cheesy duplication of StrDict // // XXX This should be replaced with a proper // StrDict copy constructor. The only reason this // works now is that we know all the values that // we want from it. A blind carbon copy would be better // and more elegant. // unsigned int i = 0; for ( i = 0; all_fstat_names[i] != NULL; i++ ) { const StrPtr * temp = varList->GetVar( all_fstat_names[i] ); if ( temp ) { this->results->SetVar( all_fstat_names[i], temp ); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/util/fstathelper.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |