1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// $Id$
#include "ACEXML/compass/ComponentInstallation.h"
#include "ACEXML/common/ZipCharStream.h"
using namespace Deployment;
static const empty_string[] = {0};
ComponentInstallation::ComponentInstallation()
: packages_()
{}
ComponentInstallation::~ComponentInstallation()
{
}
void
ComponentInstallation::install (const UUID& implUUID,
const Location& component_loc)
ACE_THROW_SPEC ((InvalidLocation,InstallationFailure))
{
if (implUUID == empty_string)
{
ACE_ERROR ((LM_ERROR, "Implementation id is an Empty string\n"));
ACE_THROW (InstallationFailure());
}
else if (component_loc == empty_string)
{
ACE_ERROR ((LM_ERROR, "Component Location is an Empty string\n"));
ACE_THROW (InvalidLocation());
}
ACEXML_StreamFactory factory;
ACEXML_CharStream* stream = factory.create_stream (component_loc.c_str());
if (!stream)
{
ACE_ERROR ((LM_ERROR, "Unable to create a stream for the Component"
"location %s\n", component_loc.c_str()));
ACE_THROW (InstallationFailure());
}
ACEXML_Char temp[MAXNAMLEN + 1] = "acefileXXXXXX";
if (mkdtemp (temp) == 0)
{
ACE_ERROR ((LM_ERROR, "Unable to create safe temporary directory\n"));
ACE_THROW (InstallationFailure());
}
ACEXML_Char* file = ACE_OS::strrchr (component_loc.c_str(), '/');
if (!file)
file = component_loc.c_str();
else
file += 1;
ACEXML_String dsoname = temp + '/' + file;
ACE_HANDLE dso = ACE_OS::open (dsoname.c_str(),
O_WRONLY| O_CREAT|O_EXCL, S_IRWXU);
if (dso == 0)
{
ACE_ERROR ((LM_ERROR, "Unable to unpack the implementation %s : %m\n",
dsoname.c_str()));
ACE_THROW (InstallationFailure());
}
ACEXML_Char buf[65535];
int bytes = 0;
while ((bytes = stream.read (buf, sizeof(buf))) > 0)
{
if (ACE_OS::write (dso, buf, bytes) != bytes)
{
ACE_ERROR ((LM_ERROR, "Unable to unpack the implementation %s: %m\n",
dsoname.c_str()));
ACE_THROW (InstallationFailure());
}
}
ACE_OS::close (dso);
if (this->packages_->bind (implUUID, dsoname) != 0)
{
ACE_ERROR ((LM_ERROR, "Component %s already installed\n",
implUUID.c_str()));
ACE_THROW (InstallationFailure());
}
}
void
ComponentInstallation::replace (const UUID& implUUID,
const Location& component_loc)
ACE_THROW_SPEC ((InvalidLocation,InstallationFailure))
{
if (implUUID == empty_string)
ACE_THROW (InstallationFailure());
else if (component_loc == empty_string)
ACE_THROW (InvalidLocation());
else
{
if (this->packages_->unbind (implUUID) != 0)
ACE_THROW (InstallationFailure());
this->install (implUUID, component_loc);
}
}
void
ComponentInstallation::remove (const UUID& implUUID)
ACE_THROW_SPEC ((UnknownImplId, RemoveFailure));
{
if (implUUID == empty_string)
ACE_THROW (UnknownImplId());
else if (this->packages_->unbind (implUUID) != 0)
ACE_THROW (RemoveFailure());
}
|