Changeset 76 for trunk/src/sh_hash.c
- Timestamp:
- Dec 19, 2006, 10:01:59 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_hash.c
r68 r76 1460 1460 if (sh.flag.update == S_FALSE) 1461 1461 { 1462 if (pushdata_stdout == S_FALSE) 1463 { 1464 pushdata_fd = -1; 1465 if ( SL_ISERROR(pushdata_fd = sl_open_write(file_path('D', 'W'), SL_YESPRIV))) { 1466 SH_FREE(fullpath); 1467 SH_FREE(linkpath); 1468 sh_error_handle((-1), FIL__, __LINE__, pushdata_fd, MSG_E_ACCESS, 1469 geteuid(), file_path('D', 'W')); 1470 SL_RET0(_("sh_hash_pushdata")); 1471 } 1472 if ( SL_ISERROR(status = sl_forward(pushdata_fd))) { 1473 SH_FREE(fullpath); 1474 SH_FREE(linkpath); 1475 sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGPATH, 1476 _("Fast forward failed"), _("sh_hash_pushdata"), 1477 file_path('D', 'W')); 1478 SL_RET0(_("sh_hash_pushdata")); 1479 } 1462 if (pushdata_stdout == S_FALSE && pushdata_fd == -1) 1463 { 1464 if ( SL_ISERROR(pushdata_fd = sl_open_write(file_path('D', 'W'), SL_YESPRIV))) 1465 { 1466 SH_FREE(fullpath); 1467 SH_FREE(linkpath); 1468 sh_error_handle((-1), FIL__, __LINE__, pushdata_fd, MSG_E_ACCESS, 1469 geteuid(), file_path('D', 'W')); 1470 SL_RET0(_("sh_hash_pushdata")); 1471 } 1472 if ( SL_ISERROR(status = sl_forward(pushdata_fd))) 1473 { 1474 SH_FREE(fullpath); 1475 SH_FREE(linkpath); 1476 sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGPATH, 1477 _("Fast forward failed"), _("sh_hash_pushdata"), 1478 file_path('D', 'W')); 1479 SL_RET0(_("sh_hash_pushdata")); 1480 } 1480 1481 } 1481 1482 } … … 1726 1727 { 1727 1728 sl_write (pushdata_fd, &p, sizeof(sh_filestore_t)); 1728 sl_write_line (pushdata_fd, fullpath,sl_strlen(fullpath));1729 sl_write_line (pushdata_fd, linkpath,sl_strlen(linkpath));1729 sl_write_line_fast (pushdata_fd, fullpath, sl_strlen(fullpath)); 1730 sl_write_line_fast (pushdata_fd, linkpath, sl_strlen(linkpath)); 1730 1731 if (attr_string) 1731 sl_write_line (pushdata_fd, attr_string,sl_strlen(attr_string));1732 sl_write_line_fast (pushdata_fd, attr_string, sl_strlen(attr_string)); 1732 1733 } else { 1733 1734 fwrite (&p, sizeof(sh_filestore_t), 1, stdout); … … 1742 1743 if ((sh.flag.update != S_TRUE) && (pushdata_stdout == S_FALSE)) 1743 1744 { 1744 sl_close (pushdata_fd); 1745 pushdata_fd = -1; 1745 if (sh.flag.checkSum != SH_CHECK_INIT || (buf == NULL && fileHash == NULL)) 1746 { 1747 sl_close (pushdata_fd); 1748 pushdata_fd = -1; 1749 } 1746 1750 } 1747 1751 … … 3413 3417 return 0; 3414 3418 } 3419 3420 /* Always quote the string, except if it is empty. Qoute quotes by 3421 * doubling them. 3422 */ 3423 char * csv_escape(const char * str) 3424 { 3425 const char * p = str; 3426 const char * q; 3427 3428 size_t size = 0; 3429 size_t flag_quote = 0; 3430 int flag_comma = 0; 3431 char * new; 3432 char * pnew; 3433 3434 if (p) 3435 { 3436 3437 while (*p) 3438 { 3439 if (*p == ',') 3440 flag_comma = 1; 3441 else if (*p == '"') 3442 ++flag_quote; 3443 3444 ++size; ++p; 3445 } 3446 3447 if (sl_ok_adds(size, flag_quote)) 3448 size += flag_quote; /* double each quote */ 3449 else 3450 return NULL; 3451 3452 if (sl_ok_adds(size, 3)) 3453 size += 3; /* two quotes and terminating null */ 3454 else 3455 return NULL; 3456 3457 new = SH_ALLOC(size); 3458 3459 if (flag_quote != 0) 3460 { 3461 new[0] = '"'; 3462 pnew = &new[1]; 3463 q = str; 3464 while (*q) 3465 { 3466 *pnew = *q; 3467 if (*pnew == '"') 3468 { 3469 ++pnew; *pnew = '"'; 3470 } 3471 ++pnew; ++q; 3472 } 3473 *pnew = '"'; ++pnew; 3474 *pnew = '\0'; 3475 } 3476 else 3477 { 3478 if (size > 3) 3479 { 3480 new[0] = '"'; 3481 sl_strlcpy (&new[1], str, size-1); 3482 new[size-2] = '"'; 3483 new[size-1] = '\0'; 3484 } 3485 else 3486 { 3487 new[0] = '\0'; 3488 } 3489 } 3490 3491 return new; 3492 } 3493 return NULL; 3494 } 3495 3496 3415 3497 3416 3498 void sh_hash_list_db_entry_full_detail (sh_file_t * p) 3417 3499 { 3418 3500 char * tmp; 3501 char * esc; 3419 3502 char str[81]; 3420 size_t i;3421 3503 3422 3504 if (ListWithDelimiter == S_TRUE) … … 3464 3546 3465 3547 tmp = sh_util_safe_name(p->fullpath); 3466 printf( _(" %s"), tmp); 3548 if (ListWithDelimiter != S_TRUE) 3549 { 3550 printf( _(" %s"), tmp); 3551 } 3552 else 3553 { 3554 esc = csv_escape(tmp); 3555 printf( _(" %s,"), (esc != NULL) ? esc : _("(null)")); 3556 if (esc) 3557 SH_FREE(esc); 3558 } 3467 3559 SH_FREE(tmp); 3468 if (ListWithDelimiter == S_TRUE)3469 putchar(',');3470 3560 3471 3561 if ('l' == p->theFile.c_mode[0]) 3472 3562 { 3473 3563 tmp = sh_util_safe_name(p->linkpath); 3474 if (ListWithDelimiter == S_TRUE) 3475 printf(_(" %s"), tmp); 3564 if (ListWithDelimiter != S_TRUE) 3565 { 3566 printf(_(" -> %s"), tmp); 3567 } 3476 3568 else 3477 printf(_(" -> %s"), tmp); 3569 { 3570 esc = csv_escape(tmp); 3571 printf( _(" %s,"), (esc != NULL) ? esc : _("(null)")); 3572 if (esc) 3573 SH_FREE(esc); 3574 } 3478 3575 SH_FREE(tmp); 3479 3576 } 3480 if (ListWithDelimiter == S_TRUE)3481 putchar(',');3482 3577 3483 3578 if (p->attr_string) 3484 3579 { 3485 3580 tmp = sh_util_safe_name(p->attr_string); 3486 if (ListWithDelimiter == S_TRUE) { 3487 for (i = 0; i < strlen(tmp); ++i) 3488 if (tmp[i] == ',') tmp[i] = ';'; 3489 } 3581 if (ListWithDelimiter != S_TRUE) 3582 { 3583 printf(_(" %s"), tmp); 3584 } 3585 else 3586 { 3587 esc = csv_escape(tmp); 3588 printf( _(" %s"), (esc != NULL) ? esc : _("(null)")); 3589 if (esc) 3590 SH_FREE(esc); 3591 } 3490 3592 printf(_(" %s"), tmp); 3491 3593 SH_FREE(tmp);
Note:
See TracChangeset
for help on using the changeset viewer.