[BACK]Return to co.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rcs

Diff for /src/usr.bin/rcs/co.c between version 1.85 and 1.86

version 1.85, 2006/04/26 02:55:13 version 1.86, 2006/04/26 21:55:22
Line 36 
Line 36 
 int  int
 checkout_main(int argc, char **argv)  checkout_main(int argc, char **argv)
 {  {
         int i, ch, flags, kflag, status, warg;          int fd, i, ch, flags, kflag, status, warg;
         RCSNUM *rev;          RCSNUM *rev;
         RCSFILE *file;          RCSFILE *file;
         char fpath[MAXPATHLEN];          char fpath[MAXPATHLEN];
Line 152 
Line 152 
                 err(1, "getlogin");                  err(1, "getlogin");
   
         for (i = 0; i < argc; i++) {          for (i = 0; i < argc; i++) {
                 if (rcs_statfile(argv[i], fpath, sizeof(fpath), flags) < 0)                  fd = rcs_statfile(argv[i], fpath, sizeof(fpath), flags);
                   if (fd < 0)
                         continue;                          continue;
   
                 if (!(flags & QUIET))                  if (!(flags & QUIET))
Line 161 
Line 162 
   
                 if ((flags & CO_LOCK) && (kflag & RCS_KWEXP_VAL)) {                  if ((flags & CO_LOCK) && (kflag & RCS_KWEXP_VAL)) {
                         warnx("%s: cannot combine -kv and -l", fpath);                          warnx("%s: cannot combine -kv and -l", fpath);
                           (void)close(fd);
                         continue;                          continue;
                 }                  }
   
                 if ((file = rcs_open(fpath, RCS_RDWR|RCS_PARSE_FULLY)) == NULL)                  if ((file = rcs_open(fpath, fd,
                       RCS_RDWR|RCS_PARSE_FULLY)) == NULL)
                         continue;                          continue;
   
                 if (flags & PRESERVETIME)                  if (flags & PRESERVETIME)
                         rcs_mtime = rcs_get_mtime(file->rf_path);                          rcs_mtime = rcs_get_mtime(file);
   
                 rcs_kwexp_set(file, kflag);                  rcs_kwexp_set(file, kflag);
   
Line 197 
Line 200 
                 if (!(flags & QUIET))                  if (!(flags & QUIET))
                         printf("done\n");                          printf("done\n");
   
                 rcs_close(file);  
                 rcsnum_free(rev);                  rcsnum_free(rev);
   
                   rcs_write(file);
                 if (flags & PRESERVETIME)                  if (flags & PRESERVETIME)
                         rcs_set_mtime(fpath, rcs_mtime);                          rcs_set_mtime(file, rcs_mtime);
                   rcs_close(file);
         }          }
   
         if (author != NULL && warg)          if (author != NULL && warg)
Line 240 
Line 244 
 {  {
         BUF *bp;          BUF *bp;
         u_int i;          u_int i;
         int lcount;          int fd, lcount;
         char buf[16];          char buf[16];
         mode_t mode = 0444;          mode_t mode = 0444;
         struct stat st;          struct stat st;
Line 364 
Line 368 
         /*          /*
          * File inherits permissions from its ,v file           * File inherits permissions from its ,v file
          */           */
         if (stat(file->rf_path, &st) == -1)          if (file->fd != -1) {
                 err(1, "%s", file->rf_path);                  if (fstat(file->fd, &st) == -1)
                           err(1, "%s", file->rf_path);
                   mode = st.st_mode;
           }
   
         mode = st.st_mode;  
   
         if (flags & CO_LOCK) {          if (flags & CO_LOCK) {
                 if (file->rf_ndelta != 0) {                  if (file->rf_ndelta != 0) {
                         if (lockname != NULL &&                          if (lockname != NULL &&
Line 379 
Line 384 
                 }                  }
   
                 /* Strip all write bits from mode */                  /* Strip all write bits from mode */
                 mode = st.st_mode &                  if (file->fd != -1) {
                     (S_IXUSR|S_IXGRP|S_IXOTH|S_IRUSR|S_IRGRP|S_IROTH);                          mode = st.st_mode &
                               (S_IXUSR|S_IXGRP|S_IXOTH|S_IRUSR|S_IRGRP|S_IROTH);
                   }
   
                 mode |= S_IWUSR;                  mode |= S_IWUSR;
   
                 if (file->rf_ndelta != 0) {                  if (file->rf_ndelta != 0) {
Line 397 
Line 405 
                 }                  }
   
                 /* Strip all write bits from mode */                  /* Strip all write bits from mode */
                 mode = st.st_mode &                  if (file->fd != -1) {
                     (S_IXUSR|S_IXGRP|S_IXOTH|S_IRUSR|S_IRGRP|S_IROTH);                          mode = st.st_mode &
                               (S_IXUSR|S_IXGRP|S_IXOTH|S_IRUSR|S_IRGRP|S_IROTH);
                   }
   
                 if (file->rf_ndelta != 0) {                  if (file->rf_ndelta != 0) {
                         if (!(flags & QUIET) && !(flags & NEWFILE) &&                          if (!(flags & QUIET) && !(flags & NEWFILE) &&
Line 424 
Line 434 
                             file->rf_path, lcount);                              file->rf_path, lcount);
         }          }
   
         if (!(flags & PIPEOUT) && stat(dst, &st) == 0 && !(flags & FORCE)) {          if (!(flags & PIPEOUT) && stat(dst, &st) != -1 && !(flags & FORCE)) {
                 /*                  /*
                  * XXX - Not sure what is "right".  If we go according                   * XXX - Not sure what is "right".  If we go according
                  * to GNU's behavior, an existing file with no writable                   * to GNU's behavior, an existing file with no writable
Line 460 
Line 470 
                 printf("%s", content);                  printf("%s", content);
                 xfree(content);                  xfree(content);
         } else {          } else {
                 if (rcs_buf_write(bp, dst, mode) < 0) {                  (void)unlink(dst);
   
                   if ((fd = open(dst, O_WRONLY|O_CREAT|O_TRUNC, mode)) < 0)
                           err(1, "%s", dst);
   
                   if (rcs_buf_write_fd(bp, fd) < 0) {
                         warnx("failed to write revision to file");                          warnx("failed to write revision to file");
                         rcs_buf_free(bp);                          rcs_buf_free(bp);
                           (void)close(fd);
                         return (-1);                          return (-1);
                 }                  }
   
                   if (fchmod(fd, mode) == -1)
                           warn("%s", dst);
   
                 rcs_buf_free(bp);                  rcs_buf_free(bp);
   
                 if (flags & CO_REVDATE) {                  if (flags & CO_REVDATE) {
                         struct timeval tv[2];                          struct timeval tv[2];
                         memset(&tv, 0, sizeof(tv));                          memset(&tv, 0, sizeof(tv));
                         tv[0].tv_sec = (long)rcs_rev_getdate(file, rev);                          tv[0].tv_sec = (long)rcs_rev_getdate(file, rev);
                         tv[1].tv_sec = tv[0].tv_sec;                          tv[1].tv_sec = tv[0].tv_sec;
                         if (utimes(dst, (const struct timeval *)&tv) < 0)                          if (futimes(fd, (const struct timeval *)&tv) < 0)
                                 warn("utimes");                                  warn("utimes");
                 }                  }
   
                   (void)close(fd);
         }          }
   
         return (0);          return (0);

Legend:
Removed from v.1.85  
changed lines
  Added in v.1.86