#include "cvs.h"
int
Create_Admin (dir, update_dir, repository, tag, date, nonbranch, warn)
char *dir;
char *update_dir;
char *repository;
char *tag;
char *date;
int nonbranch;
int warn;
{
FILE *fout;
char *cp;
char *reposcopy;
char *tmp;
#ifdef SERVER_SUPPORT
if (trace)
{
fprintf (stderr, "%c-> Create_Admin (%s, %s, %s, %s, %s, %d, %d)\n",
(server_active) ? 'S' : ' ',
dir, update_dir, repository, tag ? tag : "",
date ? date : "", nonbranch, warn);
}
#endif
if (noexec)
return 0;
tmp = xmalloc (strlen (dir) + 100);
if (dir != NULL)
(void) sprintf (tmp, "%s/%s", dir, CVSADM);
else
(void) strcpy (tmp, CVSADM);
if (isfile (tmp))
error (1, 0, "there is a version in %s already", update_dir);
if (CVS_MKDIR (tmp, 0777) < 0)
{
if (warn)
{
error (0, errno, "warning: cannot make directory %s in %s",
CVSADM, update_dir);
free (tmp);
return 1;
}
else
error (1, errno, "cannot make directory %s in %s",
CVSADM, update_dir);
}
Create_Root (dir, CVSroot_original);
if (dir != NULL)
(void) sprintf (tmp, "%s/%s", dir, CVSADM_REP);
else
(void) strcpy (tmp, CVSADM_REP);
fout = CVS_FOPEN (tmp, "w+");
if (fout == NULL)
{
if (update_dir[0] == '\0')
error (1, errno, "cannot open %s", tmp);
else
error (1, errno, "cannot open %s/%s", update_dir, CVSADM_REP);
}
reposcopy = xstrdup (repository);
Sanitize_Repository_Name (reposcopy);
if (strcmp (reposcopy, CVSroot_directory) == 0)
{
reposcopy = xrealloc (reposcopy, strlen (reposcopy) + 3);
strcat (reposcopy, "/.");
}
cp = reposcopy;
#ifdef RELATIVE_REPOS
if (CVSroot_directory != NULL)
{
char *path = xmalloc (strlen (CVSroot_directory) + 10);
(void) sprintf (path, "%s/", CVSroot_directory);
if (strncmp (cp, path, strlen (path)) == 0)
cp += strlen (path);
free (path);
}
#endif
if (fprintf (fout, "%s\n", cp) < 0)
{
if (update_dir[0] == '\0')
error (1, errno, "write to %s failed", tmp);
else
error (1, errno, "write to %s/%s failed", update_dir, CVSADM_REP);
}
if (fclose (fout) == EOF)
{
if (update_dir[0] == '\0')
error (1, errno, "cannot close %s", tmp);
else
error (1, errno, "cannot close %s/%s", update_dir, CVSADM_REP);
}
if (dir != NULL)
(void) sprintf (tmp, "%s/%s", dir, CVSADM_ENT);
else
(void) strcpy (tmp, CVSADM_ENT);
fout = CVS_FOPEN (tmp, "w+");
if (fout == NULL)
{
if (update_dir[0] == '\0')
error (1, errno, "cannot open %s", tmp);
else
error (1, errno, "cannot open %s/%s", update_dir, CVSADM_ENT);
}
if (fclose (fout) == EOF)
{
if (update_dir[0] == '\0')
error (1, errno, "cannot close %s", tmp);
else
error (1, errno, "cannot close %s/%s", update_dir, CVSADM_ENT);
}
WriteTag (dir, tag, date, nonbranch, update_dir, repository);
#ifdef SERVER_SUPPORT
if (server_active)
{
server_template (update_dir, repository);
}
if (trace)
{
fprintf (stderr, "%c<- Create_Admin\n",
(server_active) ? 'S' : ' ');
}
#endif
free (reposcopy);
free (tmp);
return 0;
}