| 95 | } |
| 96 | |
| 97 | Status IGFS::NewWritableFile(const string &file_name, |
| 98 | std::unique_ptr<WritableFile> *result) { |
| 99 | std::unique_ptr<IGFSClient> client = CreateClient(); |
| 100 | string path = TranslateName(file_name); |
| 101 | |
| 102 | CtrlResponse<HandshakeResponse> handshake_response(true); |
| 103 | TF_RETURN_IF_ERROR(client->Handshake(&handshake_response)); |
| 104 | |
| 105 | CtrlResponse<ExistsResponse> exists_response(false); |
| 106 | TF_RETURN_IF_ERROR(client->Exists(&exists_response, path)); |
| 107 | |
| 108 | if (exists_response.res.exists) { |
| 109 | CtrlResponse<DeleteResponse> del_response(false); |
| 110 | TF_RETURN_IF_ERROR(client->Delete(&del_response, path, false)); |
| 111 | } |
| 112 | |
| 113 | CtrlResponse<OpenCreateResponse> open_create_resp(false); |
| 114 | TF_RETURN_IF_ERROR(client->OpenCreate(&open_create_resp, path)); |
| 115 | |
| 116 | int64 resource_id = open_create_resp.res.stream_id; |
| 117 | result->reset(new IGFSWritableFile(path, resource_id, std::move(client))); |
| 118 | |
| 119 | LOG(INFO) << "New writable file completed successfully [file_name=" |
| 120 | << file_name << "]"; |
| 121 | |
| 122 | return Status::OK(); |
| 123 | } |
| 124 | |
| 125 | Status IGFS::NewAppendableFile(const string &file_name, |
| 126 | std::unique_ptr<WritableFile> *result) { |