home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / src / create_adm.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  3KB  |  141 lines

  1. /*
  2.  * Copyright (c) 1992, Brian Berliner and Jeff Polk
  3.  * Copyright (c) 1989-1992, Brian Berliner
  4.  * 
  5.  * You may distribute under the terms of the GNU General Public License as
  6.  * specified in the README file that comes with the CVS 1.4 kit.
  7.  * 
  8.  * Create Administration.
  9.  * 
  10.  * Creates a CVS administration directory based on the argument repository; the
  11.  * "Entries" file is prefilled from the "initrecord" argument.
  12.  */
  13.  
  14. #include "cvs.h"
  15.  
  16. /* update_dir includes dir as its last component.  */
  17.  
  18. void
  19. Create_Admin (dir, update_dir, repository, tag, date)
  20.     char *dir;
  21.     char *update_dir;
  22.     char *repository;
  23.     char *tag;
  24.     char *date;
  25. {
  26.     FILE *fout;
  27.     char *cp;
  28.     char tmp[PATH_MAX];
  29.  
  30. #ifdef SERVER_SUPPORT
  31.     if (trace)
  32.     {
  33.     char wd[PATH_MAX];
  34.     getwd (wd);
  35.     fprintf (stderr, "%c-> Create_Admin (%s, %s, %s, %s, %s) in %s\n",
  36.          (server_active) ? 'S' : ' ',
  37.                 dir, update_dir, repository, tag ? tag : "",
  38.                 date ? date : "", wd);
  39.     }
  40. #endif
  41.  
  42.     if (noexec)
  43.     return;
  44.  
  45.     if (dir != NULL)
  46.     (void) sprintf (tmp, "%s/%s", dir, CVSADM);
  47.     else
  48.     (void) strcpy (tmp, CVSADM);
  49.     if (isfile (tmp))
  50.     error (1, 0, "there is a version in %s already", update_dir);
  51.  
  52.     make_directory (tmp);
  53.  
  54.     /* record the current cvs root for later use */
  55.  
  56.     Create_Root (dir, CVSroot_original);
  57.     if (dir != NULL)
  58.     (void) sprintf (tmp, "%s/%s", dir, CVSADM_REP);
  59.     else
  60.     (void) strcpy (tmp, CVSADM_REP);
  61.     fout = CVS_FOPEN (tmp, "w+");
  62.     if (fout == NULL)
  63.     {
  64.     if (update_dir[0] == '\0')
  65.         error (1, errno, "cannot open %s", tmp);
  66.     else
  67.         error (1, errno, "cannot open %s/%s", update_dir, CVSADM_REP);
  68.     }
  69.     cp = repository;
  70.     strip_path (cp);
  71.  
  72. #ifdef RELATIVE_REPOS
  73.     /*
  74.      * If the Repository file is to hold a relative path, try to strip off
  75.      * the leading CVSroot argument.
  76.      */
  77.     if (CVSroot_directory != NULL)
  78.     {
  79.     char path[PATH_MAX];
  80.  
  81.     (void) sprintf (path, "%s/", CVSroot_directory);
  82.     if (strncmp (repository, path, strlen (path)) == 0)
  83.         cp = repository + strlen (path);
  84.     }
  85. #endif
  86.  
  87.     if (fprintf (fout, "%s\n", cp) < 0)
  88.     {
  89.     if (update_dir[0] == '\0')
  90.         error (1, errno, "write to %s failed", tmp);
  91.     else
  92.         error (1, errno, "write to %s/%s failed", update_dir, CVSADM_REP);
  93.     }
  94.     if (fclose (fout) == EOF)
  95.     {
  96.     if (update_dir[0] == '\0')
  97.         error (1, errno, "cannot close %s", tmp);
  98.     else
  99.         error (1, errno, "cannot close %s/%s", update_dir, CVSADM_REP);
  100.     }
  101.  
  102.     /* now, do the Entries file */
  103.     if (dir != NULL)
  104.     (void) sprintf (tmp, "%s/%s", dir, CVSADM_ENT);
  105.     else
  106.     (void) strcpy (tmp, CVSADM_ENT);
  107.     fout = CVS_FOPEN (tmp, "w+");
  108.     if (fout == NULL)
  109.     {
  110.     if (update_dir[0] == '\0')
  111.         error (1, errno, "cannot open %s", tmp);
  112.     else
  113.         error (1, errno, "cannot open %s/%s", update_dir, CVSADM_ENT);
  114.     }
  115.     if (fclose (fout) == EOF)
  116.     {
  117.     if (update_dir[0] == '\0')
  118.         error (1, errno, "cannot close %s", tmp);
  119.     else
  120.         error (1, errno, "cannot close %s/%s", update_dir, CVSADM_ENT);
  121.     }
  122.  
  123.     /* Create a new CVS/Tag file */
  124.     WriteTag (dir, tag, date);
  125.  
  126. #ifdef SERVER_SUPPORT
  127.     if (server_active)
  128.     {
  129.     server_set_sticky (update_dir, repository, tag, date);
  130.     server_template (update_dir, repository);
  131.     }
  132.  
  133.     if (trace)
  134.     {
  135.     fprintf (stderr, "%c<- Create_Admin\n",
  136.          (server_active) ? 'S' : ' ');
  137.     }
  138. #endif
  139.  
  140. }
  141.