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/IcePack/ComponentDeployer.cpp | |
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/IcePack/ComponentDeployer.cpp')
-rw-r--r-- | cpp/src/IcePack/ComponentDeployer.cpp | 67 |
1 files changed, 63 insertions, 4 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 |