| 296 | |
| 297 | |
| 298 | Try<string> parseMountPath(const string& mountRootDir, const string& dir) |
| 299 | { |
| 300 | // TODO(chhsiao): Consider using `<regex>`, which requires GCC 4.9+. |
| 301 | |
| 302 | // Make sure there's a separator at the end of the `mountRootDir` so that we |
| 303 | // don't accidentally slice off part of a directory. |
| 304 | const string prefix = path::join(mountRootDir, ""); |
| 305 | |
| 306 | if (!strings::startsWith(dir, prefix)) { |
| 307 | return Error( |
| 308 | "Directory '" + dir + "' does not fall under the mount root directory" |
| 309 | " '" + mountRootDir + "'"); |
| 310 | } |
| 311 | |
| 312 | // Volume ID is percent-encoded to avoid invalid characters in the path. |
| 313 | Try<string> volumeId = http::decode(Path(dir).basename()); |
| 314 | if (volumeId.isError()) { |
| 315 | return Error( |
| 316 | "Could not decode volume ID from string '" + Path(dir).basename() + |
| 317 | "': " + volumeId.error()); |
| 318 | } |
| 319 | |
| 320 | return volumeId.get(); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | string getMountStagingPath( |