dav/main.c

changeset 517
8531b63accae
parent 512
3320a015a3bc
child 520
da2b0cc44e4f
equal deleted inserted replaced
516:39f5f17c3bc3 517:8531b63accae
45 #include "config.h" 45 #include "config.h"
46 #include "error.h" 46 #include "error.h"
47 #include "assistant.h" 47 #include "assistant.h"
48 #include "system.h" 48 #include "system.h"
49 #include "pwd.h" 49 #include "pwd.h"
50 #include "finfo.h"
50 #include "main.h" 51 #include "main.h"
51 52
52 static DavContext *ctx; 53 static DavContext *ctx;
53 54
54 static int printxmlerror = 1; 55 static int printxmlerror = 1;
74 if(argc < 2) { 75 if(argc < 2) {
75 fprintf(stderr, "Missing command\n"); 76 fprintf(stderr, "Missing command\n");
76 print_usage(argv[0]); 77 print_usage(argv[0]);
77 return -1; 78 return -1;
78 } 79 }
80
81 putenv("LC_TIME=C");
79 82
80 char *cmd = argv[1]; 83 char *cmd = argv[1];
81 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2); 84 CmdArgs *args = cmd_parse_args(argc - 2, argv + 2);
82 if(!args) { 85 if(!args) {
83 print_usage(argv[0]); 86 print_usage(argv[0]);
1251 ignoredirerr = TRUE; 1254 ignoredirerr = TRUE;
1252 } else if(ucx_map_cstr_get(a->options, "recursive")) { 1255 } else if(ucx_map_cstr_get(a->options, "recursive")) {
1253 printfile = TRUE; 1256 printfile = TRUE;
1254 } 1257 }
1255 1258
1259 char *finfo_str = cmd_getoption(a, "finfo");
1260 uint32_t finfo = 0;
1261 if(finfo_str) {
1262 finfo = parse_finfo(finfo_str);
1263 }
1256 1264
1257 int ret; 1265 int ret;
1258 for(int i=1;i<a->argc;i++) { 1266 for(int i=1;i<a->argc;i++) {
1259 char *file = a->argv[i]; 1267 char *file = a->argv[i];
1260 if(!import) { 1268 if(!import) {
1261 if(!strcmp(file, "-")) { 1269 if(!strcmp(file, "-")) {
1262 FILE *in = stdin; 1270 FILE *in = stdin;
1263 ret = put_file(repo, a, sn, path, "stdin", in, 0); 1271 ret = put_file(repo, a, sn, path, "stdin", 0, NULL, in, 0);
1264 } else { 1272 } else {
1265 ret = put_entry( 1273 ret = put_entry(
1266 repo, 1274 repo,
1267 a, 1275 a,
1268 sn, 1276 sn,
1269 path, 1277 path,
1270 file, 1278 file,
1279 finfo,
1271 TRUE, 1280 TRUE,
1272 printfile, 1281 printfile,
1273 ignoredirerr); 1282 ignoredirerr);
1274 } 1283 }
1275 } else { 1284 } else {
1289 Repository *repo, 1298 Repository *repo,
1290 CmdArgs *a, 1299 CmdArgs *a,
1291 DavSession *sn, 1300 DavSession *sn,
1292 char *path, 1301 char *path,
1293 char *file, 1302 char *file,
1303 uint32_t finfo,
1294 DavBool root, 1304 DavBool root,
1295 DavBool printfile, 1305 DavBool printfile,
1296 DavBool ignoredirerr) 1306 DavBool ignoredirerr)
1297 { 1307 {
1298 int recursive = cmd_getoption(a, "recursive") ? 1 : 0; 1308 int recursive = cmd_getoption(a, "recursive") ? 1 : 0;
1338 repo, 1348 repo,
1339 a, 1349 a,
1340 sn, 1350 sn,
1341 entry_path, 1351 entry_path,
1342 entry_file, 1352 entry_file,
1353 finfo,
1343 FALSE, 1354 FALSE,
1344 printfile, 1355 printfile,
1345 ignoredirerr); 1356 ignoredirerr);
1346 free(entry_path); 1357 free(entry_path);
1347 free(entry_file); 1358 free(entry_file);
1368 } else if(S_ISREG(s.st_mode)) { 1379 } else if(S_ISREG(s.st_mode)) {
1369 if(printfile) { 1380 if(printfile) {
1370 printf("put: %s\n", file); 1381 printf("put: %s\n", file);
1371 } 1382 }
1372 1383
1373 /*
1374 * use stdin if the input file is -
1375 */
1376 FILE *in = fopen(file, "rb"); 1384 FILE *in = fopen(file, "rb");
1377 if(!in) { 1385 if(!in) {
1378 fprintf(stderr, "cannot open input file\n"); 1386 fprintf(stderr, "cannot open input file\n");
1379 return -1; 1387 return -1;
1380 } 1388 }
1381 char *filename = util_resource_name(file); 1389 char *filename = util_resource_name(file);
1382 //path = util_concat_path(path, filename); 1390 //path = util_concat_path(path, filename);
1383 ret = put_file(repo, a, sn, path, filename, in, s.st_size); 1391 ret = put_file(repo, a, sn, path, filename, finfo, file, in, s.st_size);
1384 //free(path); 1392 //free(path);
1385 fclose(in); 1393 fclose(in);
1386 } 1394 }
1387 1395
1388 return ret; 1396 return ret;
1467 static int file_seek(FILE *f, curl_off_t offset, int origin) { 1475 static int file_seek(FILE *f, curl_off_t offset, int origin) {
1468 int ret = fseek(f, offset, origin); 1476 int ret = fseek(f, offset, origin);
1469 return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK; 1477 return ret == 0 ? CURL_SEEKFUNC_OK : CURL_SEEKFUNC_CANTSEEK;
1470 } 1478 }
1471 1479
1472 int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { 1480 int put_file(
1481 Repository *repo,
1482 CmdArgs *a,
1483 DavSession *sn,
1484 char *path,
1485 char *name,
1486 uint32_t finfo,
1487 const char *fpath,
1488 FILE *in,
1489 off_t len)
1490 {
1473 DavResource *res = dav_query(sn, "select - from %s", path); 1491 DavResource *res = dav_query(sn, "select - from %s", path);
1474 1492
1475 if(!res) { 1493 if(!res) {
1476 if(sn->error == DAV_NOT_FOUND) { 1494 if(sn->error == DAV_NOT_FOUND) {
1477 res = dav_resource_new(sn, path); 1495 res = dav_resource_new(sn, path);
1495 return -1; 1513 return -1;
1496 } 1514 }
1497 1515
1498 path = newpath; 1516 path = newpath;
1499 res = dav_resource_new(sn, path); 1517 res = dav_resource_new(sn, path);
1518 int ret = put_file(repo, a, sn, res->path, NULL, finfo, fpath, in, len);
1519 // TODO: free res
1500 free(newpath); 1520 free(newpath);
1501 int ret = put_file(repo, a, sn, res->path, NULL, in, len);
1502 // TODO: free res
1503 return ret; 1521 return ret;
1522 }
1523
1524 if(resource_set_finfo(fpath, res, finfo)) {
1525 fprintf(stderr, "Cannot set finfo: %s.\n", strerror(errno));
1504 } 1526 }
1505 1527
1506 dav_set_content(res, in, (dav_read_func)fread, (dav_seek_func)file_seek); 1528 dav_set_content(res, in, (dav_read_func)fread, (dav_seek_func)file_seek);
1507 if(len > 0 && len < 0x7d000000) { 1529 if(len > 0 && len < 0x7d000000) {
1508 dav_set_content_length(res, (size_t)len); 1530 dav_set_content_length(res, (size_t)len);

mercurial