aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-01-03 19:40:33 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-01-03 20:03:27 +0200
commitfa78a9f21ff4fd85fb568232c9bee957b9c83497 (patch)
tree597162dff26a81877b5788fc5015fc8b075354b7
parent17f28552af10e72a221a0be16417249852774f1b (diff)
downloadwydawca-fa78a9f21ff4fd85fb568232c9bee957b9c83497.tar.gz
wydawca-fa78a9f21ff4fd85fb568232c9bee957b9c83497.tar.bz2
Improve memory management and optimize function signatures.
* src/wydawca.h (file_triplet): New members: relative_dir, obstk. (virt_tab): Remove spool and reldir from argument lists. (triplet_strdup): New prototype. (move_file, archive_file, symlink_file) (rmsymlink_file, dir_move_file, dir_archive_file) (dir_symlink_file, dir_rmsymlink_file) (null_move_file, null_archive_file) (null_symlink_file, null_rmsymlink_file): Remove spool and reldir from argument lists. * src/directive.c (run_check_script): Use trp->obstk to store the program output. (process_directives): Update calls to vtab interfaces. * src/diskio.c (dir_move_file) (dir_archive_file, dir_symlink_file) (dir_rmsymlink_file): Remove spool and reldir arguments. Use the corresponding members of the struct file_triplet. * src/null.c (null_move_file, null_archive_file) (null_symlink_file, null_rmsymlink_file): Likewise. * src/vtab.c (move_file, archive_file) (symlink_file, rmsymlink_file): Likewise. * src/triplet.c (hash_triplet_free): Free obstack and uploader_list. (triplet_strdup): New function. (register_file): Initialize trp->obstck. (fill_project_name): Fill relative_dir as well. (verify_directive_file): Use triplet_strdup to keep string values.
-rw-r--r--src/directive.c34
-rw-r--r--src/diskio.c61
-rw-r--r--src/null.c22
-rw-r--r--src/triplet.c26
-rw-r--r--src/verify.c38
-rw-r--r--src/vtab.c29
-rw-r--r--src/wydawca.h56
7 files changed, 127 insertions, 139 deletions
diff --git a/src/directive.c b/src/directive.c
index 93830b1..34e5feb 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -404,7 +404,6 @@ run_check_script (const char *script, struct file_triplet *trp,
404 FILE *fp; 404 FILE *fp;
405 char *buf; 405 char *buf;
406 size_t size, total; 406 size_t size, total;
407 struct obstack stk;
408 407
409 if (debug_level > 1) 408 if (debug_level > 1)
410 logmsg (LOG_DEBUG, _("prep script: %20.20s%s"), 409 logmsg (LOG_DEBUG, _("prep script: %20.20s%s"),
@@ -492,7 +491,6 @@ run_check_script (const char *script, struct file_triplet *trp,
492 fp = fdopen (p[0], "r"); 491 fp = fdopen (p[0], "r");
493 buf = NULL; 492 buf = NULL;
494 size = total = 0; 493 size = total = 0;
495 obstack_init (&stk);
496 if (debug_level > 2) 494 if (debug_level > 2)
497 logmsg (LOG_DEBUG, _("reading script output...")); 495 logmsg (LOG_DEBUG, _("reading script output..."));
498 while (getline (&buf, &size, fp) > 0) 496 while (getline (&buf, &size, fp) > 0)
@@ -500,10 +498,10 @@ run_check_script (const char *script, struct file_triplet *trp,
500 size_t len = strlen (buf); 498 size_t len = strlen (buf);
501 if (debug_level > 2) 499 if (debug_level > 2)
502 logmsg (LOG_DEBUG, _("read: %s"), buf); 500 logmsg (LOG_DEBUG, _("read: %s"), buf);
503 obstack_grow (&stk, buf, len); 501 obstack_grow (&trp->obstk, buf, len);
504 total += size; 502 total += size;
505 } 503 }
506 obstack_1grow (&stk, 0); 504 obstack_1grow (&trp->obstk, 0);
507 if (debug_level > 2) 505 if (debug_level > 2)
508 logmsg (LOG_DEBUG, _("bytes read: %lu"), (unsigned long)total); 506 logmsg (LOG_DEBUG, _("bytes read: %lu"), (unsigned long)total);
509 507
@@ -513,8 +511,7 @@ run_check_script (const char *script, struct file_triplet *trp,
513 signal (SIGCHLD, oldsig); 511 signal (SIGCHLD, oldsig);
514 512
515 if (total) 513 if (total)
516 trp->check_diag = xstrdup (obstack_finish (&stk)); 514 trp->check_diag = obstack_finish (&trp->obstk);
517 obstack_free (&stk, NULL);
518 515
519 trp->check_result = status; 516 trp->check_result = status;
520 if (WIFEXITED (status)) 517 if (WIFEXITED (status))
@@ -593,7 +590,6 @@ process_directives (struct file_triplet *trp)
593{ 590{
594 int rc, n; 591 int rc, n;
595 const char *key, *val; 592 const char *key, *val;
596 char *relative_dir;
597 const struct spool *spool; 593 const struct spool *spool;
598 594
599 ASGN_SPOOL (spool, trp, return 1); 595 ASGN_SPOOL (spool, trp, return 1);
@@ -616,14 +612,7 @@ process_directives (struct file_triplet *trp)
616 break; 612 break;
617 613
618 case directory_dir: 614 case directory_dir:
619 /* FIXME: Alloc it in triplet */ 615 /* already processed (see fill_project_name in verify.c */
620 relative_dir = safe_file_name_alloc (val);
621 if (!relative_dir || relative_dir[0] == '/')
622 {
623 logmsg (LOG_ERR, _("%s: invalid directory: %s"),
624 trp->file[file_directive].name, val);
625 return 1;
626 }
627 break; 616 break;
628 617
629 case filename_dir: 618 case filename_dir:
@@ -632,8 +621,8 @@ process_directives (struct file_triplet *trp)
632 { 621 {
633 if (external_check (trp)) 622 if (external_check (trp))
634 return 1; 623 return 1;
635 if (move_file (trp, spool, file_dist, relative_dir) 624 if (move_file (trp, file_dist)
636 || move_file (trp, spool, file_signature, relative_dir)) 625 || move_file (trp, file_signature))
637 return 1; 626 return 1;
638 } 627 }
639 else 628 else
@@ -645,11 +634,12 @@ process_directives (struct file_triplet *trp)
645 break; 634 break;
646 635
647 case version_dir: 636 case version_dir:
648 /* Already processed */ 637 /* Already processed. See directive_version_in_range_p,
638 called by verify_directive_format */
649 break; 639 break;
650 640
651 case archive_dir: 641 case archive_dir:
652 if (archive_file (trp, spool, relative_dir, val)) 642 if (archive_file (trp, val))
653 return 1; 643 return 1;
654 break; 644 break;
655 645
@@ -673,8 +663,7 @@ process_directives (struct file_triplet *trp)
673 key, val); 663 key, val);
674 } 664 }
675 else 665 else
676 rc = symlink_file (trp, spool, relative_dir, 666 rc = symlink_file (trp, ws.ws_wordv[0], ws.ws_wordv[1]);
677 ws.ws_wordv[0], ws.ws_wordv[1]);
678 667
679 wordsplit_free (&ws); 668 wordsplit_free (&ws);
680 if (rc) 669 if (rc)
@@ -683,7 +672,7 @@ process_directives (struct file_triplet *trp)
683 break; 672 break;
684 673
685 case rmsymlink_dir: 674 case rmsymlink_dir:
686 if (rmsymlink_file (trp, spool, relative_dir, val)) 675 if (rmsymlink_file (trp, val))
687 return 1; 676 return 1;
688 } 677 }
689 } 678 }
@@ -694,7 +683,6 @@ process_directives (struct file_triplet *trp)
694 trp->file[file_directive].name, strerror (errno)); 683 trp->file[file_directive].name, strerror (errno));
695 } 684 }
696 685
697 free (relative_dir);
698 UPDATE_STATS (STAT_TRIPLET_SUCCESS); 686 UPDATE_STATS (STAT_TRIPLET_SUCCESS);
699 report_finish (); 687 report_finish ();
700 timer_stop ("triplet"); 688 timer_stop ("triplet");
diff --git a/src/diskio.c b/src/diskio.c
index 1760a88..46526d0 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -108,7 +108,7 @@ create_hierarchy (char *dir, size_t baselen)
108} 108}
109 109
110/* Create a directory BASE/NAME (with eventual intermediate directories in 110/* Create a directory BASE/NAME (with eventual intermediate directories in
111 NAME). Use UID and GID as owner ids. 111 NAME).
112 Do nothing if dry_run_mode is set. */ 112 Do nothing if dry_run_mode is set. */
113char * 113char *
114create_directory (const char *base, const char *name) 114create_directory (const char *base, const char *name)
@@ -372,19 +372,27 @@ do_archive_file (const char *dst_file, const char *dst_dir, const char *file,
372 const struct archive_descr *archive, 372 const struct archive_descr *archive,
373 const char *reldir) 373 const char *reldir)
374{ 374{
375 int rc = 0;
376
375 switch (archive->type) 377 switch (archive->type)
376 { 378 {
377 case archive_none: 379 case archive_none:
378 break; 380 break;
379 381
380 case archive_directory: 382 case archive_directory:
381 return backup_file (dst_file, dst_dir, file, archive, reldir); 383 if (backup_file (dst_file, dst_dir, file, archive, reldir))
384 return 1;
385 UPDATE_STATS (STAT_ARCHIVES);
386 break;
382 387
383 case archive_tar: 388 case archive_tar:
384 if (tar_append_file (archive->name, dst_file)) 389 if (tar_append_file (archive->name, dst_file))
385 return 1; 390 return 1;
391 UPDATE_STATS (STAT_ARCHIVES);
392 break;
386 } 393 }
387 if (!dry_run_mode && unlink (dst_file)) 394
395 if (!dry_run_mode && unlink (dst_file) && errno != ENOENT)
388 { 396 {
389 logmsg (LOG_ERR, _("canot unlink file `%s': %s"), 397 logmsg (LOG_ERR, _("canot unlink file `%s': %s"),
390 dst_file, strerror (errno)); 398 dst_file, strerror (errno));
@@ -394,17 +402,17 @@ do_archive_file (const char *dst_file, const char *dst_dir, const char *file,
394} 402}
395 403
396/* Move the part FILE_ID of the triplet TRP between the directories in 404/* Move the part FILE_ID of the triplet TRP between the directories in
397 DPAIR. RELDIR gives relative directory (i.e. the directory part of 405 TRP->SPOOL. TRP->RELATIVE_DIR gives relative directory (i.e. the
398 the file name) for backup purposes. 406 directory part of the file name) for backup purposes.
399 407
400 Do nothing if dry_run_mode is set. */ 408 Do nothing if dry_run_mode is set. */
401int 409int
402dir_move_file (struct file_triplet *trp, const struct spool *spool, 410dir_move_file (struct file_triplet *trp, enum file_type file_id)
403 enum file_type file_id, const char *reldir)
404{ 411{
405 char *dst_file; 412 char *dst_file;
406 int rc = 0; 413 int rc = 0;
407 char *dst_dir = create_directory (spool->dest_dir, reldir); 414 const struct spool *spool = trp->spool;
415 char *dst_dir = create_directory (spool->dest_dir, trp->relative_dir);
408 416
409 if (!dst_dir) 417 if (!dst_dir)
410 return 1; 418 return 1;
@@ -416,7 +424,7 @@ dir_move_file (struct file_triplet *trp, const struct spool *spool,
416 424
417 if (access (dst_file, F_OK) == 0) 425 if (access (dst_file, F_OK) == 0)
418 rc = do_archive_file (dst_file, dst_dir, trp->file[file_id].name, 426 rc = do_archive_file (dst_file, dst_dir, trp-&