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

Method parseVolumePath

src/examples/test_csi_plugin.cpp:1291–1333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1289
1290
1291Try<VolumeInfo> TestCSIPlugin::parseVolumePath(const string& dir)
1292{
1293 // TODO(chhsiao): Consider using `<regex>`, which requires GCC 4.9+.
1294
1295 // Make sure there's a separator at the end of the prefix so that we
1296 // don't accidentally slice off part of a directory.
1297 const string prefix = path::join(workDir, "");
1298
1299 if (!strings::startsWith(dir, prefix)) {
1300 return Error(
1301 "Directory '" + dir + "' does not fall under work directory '" +
1302 prefix + "'");
1303 }
1304
1305 const string basename = Path(dir).basename();
1306
1307 vector<string> tokens = strings::tokenize(basename, "-", 2);
1308 if (tokens.size() != 2) {
1309 return Error("Cannot find delimiter '-' in '" + basename + "'");
1310 }
1311
1312 Try<Bytes> capacity = Bytes::parse(tokens[0]);
1313 if (capacity.isError()) {
1314 return Error(
1315 "Failed to parse capacity from '" + tokens[0] +
1316 "': " + capacity.error());
1317 }
1318
1319 Try<string> name = http::decode(tokens[1]);
1320 if (name.isError()) {
1321 return Error(
1322 "Failed to decode volume name from '" + tokens[1] +
1323 "': " + name.error());
1324 }
1325
1326 CHECK_EQ(dir, getVolumePath(capacity.get(), name.get()))
1327 << "Cannot reconstruct volume path '" << dir << "' from volume name '"
1328 << name.get() << "' and capacity " << capacity.get();
1329
1330 const string volumeId = volumeIdPath ? dir : name.get();
1331
1332 return VolumeInfo{capacity.get(), volumeId, dir, volumeMetadata};
1333}
1334
1335
1336Option<VolumeInfo> TestCSIPlugin::findVolumeByName(const string& name)

Callers

nothing calls this directly

Calls 13

startsWithFunction · 0.85
PathClass · 0.85
tokenizeFunction · 0.85
getVolumePathFunction · 0.85
errorMethod · 0.65
joinFunction · 0.50
ErrorFunction · 0.50
parseFunction · 0.50
decodeFunction · 0.50
basenameMethod · 0.45
sizeMethod · 0.45
isErrorMethod · 0.45

Tested by

no test coverage detected