| 46 | |
| 47 | |
| 48 | Try<Nothing> Rootfs::add(const string& path) |
| 49 | { |
| 50 | Option<string> source = None(); |
| 51 | |
| 52 | // If we are copying a symlink, follow it and copy the |
| 53 | // target instead. While this is a little inefficient on |
| 54 | // disk space, it avoids complexity in dealing with chains |
| 55 | // of symlinks and symlinks in intermediate path components. |
| 56 | if (os::stat::islink(path)) { |
| 57 | Result<string> target = os::realpath(path); |
| 58 | if (target.isNone()) { |
| 59 | return Error("Failed to resolve '" + path + "'"); |
| 60 | } |
| 61 | |
| 62 | if (target.isError()) { |
| 63 | return Error("Failed to resolve '" + path + "': " + target.error()); |
| 64 | } |
| 65 | |
| 66 | source = target.get(); |
| 67 | } |
| 68 | |
| 69 | Try<Nothing> copy = copyPath(source.isSome() ? source.get() : path, path); |
| 70 | if (copy.isError()) { |
| 71 | return Error("Failed to copy '" + path + "' to rootfs: " + copy.error()); |
| 72 | } |
| 73 | |
| 74 | return Nothing(); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | Try<Nothing> Rootfs::copyPath(const string& source, const string& destination) |
no test coverage detected