| 75 | |
| 76 | |
| 77 | Future<Nothing> CopyFetcherPlugin::fetch( |
| 78 | const URI& uri, |
| 79 | const string& directory, |
| 80 | const Option<string>& data, |
| 81 | const Option<string>& outputFileName) const |
| 82 | { |
| 83 | // TODO(jojy): Validate the given URI. |
| 84 | |
| 85 | if (!uri.has_path()) { |
| 86 | return Failure("URI path is not specified"); |
| 87 | } |
| 88 | |
| 89 | // TODO(jojy): Verify that the path is a file. |
| 90 | |
| 91 | Try<Nothing> mkdir = os::mkdir(directory); |
| 92 | if (mkdir.isError()) { |
| 93 | return Failure( |
| 94 | "Failed to create directory '" + |
| 95 | directory + "': " + mkdir.error()); |
| 96 | } |
| 97 | |
| 98 | VLOG(1) << "Copying '" << uri.path() << "' to '" << directory << "'"; |
| 99 | |
| 100 | #ifndef __WINDOWS__ |
| 101 | const char* copyCommand = "cp"; |
| 102 | const vector<string> argv = {"cp", "-a", uri.path(), directory}; |
| 103 | #else // __WINDOWS__ |
| 104 | const char* copyCommand = os::Shell::name; |
| 105 | const vector<string> argv = |
| 106 | {os::Shell::arg0, os::Shell::arg1, "copy", "/Y", uri.path(), directory}; |
| 107 | #endif // __WINDOWS__ |
| 108 | |
| 109 | Try<Subprocess> s = subprocess( |
| 110 | copyCommand, |
| 111 | argv, |
| 112 | Subprocess::PATH(os::DEV_NULL), |
| 113 | Subprocess::PIPE(), |
| 114 | Subprocess::PIPE()); |
| 115 | |
| 116 | if (s.isError()) { |
| 117 | return Failure("Failed to exec the copy subprocess: " + s.error()); |
| 118 | } |
| 119 | |
| 120 | return await( |
| 121 | s->status(), |
| 122 | io::read(s->out().get()), |
| 123 | io::read(s->err().get())) |
| 124 | .then([](const tuple< |
| 125 | Future<Option<int>>, |
| 126 | Future<string>, |
| 127 | Future<string>>& t) -> Future<Nothing> { |
| 128 | const Future<Option<int>>& status = std::get<0>(t); |
| 129 | if (!status.isReady()) { |
| 130 | return Failure( |
| 131 | "Failed to get the exit status of the copy subprocess: " + |
| 132 | (status.isFailed() ? status.failure() : "discarded")); |
| 133 | } |
| 134 |
nothing calls this directly
no test coverage detected