| 1289 | |
| 1290 | |
| 1291 | Try<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 | |
| 1336 | Option<VolumeInfo> TestCSIPlugin::findVolumeByName(const string& name) |
nothing calls this directly
no test coverage detected