Пример #1
0
/* Get FILENAME from version control system CS.  The file already exists if
   EXISTS.  Only readonly access is needed if READONLY.
   Use the command GETBUF to actually get the named file.
   Store the resulting file status into *FILESTAT.
   Return true if successful.  */
bool
version_get (char const *filename, char const *cs, bool exists, bool readonly,
	     char const *getbuf, struct stat *filestat)
{
  if (patch_get < 0)
    {
      ask ("Get file %s from %s%s? [y] ",
	   quotearg (filename), cs, readonly ? "" : " with lock");
      if (*buf == 'n')
	return 0;
    }

  if (dry_run)
    {
      if (! exists)
	fatal ("can't do dry run on nonexistent version-controlled file %s; invoke '%s' and try again",
	       quotearg (filename), getbuf);
    }
  else
    {
      if (verbosity == VERBOSE)
	say ("Getting file %s from %s%s...\n", quotearg (filename),
	     cs, readonly ? "" : " with lock");
      if (systemic (getbuf) != 0)
	fatal ("Can't get file %s from %s", quotearg (filename), cs);
      if (stat (filename, filestat) != 0)
	pfatal ("%s", quotearg (filename));
    }

  return 1;
}
Пример #2
0
void
	get_input_file (char const *filename, char const *outname)
{
	bool elsewhere = strcmp (filename, outname) != 0;
	char const *cs;
	char *diffbuf;
	char *getbuf;

	if (inerrno == -1)
		inerrno = stat (inname, &instat) == 0 ? 0 : errno;

	/* Perhaps look for RCS or SCCS versions.  */
	if (patch_get
		&& invc != 0
		&& (inerrno
		|| (! elsewhere
		&& (/* No one can write to it.  */
		(instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) == 0
		/* Only the owner (who's not me) can write to it.  */
		|| ((instat.st_mode & (S_IWGRP|S_IWOTH)) == 0
		&& instat.st_uid != geteuid ()))))
		&& (invc = !! (cs = (version_controller
		(filename, elsewhere,
		inerrno ? (struct stat *) 0 : &instat,
		&getbuf, &diffbuf))))) {

			if (!inerrno) {
				if (!elsewhere
					&& (instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) != 0)
					/* Somebody can write to it.  */
					fatal ("File %s seems to be locked by somebody else under %s",
					quotearg (filename), cs);
				if (diffbuf)
				{
					/* It might be checked out unlocked.  See if it's safe to
					check out the default version locked.  */

					if (verbosity == VERBOSE)
						say ("Comparing file %s to default %s version...\n",
						quotearg (filename), cs);

					if (systemic (diffbuf) != 0)
					{
						say ("warning: Patching file %s, which does not match default %s version\n",
							quotearg (filename), cs);
						cs = 0;
					}
				}
			}

			if (cs && version_get (filename, cs, ! inerrno, elsewhere, getbuf,
				&instat))
				inerrno = 0;

			free (getbuf);
			if (diffbuf)
				free (diffbuf);

	} else if (inerrno && !pch_says_nonexistent (reverse))
	{
		errno = inerrno;
		pfatal ("Can't find file %s", quotearg (filename));
	}

	if (inerrno)
	{
		instat.st_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
		instat.st_size = 0;
	}
	else if (! S_ISREG (instat.st_mode))
		fatal ("File %s is not a regular file -- can't patch",
		quotearg (filename));
}