MCPcopy Create free account
hub / github.com/apache/mesos / getEndpointSocketPath

Function getEndpointSocketPath

src/csi/paths.cpp:143–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141
142
143Try<string> getEndpointSocketPath(
144 const string& rootDir,
145 const string& type,
146 const string& name,
147 const ContainerID& containerId)
148{
149#ifdef __WINDOWS__
150 return Error("CSI is not supported on Windows");
151#else
152 const string symlinkPath =
153 getEndpointDirSymlinkPath(rootDir, type, name, containerId);
154
155 Try<Nothing> mkdir = os::mkdir(Path(symlinkPath).dirname());
156 if(mkdir.isError()) {
157 return Error(
158 "Failed to create directory '" + Path(symlinkPath).dirname() + "': " +
159 mkdir.error());
160 }
161
162 Result<string> endpointDir = os::realpath(symlinkPath);
163 if (endpointDir.isSome()) {
164 return path::join(endpointDir.get(), ENDPOINT_SOCKET_FILE);
165 }
166
167 if (os::exists(symlinkPath)) {
168 Try<Nothing> rm = os::rm(symlinkPath);
169 if (rm.isError()) {
170 return Error(
171 "Failed to remove endpoint symlink '" + symlinkPath + "': " +
172 rm.error());
173 }
174 }
175
176 Try<string> mkdtemp = os::mkdtemp(path::join(os::temp(), ENDPOINT_DIR));
177 if (mkdtemp.isError()) {
178 return Error(
179 "Failed to create endpoint directory in '" + os::temp() + "': " +
180 mkdtemp.error());
181 }
182
183 Try<Nothing> symlink = fs::symlink(mkdtemp.get(), symlinkPath);
184 if (symlink.isError()) {
185 return Error(
186 "Failed to symlink directory '" + mkdtemp.get() + "' to '" +
187 symlinkPath + "': " + symlink.error());
188 }
189
190 const string socketPath = path::join(mkdtemp.get(), ENDPOINT_SOCKET_FILE);
191
192 // Check if the socket path is too long.
193 Try<process::network::unix::Address> address =
194 process::network::unix::Address::create(socketPath);
195 if (address.isError()) {
196 return Error(
197 "Failed to create address from '" + socketPath + "': " +
198 address.error());
199 }
200

Callers 1

getEndpointMethod · 0.85

Calls 15

PathClass · 0.85
dirnameMethod · 0.80
errorMethod · 0.65
ErrorFunction · 0.50
mkdirFunction · 0.50
realpathFunction · 0.50
joinFunction · 0.50
existsFunction · 0.50
rmFunction · 0.50
mkdtempFunction · 0.50
tempFunction · 0.50

Tested by

no test coverage detected