summaryrefslogtreecommitdiff
path: root/cpp/src/IcePack/ComponentDeployer.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2002-07-23 20:15:40 +0000
committerBenoit Foucher <benoit@zeroc.com>2002-07-23 20:15:40 +0000
commita53237cad044fb5e7cccdb797e908d11aca94e25 (patch)
tree93a93078f5fc8fd0306b1b9d674e12393aac274c /cpp/src/IcePack/ComponentDeployer.cpp
parentAdded persistence and fixed numerous bugs. (diff)
downloadice-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.cpp67
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