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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// **********************************************************************
//
// Copyright (c) 2002
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <IcePatch/NodeI.h>
#include <dirent.h>
using namespace std;
using namespace Ice;
using namespace IcePatch;
IcePatch::NodeI::NodeI(const ObjectAdapterPtr& adapter) :
_adapter(adapter)
{
}
string
IcePatch::NodeI::normalizePath(const string& path)
{
string result = path;
string::size_type pos;
for (pos = 0; pos < result.size(); ++pos)
{
if (result[pos] == '\\')
{
result[pos] = '/';
}
}
pos = 0;
while ((pos = result.find("//", pos)) != string::npos)
{
result.erase(pos, 1);
}
pos = 0;
while ((pos = result.find("/./", pos)) != string::npos)
{
result.erase(pos, 2);
}
return result;
}
IcePatch::DirectoryI::DirectoryI(const ObjectAdapterPtr& adapter) :
NodeI(adapter)
{
}
NodeDescPtr
IcePatch::DirectoryI::describe(const Ice::Current& current)
{
DirectoryDescPtr desc = new DirectoryDesc;
desc->directory = DirectoryPrx::uncheckedCast(_adapter->createProxy(current.identity));
return desc;
}
NodeDescSeq
IcePatch::DirectoryI::getContents(const Ice::Current& current)
{
string path = normalizePath(current.identity.name);
struct dirent **namelist;
int n = scandir(path.c_str(), &namelist, 0, alphasort);
if (n < 0)
{
NodeAccessException ex;
ex.reason = "cannot read directory `" + path + "':" + strerror(errno);
throw ex;
}
NodeDescSeq result;
result.reserve(n - 2);
int i;
try
{
Identity identity;
identity.category = "IcePatch";
for (i = 0; i < n; ++i)
{
string name = namelist[i]->d_name;
if (name != ".." && name != ".")
{
identity.name = path + '/' + name;
NodePrx node = NodePrx::uncheckedCast(_adapter->createProxy(identity));
try
{
result.push_back(node->describe());
}
catch (const ObjectNotExistException&)
{
//
// Ignore. This can for example happen if the node
// locator cannot call stat() on the file.
//
}
}
}
for (i = 0; i < n; ++i)
{
free(namelist[i]);
}
free(namelist);
}
catch (...)
{
for (i = 0; i < n; ++i)
{
free(namelist[i]);
}
free(namelist);
throw;
}
return result;
}
IcePatch::FileI::FileI(const ObjectAdapterPtr& adapter) :
NodeI(adapter)
{
}
NodeDescPtr
IcePatch::FileI::describe(const Ice::Current& current)
{
FileDescPtr desc = new FileDesc;
desc->file = FilePrx::uncheckedCast(_adapter->createProxy(current.identity));
return desc;
}
ByteSeq
IcePatch::FileI::getBytes(Int startPos, Int howMuch, const Ice::Current& current)
{
string path = normalizePath(current.identity.name);
return ByteSeq();
}
|