1203 |
1203 |
1204 return 0; |
1204 return 0; |
1205 } |
1205 } |
1206 |
1206 |
1207 int cmd_put(CmdArgs *a, DavBool import) { |
1207 int cmd_put(CmdArgs *a, DavBool import) { |
1208 if(a->argc != 2) { |
1208 if(a->argc < 2) { |
1209 // TODO: change, when put supports multiple files (however it should do) |
1209 fprintf(stderr, "Too few arguments\n"); |
1210 fprintf(stderr, "Too %s arguments\n", a->argc < 2 ? "few":"many"); |
1210 fprintf(stderr, |
1211 fprintf(stderr, "Usage: dav %s\n", find_usage_str("put")); |
1211 "Usage: dav %s\n", |
1212 return -1; |
1212 find_usage_str(import ? "import" : "put")); |
1213 } |
1213 return -1; |
|
1214 } |
|
1215 DavBool use_stdin = FALSE; |
|
1216 for(int i=1;i<a->argc;i++) { |
|
1217 if(!strcmp(a->argv[i], "-")) { |
|
1218 if(use_stdin) { |
|
1219 fprintf(stderr, "Error: stdin can only occur once in input list\n"); |
|
1220 return -1; |
|
1221 } else { |
|
1222 use_stdin = TRUE; |
|
1223 } |
|
1224 } |
|
1225 } |
|
1226 |
1214 if(import) { |
1227 if(import) { |
1215 ucx_map_cstr_put(a->options, "resursive", ""); |
1228 ucx_map_cstr_put(a->options, "resursive", ""); |
1216 } |
1229 } |
1217 |
1230 |
1218 char *url = a->argv[0]; |
1231 char *url = a->argv[0]; |
1219 char *file = a->argv[1]; |
|
1220 char *path = NULL; |
1232 char *path = NULL; |
1221 Repository *repo = url2repo(url, &path); |
1233 Repository *repo = url2repo(url, &path); |
1222 DavSession *sn = connect_to_repo(repo, path, a); |
1234 DavSession *sn = connect_to_repo(repo, path, a); |
1223 |
1235 |
1224 if(set_session_config(sn, a)) { |
1236 if(set_session_config(sn, a)) { |
1229 if(check_encryption_key(a, sn)) { |
1241 if(check_encryption_key(a, sn)) { |
1230 // TODO: free |
1242 // TODO: free |
1231 return -1; |
1243 return -1; |
1232 } |
1244 } |
1233 |
1245 |
|
1246 DavBool printfile = FALSE; |
|
1247 DavBool ignoredirerr = FALSE; |
|
1248 if(a->argc > 2) { |
|
1249 printfile = TRUE; |
|
1250 ignoredirerr = TRUE; |
|
1251 } else if(ucx_map_cstr_get(a->options, "recursive")) { |
|
1252 printfile = TRUE; |
|
1253 } |
|
1254 |
|
1255 |
1234 int ret; |
1256 int ret; |
1235 if(!import) { |
1257 for(int i=1;i<a->argc;i++) { |
1236 if(!strcmp(file, "-")) { |
1258 char *file = a->argv[i]; |
1237 FILE *in = stdin; |
1259 if(!import) { |
1238 ret = put_file(repo, a, sn, path, "stdin", in, 0); |
1260 if(!strcmp(file, "-")) { |
1239 } else { |
1261 FILE *in = stdin; |
1240 ret = put_entry(repo, a, sn, path, file, TRUE); |
1262 ret = put_file(repo, a, sn, path, "stdin", in, 0); |
1241 } |
1263 } else { |
1242 } else { |
1264 ret = put_entry( |
1243 ret = put_tar(repo, a, sn, file, path); |
1265 repo, |
|
1266 a, |
|
1267 sn, |
|
1268 path, |
|
1269 file, |
|
1270 TRUE, |
|
1271 printfile, |
|
1272 ignoredirerr); |
|
1273 } |
|
1274 } else { |
|
1275 ret = put_tar(repo, a, sn, file, path); |
|
1276 } |
|
1277 if(ret) { |
|
1278 break; |
|
1279 } |
1244 } |
1280 } |
1245 |
1281 |
1246 free(path); |
1282 free(path); |
|
1283 dav_session_destroy(sn); |
1247 return ret; |
1284 return ret; |
1248 } |
1285 } |
1249 |
1286 |
1250 int put_entry(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *file, DavBool root) { |
1287 int put_entry( |
|
1288 Repository *repo, |
|
1289 CmdArgs *a, |
|
1290 DavSession *sn, |
|
1291 char *path, |
|
1292 char *file, |
|
1293 DavBool root, |
|
1294 DavBool printfile, |
|
1295 DavBool ignoredirerr) |
|
1296 { |
1251 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
1297 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; |
1252 struct stat s; |
1298 struct stat s; |
1253 if(stat(file, &s)) { |
1299 if(stat(file, &s)) { |
1254 perror("stat"); |
1300 perror("stat"); |
1255 fprintf(stderr, "cannot stat file %s\n", file); |
1301 fprintf(stderr, "cannot stat file %s\n", file); |