KDevelop API Documentation

vcs/cvsservice/cvsdir.cpp

Go to the documentation of this file.
00001 /*************************************************************************** 00002 * Copyright (C) 2003 by Mario Scalas * 00003 * mario.scalas@libero.it * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include <qfile.h> 00013 #include <qtextstream.h> 00014 00015 #include "cvsdir.h" 00016 00018 // class CVSDir 00020 00021 CVSDir::CVSDir() : QDir() 00022 { 00023 } 00024 00026 00027 CVSDir::CVSDir( const QDir &dir ) 00028 : QDir( dir ) 00029 { 00030 // We deal with absolute paths only 00031 convertToAbs(); 00032 00033 m_cvsDir = absPath() + QDir::separator() + "CVS"; 00034 00035 if (isValid()) 00036 refreshEntriesCache(); 00037 } 00038 00040 00041 CVSDir::CVSDir( const CVSDir &aCvsDir ) 00042 : QDir( aCvsDir ) 00043 { 00044 *this = aCvsDir; 00045 } 00046 00048 00049 CVSDir &CVSDir::operator=( const CVSDir &aCvsDir ) 00050 { 00051 m_cvsDir = aCvsDir.m_cvsDir; 00052 m_cachedEntries = aCvsDir.m_cachedEntries; 00053 QDir::operator=( aCvsDir ); 00054 00055 return *this; 00056 } 00057 00059 00060 CVSDir::~CVSDir() 00061 { 00062 } 00063 00065 00066 bool CVSDir::isValid() const 00067 { 00068 return exists() && 00069 QFile::exists( entriesFileName() ) && 00070 QFile::exists( rootFileName() ) && 00071 QFile::exists( repoFileName() ); 00072 } 00073 00075 00076 QString CVSDir::entriesFileName() const 00077 { 00078 return m_cvsDir + QDir::separator() + "Entries"; 00079 } 00080 00082 00083 QString CVSDir::rootFileName() const 00084 { 00085 return m_cvsDir + QDir::separator() + "Root"; 00086 } 00087 00089 00090 QString CVSDir::repoFileName() const 00091 { 00092 return m_cvsDir + QDir::separator() + "Repository"; 00093 } 00094 00096 00097 QString CVSDir::cvsIgnoreFileName() const 00098 { 00099 return absPath() + QDir::separator() + ".cvsignore"; 00100 } 00101 00103 00104 QString CVSDir::repository() const 00105 { 00106 // The content of CVS/Repository is a single line with the path into the 00107 // repository of the modules checked out in this directory (just like 00108 // "kdevelop/parts/cvsservice"): so we can read a single line of the file 00109 // and we are done! 00110 QString content; 00111 00112 if (!isValid()) 00113 return QString::null; 00114 00115 QByteArray bytes = cacheFile( repoFileName() ); 00116 QTextStream t( bytes, IO_ReadOnly ); 00117 content += t.readLine(); 00118 00119 return content; 00120 } 00121 00123 00124 QString CVSDir::root() const 00125 { 00126 // Same as CVSDir::repository() but CVS/Root contains the path of the 00127 // CVS server as used in "cvs -d <server-path>" (in example: 00128 // ":pserver:marios@cvs.kde.org:/home/kde") 00129 QString content; 00130 00131 if (!isValid()) 00132 return QString::null; 00133 00134 QByteArray bytes = cacheFile( repoFileName() ); 00135 QTextStream t( bytes, IO_ReadOnly ); 00136 content += t.readLine(); 00137 00138 return content; 00139 } 00140 00142 00143 QByteArray CVSDir::cacheFile( const QString &fileName ) 00144 { 00145 QFile f( fileName ); 00146 if (!f.open( IO_ReadOnly )) 00147 return QByteArray(); 00148 return f.readAll(); 00149 } 00150 00152 00153 QStringList CVSDir::registeredEntryList() const 00154 { 00155 QStringList l; 00156 if (!isValid()) 00157 return l; 00158 00159 QByteArray bytes = cacheFile( entriesFileName() ); 00160 QTextStream t( bytes, IO_ReadOnly ); 00161 CVSEntry entry; 00162 while (!t.eof()) 00163 { 00164 QString line = t.readLine(); 00165 CVSEntry::parse( line, entry ); 00166 if (entry.isValid()) 00167 l.append( entry.fileName() ); 00168 } 00169 return l; 00170 } 00171 00173 00174 bool CVSDir::isRegistered( const QString fileName ) const 00175 { 00176 CVSEntry entry = fileStatus( fileName ); 00177 return entry.isValid() && entry.fileName() == fileName; 00178 } 00179 00181 00182 void CVSDir::refreshEntriesCache() const 00183 { 00184 m_cachedEntries.clear(); 00185 00186 QByteArray bytes = cacheFile( entriesFileName() ); 00187 QTextStream t( bytes, IO_ReadOnly ); 00188 CVSEntry entry; 00189 while (!t.eof()) 00190 { 00191 QString line = t.readLine(); 00192 CVSEntry::parse( line, entry ); 00193 if (entry.isValid()) 00194 m_cachedEntries[ entry.fileName() ] = entry; 00195 } 00196 } 00197 00199 00200 CVSEntry CVSDir::fileStatus( const QString &fileName, bool refreshCache ) const 00201 { 00202 if (refreshCache) 00203 refreshEntriesCache(); 00204 00205 if (m_cachedEntries.contains( fileName )) 00206 { 00207 return m_cachedEntries[ fileName ]; 00208 } 00209 else 00210 return CVSEntry( fileName ); // Just the file name 00211 } 00212 00214 00215 void CVSDir::ignoreFile( const QString &fileName ) 00216 { 00217 if (!isValid()) 00218 return; 00219 00220 QFile f( cvsIgnoreFileName() ); 00221 if (!f.open( IO_ReadOnly)) 00222 return; 00223 00224 QByteArray cachedFile = f.readAll(); 00225 QTextStream t( cachedFile, IO_ReadOnly | IO_WriteOnly ); 00226 00227 QString readFileName; 00228 bool found = false; 00229 00230 while (!t.eof() && !found) 00231 { 00232 readFileName = t.readLine(); 00233 found = (fileName == readFileName); 00234 } 00235 00236 f.close(); 00237 if (!found) 00238 { 00239 f.open( IO_WriteOnly ); 00240 00241 t << fileName << "\n"; 00242 00243 f.writeBlock( cachedFile ); 00244 f.close(); 00245 } 00246 } 00247 00249 00250 void CVSDir::doNotIgnoreFile( const QString &fileName ) 00251 { 00252 if (!isValid()) 00253 return; 00254 00255 // 1. Read all .ignore file in memory 00256 QFile f( cvsIgnoreFileName() ); 00257 if (!f.open( IO_ReadOnly )) 00258 return; // No .cvsignore file? Nothing to do then! 00259 00260 QByteArray cachedFile = f.readAll(); 00261 QTextIStream is( cachedFile ); 00262 00263 QByteArray cachedOutputFile; 00264 QTextOStream os( cachedOutputFile ); 00265 00266 bool removed = false; 00267 while (!is.eof()) 00268 { 00269 QString readLine = is.readLine(); 00270 if (readLine != fileName) 00271 os << readLine << "\n"; // QTextStream::readLine() eats the "\n" ... 00272 else 00273 removed = true; 00274 } 00275 00276 f.close(); 00277 if (removed) 00278 { 00279 f.open( IO_WriteOnly ); 00280 f.writeBlock( cachedOutputFile ); 00281 f.close(); 00282 } 00283 } 00284 00286 00287 VCSFileInfoMap CVSDir::dirStatus() const 00288 { 00289 VCSFileInfoMap vcsInfo; 00291 QStringList entries = registeredEntryList(); 00292 for (QStringList::const_iterator it = entries.begin(); it != entries.end(); ++it) 00293 { 00294 const QString &fileName = (*it); 00295 const CVSEntry entry = fileStatus( fileName ); 00296 00297 vcsInfo.insert( fileName, entry.toVCSFileInfo() ); 00298 } 00299 00300 return vcsInfo; 00301 } 00302 00304 00305 VCSFileInfoMap *CVSDir::cacheableDirStatus() const 00306 { 00307 VCSFileInfoMap *vcsInfo = new VCSFileInfoMap; 00309 QStringList entries = registeredEntryList(); 00310 for (QStringList::const_iterator it = entries.begin(); it != entries.end(); ++it) 00311 { 00312 const QString &fileName = (*it); 00313 const CVSEntry entry = fileStatus( fileName ); 00314 00315 vcsInfo->insert( fileName, entry.toVCSFileInfo() ); 00316 } 00317 00318 return vcsInfo; 00319 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:14 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003