| 141 | |
| 142 | |
| 143 | Try<string> getEndpointSocketPath( |
| 144 | const string& rootDir, |
| 145 | const string& type, |
| 146 | const string& name, |
| 147 | const ContainerID& containerId) |
| 148 | { |
| 149 | #ifdef __WINDOWS__ |
| 150 | return Error("CSI is not supported on Windows"); |
| 151 | #else |
| 152 | const string symlinkPath = |
| 153 | getEndpointDirSymlinkPath(rootDir, type, name, containerId); |
| 154 | |
| 155 | Try<Nothing> mkdir = os::mkdir(Path(symlinkPath).dirname()); |
| 156 | if(mkdir.isError()) { |
| 157 | return Error( |
| 158 | "Failed to create directory '" + Path(symlinkPath).dirname() + "': " + |
| 159 | mkdir.error()); |
| 160 | } |
| 161 | |
| 162 | Result<string> endpointDir = os::realpath(symlinkPath); |
| 163 | if (endpointDir.isSome()) { |
| 164 | return path::join(endpointDir.get(), ENDPOINT_SOCKET_FILE); |
| 165 | } |
| 166 | |
| 167 | if (os::exists(symlinkPath)) { |
| 168 | Try<Nothing> rm = os::rm(symlinkPath); |
| 169 | if (rm.isError()) { |
| 170 | return Error( |
| 171 | "Failed to remove endpoint symlink '" + symlinkPath + "': " + |
| 172 | rm.error()); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | Try<string> mkdtemp = os::mkdtemp(path::join(os::temp(), ENDPOINT_DIR)); |
| 177 | if (mkdtemp.isError()) { |
| 178 | return Error( |
| 179 | "Failed to create endpoint directory in '" + os::temp() + "': " + |
| 180 | mkdtemp.error()); |
| 181 | } |
| 182 | |
| 183 | Try<Nothing> symlink = fs::symlink(mkdtemp.get(), symlinkPath); |
| 184 | if (symlink.isError()) { |
| 185 | return Error( |
| 186 | "Failed to symlink directory '" + mkdtemp.get() + "' to '" + |
| 187 | symlinkPath + "': " + symlink.error()); |
| 188 | } |
| 189 | |
| 190 | const string socketPath = path::join(mkdtemp.get(), ENDPOINT_SOCKET_FILE); |
| 191 | |
| 192 | // Check if the socket path is too long. |
| 193 | Try<process::network::unix::Address> address = |
| 194 | process::network::unix::Address::create(socketPath); |
| 195 | if (address.isError()) { |
| 196 | return Error( |
| 197 | "Failed to create address from '" + socketPath + "': " + |
| 198 | address.error()); |
| 199 | } |
| 200 |
no test coverage detected