1135 while((e = tar_read_entry(tar)) != NULL) { |
1135 while((e = tar_read_entry(tar)) != NULL) { |
1136 char *newpath = util_concat_path(path, e->path); |
1136 char *newpath = util_concat_path(path, e->path); |
1137 if(e->type == TAR_TYPE_FILE) { |
1137 if(e->type == TAR_TYPE_FILE) { |
1138 fprintf(stderr, "put: %s\n", e->path); |
1138 fprintf(stderr, "put: %s\n", e->path); |
1139 DavResource *res = dav_resource_new(sn, newpath); |
1139 DavResource *res = dav_resource_new(sn, newpath); |
1140 dav_set_content(res, tar, (dav_read_func)tar_fread); |
1140 dav_set_content(res, tar, (dav_read_func)tar_fread, (dav_seek_func)tar_seek); |
1141 dav_set_content_length(res, (size_t)e->size); |
1141 dav_set_content_length(res, (size_t)e->size); |
1142 |
1142 |
1143 if(dav_store(res)) { |
1143 if(dav_store(res)) { |
1144 print_resource_error(sn, res->path); |
1144 print_resource_error(sn, res->path); |
1145 fprintf(stderr, "Cannot upload file.\n"); |
1145 fprintf(stderr, "Cannot upload file.\n"); |
1176 } |
1176 } |
1177 |
1177 |
1178 return ret; |
1178 return ret; |
1179 } |
1179 } |
1180 |
1180 |
|
1181 static int file_seek(FILE *f, curl_off_t offset, int origin) { |
|
1182 int ret = fseek(f, offset, origin); |
|
1183 return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK; |
|
1184 } |
|
1185 |
1181 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { |
1186 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { |
1182 DavResource *res = dav_query(sn, "select - from %s", path); |
1187 DavResource *res = dav_query(sn, "select - from %s", path); |
1183 |
1188 |
1184 if(!res) { |
1189 if(!res) { |
1185 if(sn->error == DAV_NOT_FOUND) { |
1190 if(sn->error == DAV_NOT_FOUND) { |
1210 int ret = put_file(repo, a, sn, res->path, NULL, in, len); |
1215 int ret = put_file(repo, a, sn, res->path, NULL, in, len); |
1211 // TODO: free res |
1216 // TODO: free res |
1212 return ret; |
1217 return ret; |
1213 } |
1218 } |
1214 |
1219 |
1215 dav_set_content(res, in, (dav_read_func)fread); |
1220 dav_set_content(res, in, (dav_read_func)fread, (dav_seek_func)file_seek); |
1216 if(len > 0 && len < 0x7d000000) { |
1221 if(len > 0 && len < 0x7d000000) { |
1217 dav_set_content_length(res, (size_t)len); |
1222 dav_set_content_length(res, (size_t)len); |
1218 } |
1223 } |
1219 |
1224 |
1220 if(dav_store(res)) { |
1225 if(dav_store(res)) { |