1321 while((e = tar_read_entry(tar)) != NULL) { |
1321 while((e = tar_read_entry(tar)) != NULL) { |
1322 char *newpath = util_concat_path(path, e->path); |
1322 char *newpath = util_concat_path(path, e->path); |
1323 if(e->type == TAR_TYPE_FILE) { |
1323 if(e->type == TAR_TYPE_FILE) { |
1324 fprintf(stderr, "put: %s\n", e->path); |
1324 fprintf(stderr, "put: %s\n", e->path); |
1325 DavResource *res = dav_resource_new(sn, newpath); |
1325 DavResource *res = dav_resource_new(sn, newpath); |
1326 dav_set_content(res, tar, (dav_read_func)tar_fread); |
1326 dav_set_content(res, tar, (dav_read_func)tar_fread, (dav_seek_func)tar_seek); |
1327 dav_set_content_length(res, (size_t)e->size); |
1327 dav_set_content_length(res, (size_t)e->size); |
1328 |
1328 |
1329 if(dav_store(res)) { |
1329 if(dav_store(res)) { |
1330 print_resource_error(sn, res->path); |
1330 print_resource_error(sn, res->path); |
1331 fprintf(stderr, "Cannot upload file.\n"); |
1331 fprintf(stderr, "Cannot upload file.\n"); |
1362 } |
1362 } |
1363 |
1363 |
1364 return ret; |
1364 return ret; |
1365 } |
1365 } |
1366 |
1366 |
|
1367 static int file_seek(FILE *f, curl_off_t offset, int origin) { |
|
1368 int ret = fseek(f, offset, origin); |
|
1369 return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK; |
|
1370 } |
|
1371 |
1367 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { |
1372 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { |
1368 DavResource *res = dav_query(sn, "select - from %s", path); |
1373 DavResource *res = dav_query(sn, "select - from %s", path); |
1369 |
1374 |
1370 if(!res) { |
1375 if(!res) { |
1371 if(sn->error == DAV_NOT_FOUND) { |
1376 if(sn->error == DAV_NOT_FOUND) { |
1396 int ret = put_file(repo, a, sn, res->path, NULL, in, len); |
1401 int ret = put_file(repo, a, sn, res->path, NULL, in, len); |
1397 // TODO: free res |
1402 // TODO: free res |
1398 return ret; |
1403 return ret; |
1399 } |
1404 } |
1400 |
1405 |
1401 dav_set_content(res, in, (dav_read_func)fread); |
1406 dav_set_content(res, in, (dav_read_func)fread, (dav_seek_func)file_seek); |
1402 if(len > 0 && len < 0x7d000000) { |
1407 if(len > 0 && len < 0x7d000000) { |
1403 dav_set_content_length(res, (size_t)len); |
1408 dav_set_content_length(res, (size_t)len); |
1404 } |
1409 } |
1405 |
1410 |
1406 if(dav_store(res)) { |
1411 if(dav_store(res)) { |