diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/AdminSessionI.cpp | 25 | ||||
-rw-r--r-- | cpp/src/IceGrid/FileCache.cpp | 55 | ||||
-rw-r--r-- | cpp/src/IceGrid/PlatformInfo.cpp | 29 | ||||
-rw-r--r-- | cpp/src/IceGrid/PlatformInfo.h | 2 | ||||
-rw-r--r-- | cpp/src/IceGrid/ServerI.cpp | 24 |
5 files changed, 91 insertions, 44 deletions
diff --git a/cpp/src/IceGrid/AdminSessionI.cpp b/cpp/src/IceGrid/AdminSessionI.cpp index b30a1ecddf8..44a634abd5d 100644 --- a/cpp/src/IceGrid/AdminSessionI.cpp +++ b/cpp/src/IceGrid/AdminSessionI.cpp @@ -315,19 +315,20 @@ AdminSessionI::addFileIterator(const FileReaderPrx& reader, throw ex; } - Ice::Long offset = 0; - if(nLines > 0) + // + // Always call getOffsetFromEnd even if nLines < 0. This allows to + // throw right away if the file doesn't exit. + // + Ice::Long offset; + try { - try - { - offset = reader->getOffsetFromEnd(filename, nLines); - } - catch(const Ice::LocalException& ex) - { - ostringstream os; - os << ex; - throw FileNotAvailableException(os.str()); - } + offset = reader->getOffsetFromEnd(filename, nLines); + } + catch(const Ice::LocalException& ex) + { + ostringstream os; + os << ex; + throw FileNotAvailableException(os.str()); } Ice::PropertiesPtr properties = reader->ice_getCommunicator()->getProperties(); diff --git a/cpp/src/IceGrid/FileCache.cpp b/cpp/src/IceGrid/FileCache.cpp index 8f83b830400..4fbaffaf9ad 100644 --- a/cpp/src/IceGrid/FileCache.cpp +++ b/cpp/src/IceGrid/FileCache.cpp @@ -33,15 +33,27 @@ FileCache::getOffsetFromEnd(const string& file, int originalCount) throw FileNotAvailableException("failed to open file `" + file + "'"); } - streamoff blockSize = 16 * 1024; // Start reading a block of 16K from the end of the file. + if(originalCount < 0) + { + return 0; + } + is.seekg(0, ios::end); streampos endOfFile = is.tellg(); + if(originalCount == 0) + { + return endOfFile; + } + + streamoff blockSize = 16 * 1024; // Start reading a block of 16K from the end of the file. streampos lastBlockOffset = endOfFile; int totalCount = 0; - streamoff totalSize = 0; string line; + deque<pair<streampos, string> > lines; do { + lines.clear(); + // // Move the current position of the stream to the new block to // read. @@ -59,24 +71,19 @@ FileCache::getOffsetFromEnd(const string& file, int originalCount) // // Read the block and count the number of lines in the block - // as well as the number of bytes read. If we found the "first - // last N line", we start throwing out the lines read at the - // begining of the file. The total size read will give us the - // position from the end of the file. + // If we found the "first last N lines", we start throwing out + // the lines read at the begining of the file. // - deque<string> lines; int count = originalCount - totalCount; // Number of lines left to find. - while(is.good() && is.tellg() < streamoff(lastBlockOffset)) + while(is.good() && is.tellg() <= streamoff(lastBlockOffset)) { + streampos beg = is.tellg(); getline(is, line); - - lines.push_back(line); + lines.push_back(make_pair(beg, line)); ++totalCount; - totalSize += line.size() + 1; if(lines.size() == static_cast<unsigned int>(count + 1)) { --totalCount; - totalSize -= lines.front().size() + 1; lines.pop_front(); } } @@ -95,14 +102,21 @@ FileCache::getOffsetFromEnd(const string& file, int originalCount) blockSize *= 2; // Read a bigger block. } } - while(totalCount < originalCount && !is.bad()); + while(totalCount < originalCount && !is.bad()); if(is.bad()) { throw FileNotAvailableException("unrecoverable error occured while reading file `" + file + "'"); } - return endOfFile - totalSize; + if(lines.empty()) + { + return 0; + } + else + { + return lines[0].first; + } } bool @@ -134,6 +148,7 @@ FileCache::read(const string& file, Ice::Long offset, int size, Ice::Long& newOf is.seekg(0, ios::end); if(offset >= is.tellg()) { +// cerr << "reading at EOF " << offset << " " << is.tellg() << endl; newOffset = is.tellg(); lines = Ice::StringSeq(); return true; @@ -147,15 +162,20 @@ FileCache::read(const string& file, Ice::Long offset, int size, Ice::Long& newOf is.seekg(static_cast<streamoff>(offset), ios::beg); int totalSize = 0; string line; + +// cerr << "starting read " << offset << endl; for(int i = 0; is.good(); ++i) { getline(is, line); +// cerr << "read " << " " << is.tellg() << " " << line << endl; + int lineSize = static_cast<int>(line.size()) + 5; // 5 bytes for the encoding of the string size (worst case) if(lineSize + totalSize > size) { - if(size - totalSize - 5) // If there's some room left for a part of the string, return a partial string + if(totalSize + 5 < size) { - line.substr(0, size - totalSize - 5); + // There's some room left for a part of the string, return a partial string + line = line.substr(0, size - totalSize - 5); lines.push_back(line); newOffset += line.size(); } @@ -163,7 +183,7 @@ FileCache::read(const string& file, Ice::Long offset, int size, Ice::Long& newOf { lines.push_back(""); } - break; + return false; // We didn't reach the end of file, we've just reached the size limit! } totalSize += lineSize; @@ -174,6 +194,7 @@ FileCache::read(const string& file, Ice::Long offset, int size, Ice::Long& newOf lines.push_back(line); } +// cerr << "finished read " << newOffset << " " << is.eof() << " " << lines.size()<< endl; if(is.bad()) { throw FileNotAvailableException("unrecoverable error occured while reading file `" + file + "'"); diff --git a/cpp/src/IceGrid/PlatformInfo.cpp b/cpp/src/IceGrid/PlatformInfo.cpp index 67bc0a95db5..e9245b89527 100644 --- a/cpp/src/IceGrid/PlatformInfo.cpp +++ b/cpp/src/IceGrid/PlatformInfo.cpp @@ -258,21 +258,22 @@ PlatformInfo::PlatformInfo(const string& prefix, } } - _dataDir = properties->getProperty(prefix + ".Data"); - if(!IcePatch2::isAbsolute(_dataDir)) - { #ifdef _WIN32 - char cwd[_MAX_PATH]; - if(_getcwd(cwd, _MAX_PATH) == NULL) + char cwd[_MAX_PATH]; + if(_getcwd(cwd, _MAX_PATH) == NULL) #else char cwd[PATH_MAX]; - if(getcwd(cwd, PATH_MAX) == NULL) + if(getcwd(cwd, PATH_MAX) == NULL) #endif - { - throw "cannot get the current directory:\n" + IcePatch2::lastError(); - } - - _dataDir = string(cwd) + '/' + _dataDir; + { + throw "cannot get the current directory:\n" + IcePatch2::lastError(); + } + _cwd = string(cwd); + + _dataDir = properties->getProperty(prefix + ".Data"); + if(!IcePatch2::isAbsolute(_dataDir)) + { + _dataDir = _cwd + '/' + _dataDir; } if(_dataDir[_dataDir.length() - 1] == '/') { @@ -421,6 +422,12 @@ PlatformInfo::getDataDir() const return _dataDir; } +std::string +PlatformInfo::getCwd() const +{ + return _cwd; +} + #ifdef _WIN32 void PlatformInfo::initQuery() diff --git a/cpp/src/IceGrid/PlatformInfo.h b/cpp/src/IceGrid/PlatformInfo.h index e86d1711fa1..0cf49549de9 100644 --- a/cpp/src/IceGrid/PlatformInfo.h +++ b/cpp/src/IceGrid/PlatformInfo.h @@ -43,6 +43,7 @@ public: LoadInfo getLoadInfo(); std::string getHostname() const; std::string getDataDir() const; + std::string getCwd() const; private: @@ -59,6 +60,7 @@ private: std::string _machine; int _nProcessors; std::string _dataDir; + std::string _cwd; std::string _endpoints; #if defined(_WIN32) diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp index 27c9352ac37..e767ca6bc58 100644 --- a/cpp/src/IceGrid/ServerI.cpp +++ b/cpp/src/IceGrid/ServerI.cpp @@ -1972,10 +1972,22 @@ ServerI::updateImpl(const InternalServerDescriptorPtr& descriptor) } // - // Make sure the log paths are sorted. + // Simplify the log paths and transform relative paths into + // absolute paths, also make sure the logs are sorted. // - _logs = _desc->logs; - sort(_desc->logs.begin(), _desc->logs.begin()); + for(Ice::StringSeq::const_iterator p = _desc->logs.begin(); p != _desc->logs.end(); ++p) + { + string path = IcePatch2::simplify(*p); + if(IcePatch2::isAbsolute(path)) + { + _logs.push_back(path); + } + else + { + _logs.push_back(_node->getPlatformInfo().getCwd() + '/' + path); + } + } + sort(_logs.begin(), _logs.begin()); // // Copy the descriptor properties. We shouldn't modify the @@ -2648,7 +2660,11 @@ ServerI::getFilePath(const string& filename) const else if(!filename.empty() && filename[0] == '#') { string path = IcePatch2::simplify(filename.substr(1)); - if(find(_desc->logs.begin(), _desc->logs.end(), path) == _desc->logs.end()) + if(!IcePatch2::isAbsolute(path)) + { + path = _node->getPlatformInfo().getCwd() + "/" + path; + } + if(find(_logs.begin(), _logs.end(), path) == _logs.end()) { throw FileNotAvailableException("unknown log file `" + path + "'"); } |