summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IcePatch/FileLocator.cpp9
-rw-r--r--cpp/src/IcePatch/FileLocator.h1
-rw-r--r--cpp/src/IcePatch/IcePatchI.cpp27
-rw-r--r--cpp/src/IcePatch/IcePatchI.h1
-rw-r--r--cpp/src/IcePatch/Server.cpp3
-rw-r--r--cpp/src/IcePatch/Util.cpp20
6 files changed, 39 insertions, 22 deletions
diff --git a/cpp/src/IcePatch/FileLocator.cpp b/cpp/src/IcePatch/FileLocator.cpp
index 4fca6e31b01..5c36d962e00 100644
--- a/cpp/src/IcePatch/FileLocator.cpp
+++ b/cpp/src/IcePatch/FileLocator.cpp
@@ -25,8 +25,13 @@ IcePatch::FileLocator::FileLocator(const Ice::ObjectAdapterPtr& adapter) :
_regular(new RegularI(adapter)),
_logger(adapter->getCommunicator()->getLogger()),
_fileTraceLogger(adapter->getCommunicator()->getProperties()->getPropertyAsInt("IcePatch.Trace.Files") > 0 ?
- _logger : LoggerPtr())
+ _logger : LoggerPtr()),
+ _dir(adapter->getCommunicator()->getProperties()->getProperty("IcePatch.Directory"))
{
+ if(!_dir.empty() && _dir[_dir.length() - 1] != '/')
+ {
+ const_cast<string&>(_dir) += '/';
+ }
}
ObjectPtr
@@ -71,7 +76,7 @@ IcePatch::FileLocator::locate(const Current& current, LocalObjectPtr&)
FileInfo info;
try
{
- info = getFileInfo(path, true, _fileTraceLogger);
+ info = getFileInfo(_dir + path, true, _fileTraceLogger);
}
catch(const FileAccessException& ex)
{
diff --git a/cpp/src/IcePatch/FileLocator.h b/cpp/src/IcePatch/FileLocator.h
index 76888dba293..ce302cbc6cc 100644
--- a/cpp/src/IcePatch/FileLocator.h
+++ b/cpp/src/IcePatch/FileLocator.h
@@ -40,6 +40,7 @@ private:
const Ice::LoggerPtr _logger;
const Ice::LoggerPtr _fileTraceLogger;
+ const std::string _dir;
};
}
diff --git a/cpp/src/IcePatch/IcePatchI.cpp b/cpp/src/IcePatch/IcePatchI.cpp
index 5d73fc78621..54a2fc768a6 100644
--- a/cpp/src/IcePatch/IcePatchI.cpp
+++ b/cpp/src/IcePatch/IcePatchI.cpp
@@ -26,8 +26,13 @@ IcePatch::FileI::FileI(const ObjectAdapterPtr& adapter) :
_fileTraceLogger(adapter->getCommunicator()->getProperties()->getPropertyAsInt("IcePatch.Trace.Files") > 0 ?
adapter->getCommunicator()->getLogger() : LoggerPtr()),
_busyTimeout(IceUtil::Time::seconds(adapter->getCommunicator()->getProperties()->
- getPropertyAsIntWithDefault("IcePatch.BusyTimeout", 10)))
+ getPropertyAsIntWithDefault("IcePatch.BusyTimeout", 10))),
+ _dir(adapter->getCommunicator()->getProperties()->getProperty("IcePatch.Directory"))
{
+ if(!_dir.empty() && _dir[_dir.length() - 1] != '/')
+ {
+ const_cast<string&>(_dir) += '/';
+ }
}
ByteSeq
@@ -38,10 +43,12 @@ IcePatch::FileI::readMD5(const Current& current) const
if(path == ".")
{
//
- // We cannot create an MD5 file for the current directory.
+ // We do not create a MD5 file for the top-level directory.
//
return ByteSeq();
}
+
+ path = _dir + path;
IceUtil::RWRecMutex::TryRLock sync(globalMutex, _busyTimeout);
if(!sync.acquired())
@@ -120,8 +127,9 @@ IcePatch::DirectoryI::getContents(const Current& current) const
}
bool syncUpgraded = false;
- string path = identityToPath(current.id);
- StringSeq paths = readDirectory(path);
+ string prependPath = identityToPath(current.id);
+ string realPath = _dir + prependPath;
+ StringSeq paths = readDirectory(realPath, prependPath);
filteredPaths.reserve(paths.size() / 3);
for(StringSeq::const_iterator p = paths.begin(); p != paths.end(); ++p)
{
@@ -139,12 +147,12 @@ IcePatch::DirectoryI::getContents(const Current& current) const
throw BusyException();
}
}
- StringSeq paths2 = readDirectory(path);
+ StringSeq paths2 = readDirectory(realPath, prependPath);
pair<StringSeq::iterator, StringSeq::iterator> r2 =
equal_range(paths2.begin(), paths2.end(), removeSuffix(*p));
if(r2.first == r2.second)
{
- removeRecursive(*p, _fileTraceLogger);
+ removeRecursive(_dir + *p, _fileTraceLogger);
}
}
}
@@ -155,7 +163,6 @@ IcePatch::DirectoryI::getContents(const Current& current) const
}
}
-
//
// Call describe() outside the thread synchronization, to avoid
// deadlocks.
@@ -205,7 +212,7 @@ IcePatch::RegularI::getBZ2Size(const Current& current) const
throw BusyException();
}
- string path = identityToPath(current.id);
+ string path = _dir + identityToPath(current.id);
FileInfo info = getFileInfo(path, true, _fileTraceLogger);
assert(info.type == FileTypeRegular);
@@ -250,7 +257,7 @@ IcePatch::RegularI::getBZ2(Int pos, Int num, const Current& current) const
throw BusyException();
}
- string path = identityToPath(current.id);
+ string path = _dir + identityToPath(current.id);
FileInfo info = getFileInfo(path, true, _fileTraceLogger);
assert(info.type == FileTypeRegular);
@@ -295,7 +302,7 @@ IcePatch::RegularI::getBZ2MD5(Int size, const Current& current) const
throw BusyException();
}
- string path = identityToPath(current.id);
+ string path = _dir + identityToPath(current.id);
FileInfo info = getFileInfo(path, true, _fileTraceLogger);
assert(info.type == FileTypeRegular);
diff --git a/cpp/src/IcePatch/IcePatchI.h b/cpp/src/IcePatch/IcePatchI.h
index 2868b62fab0..0dc50a1445d 100644
--- a/cpp/src/IcePatch/IcePatchI.h
+++ b/cpp/src/IcePatch/IcePatchI.h
@@ -35,6 +35,7 @@ protected:
const Ice::ObjectAdapterPtr _adapter;
const Ice::LoggerPtr _fileTraceLogger;
const IceUtil::Time _busyTimeout;
+ const std::string _dir;
};
class DirectoryI : virtual public Directory,
diff --git a/cpp/src/IcePatch/Server.cpp b/cpp/src/IcePatch/Server.cpp
index faabc4e4ad8..e8140c06b55 100644
--- a/cpp/src/IcePatch/Server.cpp
+++ b/cpp/src/IcePatch/Server.cpp
@@ -16,9 +16,6 @@
#include <Ice/Application.h>
#include <IcePatch/FileLocator.h>
#include <IcePatch/IcePatchI.h>
-#ifdef _WIN32
-# include <direct.h>
-#endif
using namespace std;
using namespace Ice;
diff --git a/cpp/src/IcePatch/Util.cpp b/cpp/src/IcePatch/Util.cpp
index 859eee8a37b..79950e4a19d 100644
--- a/cpp/src/IcePatch/Util.cpp
+++ b/cpp/src/IcePatch/Util.cpp
@@ -351,14 +351,20 @@ IcePatch::removeRecursive(const string& path, const Ice::LoggerPtr& logger)
StringSeq
IcePatch::readDirectory(const string& path)
{
+ return readDirectory(path, path);
+}
+
+StringSeq
+IcePatch::readDirectory(const string& realPath, const string& prependPath)
+{
#ifdef _WIN32
struct _finddata_t data;
- long h = _findfirst((path + "/*").c_str(), &data);
+ long h = _findfirst((realPath + "/*").c_str(), &data);
if(h == -1)
{
FileAccessException ex;
- ex.reason = "cannot read directory `" + path + "': " + strerror(errno);
+ ex.reason = "cannot read directory `" + realPath + "': " + strerror(errno);
throw ex;
}
@@ -371,7 +377,7 @@ IcePatch::readDirectory(const string& path)
if(name != ".." && name != ".")
{
- result.push_back(normalizePath(path + '/' + name));
+ result.push_back(normalizePath(prependPath + '/' + name));
}
if(_findnext(h, &data) == -1)
@@ -382,7 +388,7 @@ IcePatch::readDirectory(const string& path)
}
FileAccessException ex;
- ex.reason = "cannot read directory `" + path + "': " + strerror(errno);
+ ex.reason = "cannot read directory `" + realPath + "': " + strerror(errno);
_findclose(h);
throw ex;
}
@@ -397,11 +403,11 @@ IcePatch::readDirectory(const string& path)
#else
struct dirent **namelist;
- int n = ::scandir(path.c_str(), &namelist, 0, alphasort);
+ int n = ::scandir(realPath.c_str(), &namelist, 0, alphasort);
if(n < 0)
{
FileAccessException ex;
- ex.reason = "cannot read directory `" + path + "': " + strerror(errno);
+ ex.reason = "cannot read directory `" + realPath + "': " + strerror(errno);
throw ex;
}
@@ -417,7 +423,7 @@ IcePatch::readDirectory(const string& path)
if(name != ".." && name != ".")
{
- result.push_back(normalizePath(path + '/' + name));
+ result.push_back(normalizePath(prependPath + '/' + name));
}
}