| 229 | } |
| 230 | |
| 231 | static bool uploadS3(const char *urlWithOptions, const char *fileToUpload) { |
| 232 | if (!urlWithOptions) { |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | size_t data_len = BUF_SIZE; |
| 237 | char data_buf[BUF_SIZE]; |
| 238 | size_t read_len = 0; |
| 239 | bool ret = true; |
| 240 | |
| 241 | thread_setup(); |
| 242 | |
| 243 | GPWriter *writer = writer_init(urlWithOptions); |
| 244 | if (!writer) { |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | FILE *fd = fopen(fileToUpload, "r"); |
| 249 | if (fd == NULL) { |
| 250 | fprintf(stderr, "File does not exist\n"); |
| 251 | ret = false; |
| 252 | } else { |
| 253 | do { |
| 254 | read_len = fread(data_buf, 1, data_len, fd); |
| 255 | |
| 256 | if (read_len == 0) { |
| 257 | break; |
| 258 | } |
| 259 | |
| 260 | if (!writer_transfer_data(writer, data_buf, (int)read_len)) { |
| 261 | fprintf(stderr, "Failed to write data to Amazon S3\n"); |
| 262 | ret = false; |
| 263 | break; |
| 264 | } |
| 265 | } while (read_len == data_len && !S3QueryIsAbortInProgress()); |
| 266 | |
| 267 | if (ferror(fd)) { |
| 268 | ret = false; |
| 269 | } |
| 270 | |
| 271 | fclose(fd); |
| 272 | } |
| 273 | |
| 274 | writer_cleanup(&writer); |
| 275 | |
| 276 | thread_cleanup(); |
| 277 | |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | int main(int argc, char *argv[]) { |
| 282 | bool ret = true; |
no test coverage detected