diff options
author | Benoit Foucher <benoit@zeroc.com> | 2002-07-23 20:15:40 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2002-07-23 20:15:40 +0000 |
commit | a53237cad044fb5e7cccdb797e908d11aca94e25 (patch) | |
tree | 93a93078f5fc8fd0306b1b9d674e12393aac274c /cpp/src | |
parent | Added persistence and fixed numerous bugs. (diff) | |
download | ice-a53237cad044fb5e7cccdb797e908d11aca94e25.tar.bz2 ice-a53237cad044fb5e7cccdb797e908d11aca94e25.tar.xz ice-a53237cad044fb5e7cccdb797e908d11aca94e25.zip |
Remove database files in the service database directory.
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IcePack/ComponentDeployer.cpp | 67 | ||||
-rw-r--r-- | cpp/src/IcePack/ComponentDeployer.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePack/ServiceDeployer.cpp | 26 |
3 files changed, 84 insertions, 11 deletions
diff --git a/cpp/src/IcePack/ComponentDeployer.cpp b/cpp/src/IcePack/ComponentDeployer.cpp index b267db0f204..0716c96d709 100644 --- a/cpp/src/IcePack/ComponentDeployer.cpp +++ b/cpp/src/IcePack/ComponentDeployer.cpp @@ -22,6 +22,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> +#include <dirent.h> #include <stack> #include <iterator> @@ -48,12 +49,17 @@ toString(const XMLCh* ch) // // Create a directory. // +// TODO: IcePatch implements portable version of filesystem primitives +// in the Util.cpp file. We should move these primitives in IceUtil +// and use them here. +// class CreateDirectory : public Task { public: - CreateDirectory(const string& name) - : _name(name) + CreateDirectory(const string& name, bool force) : + _name(name), + _force(force) { } @@ -73,6 +79,58 @@ public: virtual void undeploy() { + if(_force) + { + // + // Only remove files inside the directory, don't remove + // directories (deployed directory should only be created + // through this task so other directories should be + // removed by another task). + // + struct dirent **namelist; + int n = ::scandir(_name.c_str(), &namelist, 0, alphasort); + if(n < 0) + { + Ice::SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + + Ice::StringSeq entries; + entries.reserve(n); + for(int i = 0; i < n; ++i) + { + string name = namelist[i]->d_name; + free(namelist[i]); + entries.push_back(_name + "/" + name); + } + free(namelist); + + for(Ice::StringSeq::iterator p = entries.begin(); p != entries.end(); ++p) + { + struct stat buf; + + if(::stat(p->c_str(), &buf) != 0) + { + if(errno != ENOENT) + { + Ice::SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + } + else if(S_ISREG(buf.st_mode)) + { + if(unlink(p->c_str()) != 0) + { + Ice::SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + } + } + } + if(rmdir(_name.c_str()) != 0) { cerr << "Can't remove directory: " << _name << endl; @@ -86,6 +144,7 @@ public: private: string _name; + bool _force; }; // @@ -429,10 +488,10 @@ IcePack::ComponentDeployer::undeploy() } void -IcePack::ComponentDeployer::createDirectory(const string& name) +IcePack::ComponentDeployer::createDirectory(const string& name, bool force) { string path = _variables["datadir"] + (name.empty() || name[0] == '/' ? name : "/" + name); - _tasks.push_back(new CreateDirectory(path)); + _tasks.push_back(new CreateDirectory(path, force)); } void diff --git a/cpp/src/IcePack/ComponentDeployer.h b/cpp/src/IcePack/ComponentDeployer.h index 21e1ea20321..9f45391e07f 100644 --- a/cpp/src/IcePack/ComponentDeployer.h +++ b/cpp/src/IcePack/ComponentDeployer.h @@ -98,7 +98,7 @@ public: void parse(const std::string&, ComponentDeployHandler&); std::string substitute(const std::string&) const; - void createDirectory(const std::string&); + void createDirectory(const std::string&, bool = false); void createConfigFile(const std::string&); void addProperty(const std::string&, const std::string&); void addOffer(const std::string&, const std::string&, const std::string&); diff --git a/cpp/src/IcePack/ServiceDeployer.cpp b/cpp/src/IcePack/ServiceDeployer.cpp index 38ac5917678..0204f89aa03 100644 --- a/cpp/src/IcePack/ServiceDeployer.cpp +++ b/cpp/src/IcePack/ServiceDeployer.cpp @@ -63,7 +63,7 @@ IcePack::ServiceDeployHandler::startElement(const XMLCh *const name, AttributeLi else if(kind == "freeze") { _deployer.setKind(ServiceDeployer::ServiceKindFreeze); - _deployer.setDBEnv(getAttributeValueWithDefault(attrs, "dbenv", "${name}")); + _deployer.setDBEnv(getAttributeValueWithDefault(attrs, "dbenv", "")); } _deployer.createConfigFile("/config/config_" + _deployer.substitute("${name}")); @@ -123,8 +123,6 @@ IcePack::ServiceDeployer::setEntryPoint(const string& entry) void IcePack::ServiceDeployer::setDBEnv(const string& dir) { - assert(!dir.empty()); - if(_kind != ServiceKindFreeze) { cerr << "Database environment is only allowed for Freeze services." << endl; @@ -132,8 +130,24 @@ IcePack::ServiceDeployer::setDBEnv(const string& dir) return; } - createDirectory("/dbs" + (dir[0] == '/' ? dir : "/" + dir)); - addProperty("IceBox.DBEnvName." + _variables["name"], - _variables["datadir"] + "/dbs" + (dir[0] == '/' ? dir : "/" + dir)); + string path; + + if(dir.empty()) + { + // + // Provides database environment directory only if the + // database environment attribute is not specified. If it's + // specified, it's most likely because we share database + // environments and then it's the responsabilility of the user + // to manage the database environment directory. + // + createDirectory("/dbs/" + _variables["name"], true); + path = _variables["datadir"] + "/dbs/" + _variables["name"]; + } + else + { + path = dir[0] == '/' ? dir : _variables["basedir"] + "/" + dir; + } + _serverDeployer.addProperty("IceBox.DBEnvName." + _variables["name"], path); } |