[CVS] RPM: rpm/tools/ cp.c

2010-11-02 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   02-Nov-2010 16:18:04
  Branch: HEAD Handle: 2010110215180400

  Modified files:
rpm/tools   cp.c

  Log:
- sync with rpm-5_3.

  Summary:
RevisionChanges Path
2.22+4  -0  rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.21 -r2.22 cp.c
  --- rpm/tools/cp.c21 Mar 2010 00:30:20 -  2.21
  +++ rpm/tools/cp.c2 Nov 2010 15:18:04 -   2.22
  @@ -41,6 +41,10 @@
   
   #include "debug.h"
   
  +#if !defined(MIN)/* XXX OpenIndiana needs */
  +#define  MIN(a,b) (((a)<(b))?(a):(b))
  +#endif
  +
   /* Memory strategy threshold, in pages: if physmem is larger then this, use 
a 
* large buffer */
   #define PHYSPAGES_THRESHOLD (32*1024)
  @@ .
__
RPM Package Managerhttp://rpm5.org
CVS Sources Repositoryrpm-cvs@rpm5.org


[CVS] RPM: rpm/tools/ cp.c

2010-03-20 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   21-Mar-2010 01:30:20
  Branch: HEAD Handle: 2010032100302000

  Modified files:
rpm/tools   cp.c

  Log:
- cp: fix: resolve the tedious -R <-> -r issue by having it both ways.

  Summary:
RevisionChanges Path
2.21+3  -1  rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.20 -r2.21 cp.c
  --- rpm/tools/cp.c9 Jan 2010 22:04:15 -   2.20
  +++ rpm/tools/cp.c21 Mar 2010 00:30:20 -  2.21
  @@ -803,7 +803,7 @@
   /*...@unchecked@*/ /*...@observer@*/
   static struct poptOption optionsTable[] = {
   /*...@-type@*/ /* FIX: cast? */
  - { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | 
POPT_CBFLAG_CONTINUE,
  + { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA,
   copyArgCallback, 0, NULL, NULL },
   /*...@=type@*/
   
  @@ -815,6 +815,8 @@
N_("Never follow symbolic links"), NULL },
 { "recursive",'R', POPT_ARG_NONE,  NULL, (int)'R',
N_("Copy directories recursively"), NULL },
  +  { "recursive",'r', POPT_ARG_NONE|POPT_ARGFLAG_DOC_HIDDEN,  NULL, (int)'R',
  + N_("Copy directories recursively"), NULL },
 { "archive",'a', POPT_ARG_NONE,NULL, (int)'a',
N_("Archive mode (same as -RpP)"), NULL },
 { "force",'f', POPT_ARG_NONE,  NULL, (int)'f',
  @@ .
__
RPM Package Managerhttp://rpm5.org
CVS Sources Repositoryrpm-cvs@rpm5.org


[CVS] RPM: rpm/tools/ cp.c rpmfind.c

2010-01-09 Thread Anders F. Bj�rklund
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Anders F. Björklund
  Root:   /v/rpm/cvs   Email:  a...@rpm5.org
  Module: rpm  Date:   09-Jan-2010 23:04:15
  Branch: HEAD Handle: 2010010922041500

  Modified files:
rpm/tools   cp.c rpmfind.c

  Log:
use rpmio for compat

  Summary:
RevisionChanges Path
2.20+1  -1  rpm/tools/cp.c
2.14+1  -1  rpm/tools/rpmfind.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.19 -r2.20 cp.c
  --- rpm/tools/cp.c6 Dec 2009 16:33:26 -   2.19
  +++ rpm/tools/cp.c9 Jan 2010 22:04:15 -   2.20
  @@ -218,7 +218,7 @@
   
   TIMESPEC_TO_TIMEVAL(&ct->tv[0], &st->st_atimespec);
   TIMESPEC_TO_TIMEVAL(&ct->tv[1], &st->st_mtimespec);
  -if (islink ? lutimes(ct->npath, ct->tv) : Utimes(ct->npath, ct->tv)) {
  +if (islink ? Lutimes(ct->npath, ct->tv) : Utimes(ct->npath, ct->tv)) {
rpmlog(RPMLOG_ERR, "%stimes: %s: %s\n", islink ? "lu" : "U", ct->npath, 
strerror(errno));
rval = RPMRC_FAIL;
   }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/rpmfind.c
  
  $ cvs diff -u -r2.13 -r2.14 rpmfind.c
  --- rpm/tools/rpmfind.c   18 Dec 2009 00:32:39 -  2.13
  +++ rpm/tools/rpmfind.c   9 Jan 2010 22:04:15 -   2.14
  @@ -1483,7 +1483,7 @@
   if ((entry->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE))
&& !(entry->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE))
&& geteuid() == 0)
  - lchflags(entry->fts_accpath,
  + Lchflags(entry->fts_accpath,
   entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
   #endif
   
  @@ .
__
RPM Package Managerhttp://rpm5.org
CVS Sources Repositoryrpm-cvs@rpm5.org


[CVS] RPM: rpm/tools/ cp.c rpmfind.c

2009-12-06 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   06-Dec-2009 17:33:27
  Branch: HEAD Handle: 2009120616332600

  Modified files:
rpm/tools   cp.c rpmfind.c

  Log:
- snow leopard portability fiddle-ups.

  Summary:
RevisionChanges Path
2.19+2  -0  rpm/tools/cp.c
2.12+7  -0  rpm/tools/rpmfind.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.18 -r2.19 cp.c
  --- rpm/tools/cp.c4 Oct 2009 22:46:21 -   2.18
  +++ rpm/tools/cp.c6 Dec 2009 16:33:26 -   2.19
  @@ -864,9 +864,11 @@
   
   __progname = "cp";
   
  +#if defined(_SC_PHYS_PAGES)
   if (sysconf(_SC_PHYS_PAGES) > PHYSPAGES_THRESHOLD)
ct->ballocated = MIN(BUFSIZE_MAX, MAXPHYS * 8);
   else
  +#endif
ct->ballocated = BUFSIZE_SMALL;
   
   ct->npath[0] = '\0';
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/rpmfind.c
  
  $ cvs diff -u -r2.11 -r2.12 rpmfind.c
  --- rpm/tools/rpmfind.c   6 Sep 2009 18:39:51 -   2.11
  +++ rpm/tools/rpmfind.c   6 Dec 2009 16:33:26 -   2.12
  @@ -1106,7 +1106,11 @@
(void)fprintf(stderr, "\n");
(void)fflush(stderr);
   }
  +#if defined(__APPLE__)
  +return ((resp[0] == 'Y' || resp[0] == 'y') ? 1 : 0);
  +#else
   return (rpmatch(resp) == 1);
  +#endif
   }
   
   /*==*/
  @@ -1926,6 +1930,9 @@
   {
   char * fsname = nextarg(option, argvp);
   PLAN * new = palloc(option);
  +#if defined(__APPLE__)
  +#define  xvfsconfvfsconf
  +#endif
   #if defined(HAVE_STRUCT_STAT_ST_FLAGS)   /* XXX HACK */
   struct xvfsconf vfc;
   #endif
  @@ .
__
RPM Package Managerhttp://rpm5.org
CVS Sources Repositoryrpm-cvs@rpm5.org


[CVS] RPM: rpm/tools/ cp.c

2009-10-04 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   05-Oct-2009 00:46:21
  Branch: HEAD Handle: 2009100422462100

  Modified files:
rpm/tools   cp.c

  Log:
- cp: add --xdev, stub-in addititional GNUish bits.

  Summary:
RevisionChanges Path
2.18+16 -3  rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.17 -r2.18 cp.c
  --- rpm/tools/cp.c15 Sep 2009 19:18:48 -  2.17
  +++ rpm/tools/cp.c4 Oct 2009 22:46:21 -   2.18
  @@ -71,7 +71,13 @@
   COPY_FLAGS_HARDLINK  = _MFB( 6), /*!< -l,--link ... */
   COPY_FLAGS_NOCLOBBER = _MFB( 7), /*!< -n,--noclobber ... */
   COPY_FLAGS_PRESERVE  = _MFB( 8), /*!< -p,--preserve ... */
  - /* 9-31 unused */
  +COPY_FLAGS_XDEV  = _MFB( 9), /*!< -x,--xdev ... */
  +
  +COPY_FLAGS_SYMLINK   = _MFB(10), /*!< -s,--symlink ... */
  +COPY_FLAGS_UPDATE= _MFB(11), /*!< -u,--update ... */
  +COPY_FLAGS_SPARSE= _MFB(12), /*!<--sparse ... */
  +
  + /* 13-31 unused */
   };
   
   #define CP_ISSET(_FLAG) ((ct->flags & ((COPY_FLAGS_##_FLAG) & ~0x4000)) 
!= COPY_FLAGS_NONE)
  @@ -781,6 +787,9 @@
ct->flags |= COPY_FLAGS_FOLLOW;
ct->flags &= ~COPY_FLAGS_FOLLOWARGS;
break;
  +case 'x':
  + ct->flags |= COPY_FLAGS_XDEV;
  + break;
   
   case '?':
   default:
  @@ -818,6 +827,8 @@
N_("Do not overwrite an existing file"), NULL },
 { "preserve",'p', POPT_ARG_NONE,   NULL, (int)'p',
N_("Preserve mode/ownership/timestamps"), NULL },
  +  { "xdev",'x', POPT_ARG_NONE,   NULL, (int)'x',
  + N_("Stay on thgis file system"), NULL },
   
   #ifdef   NOTYET
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioFtsPoptTable, 0,
  @@ -837,7 +848,7 @@
 { NULL, (char)-1, POPT_ARG_INCLUDE_TABLE, NULL, 0,
   "\
   Usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file 
target_file\n\
  -   cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... 
target_directory\n\
  +   cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpv] source_file ... 
target_dir\n\
   ", NULL },
   
 POPT_TABLEEND
  @@ -861,6 +872,7 @@
   ct->npath[0] = '\0';
   ct->target_end = "";
   ct->p_end = ct->npath;
  +ct->ftsoptions = FTS_NOCHDIR | FTS_PHYSICAL;
   
   optCon = rpmioInit(argc, argv, optionsTable);
   ct->av = poptGetArgs(optCon);
  @@ -870,7 +882,6 @@
goto exit;
   }
   
  -ct->ftsoptions = FTS_NOCHDIR | FTS_PHYSICAL;
   if (CP_ISSET(RECURSE)) {
if (CP_ISSET(FOLLOWARGS))
ct->ftsoptions |= FTS_COMFOLLOW;
  @@ -882,6 +893,8 @@
ct->ftsoptions &= ~FTS_PHYSICAL;
ct->ftsoptions |= FTS_LOGICAL | FTS_COMFOLLOW;
   }
  +if (CP_ISSET(XDEV))
  + ct->ftsoptions |= FTS_XDEV;
   
   #if defined(SIGINFO)
   (void)signal(SIGINFO, siginfo);
  @@ .
__
RPM Package Managerhttp://rpm5.org
CVS Sources Repositoryrpm-cvs@rpm5.org


[CVS] RPM: rpm/tools/ cp.c rpmmtree.c

2009-09-03 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   03-Sep-2009 22:19:13
  Branch: HEAD Handle: 2009090320191300

  Modified files:
rpm/tools   cp.c rpmmtree.c

  Log:
- use rpmlog() throughout.

  Summary:
RevisionChanges Path
2.11+59 -73 rpm/tools/cp.c
2.11+1  -1  rpm/tools/rpmmtree.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.10 -r2.11 cp.c
  --- rpm/tools/cp.c3 Sep 2009 18:53:25 -   2.10
  +++ rpm/tools/cp.c3 Sep 2009 20:19:13 -   2.11
  @@ -91,9 +91,7 @@
   COPY_FLAGS_HARDLINK  = _MFB( 6), /*!< -l,--link ... */
   COPY_FLAGS_NOCLOBBER = _MFB( 7), /*!< -n,--noclobber ... */
   COPY_FLAGS_PRESERVE  = _MFB( 8), /*!< -p,--preserve ... */
  -
  -COPY_FLAGS_VERBOSE   = _MFB( 9), /*!< -v,--verbose ... */
  - /* 10-31 unused */
  + /* 9-31 unused */
   };
   
   #define CP_ISSET(_FLAG) ((ct->flags & ((COPY_FLAGS_##_FLAG) & ~0x4000)) 
!= COPY_FLAGS_NONE)
  @@ -144,16 +142,23 @@
   
   static rpmct _ct = &__ct;
   
  +#if defined(SIGINFO)
   static volatile sig_atomic_t info;
   
  -/* - utils.c */
  +static void
  +siginfo(int sig __attribute__((__unused__)))
  +{
  +info = 1;
  +}
  +
  +#define  cp_pct(x, y)((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
  +
  +#endif
   
   #if !defined(MAXPHYS)
   #define  MAXPHYS (128 * 1024)/* max raw I/O transfer size */
   #endif
   
  -#define  cp_pct(x, y)((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
  -
   /* Memory strategy threshold, in pages: if physmem is larger then this, use 
a 
* large buffer */
   #define PHYSPAGES_THRESHOLD (32*1024)
  @@ -181,7 +186,7 @@
   TIMESPEC_TO_TIMEVAL(&ct->tv[0], &st->st_atimespec);
   TIMESPEC_TO_TIMEVAL(&ct->tv[1], &st->st_mtimespec);
   if (islink ? lutimes(ct->p_path, ct->tv) : Utimes(ct->p_path, ct->tv)) {
  - warn("%sutimes: %s", islink ? "l" : "", ct->p_path);
  + rpmlog(RPMLOG_ERR, "%stimes: %s: %s\n", islink ? "lu" : "U", 
ct->p_path, strerror(errno));
rval = RPMRC_FAIL;
   }
   if (fdval ? Fstat(fd, &ts) :
  @@ -204,7 +209,7 @@
   Chown(ct->p_path, st->st_uid, st->st_gid)))
{
if (errno != EPERM) {
  - warn("chown: %s", ct->p_path);
  + rpmlog(RPMLOG_ERR, "Chown: %s: %s\n", ct->p_path, 
strerror(errno));
rval = RPMRC_FAIL;
}
st->st_mode &= ~(S_ISUID | S_ISGID);
  @@ -215,7 +220,7 @@
   (islink ? lchmod(ct->p_path, st->st_mode) :
   Chmod(ct->p_path, st->st_mode)))
{
  - warn("Chmod: %s", ct->p_path);
  + rpmlog(RPMLOG_ERR, "Chmod: %s: %s\n", ct->p_path, strerror(errno));
rval = RPMRC_FAIL;
}
   
  @@ -225,7 +230,7 @@
   (islink ? lchflags(ct->p_path, st->st_flags) :
   chflags(ct->p_path, st->st_flags)))
{
  - warn("chflags: %s", ct->p_path);
  + rpmlog(RPMLOG_ERR, "chflags: %s: %s\n", ct->p_path, 
strerror(errno));
rval = RPMRC_FAIL;
}
   #endif
  @@ -254,7 +259,7 @@
   ifd = Fopen(ct->p->fts_path, "r.ufdio");
   if (ifd == NULL || Ferror(ifd)) {
if (ifd) (void) Fclose(ifd);
  - warn("%s", ct->p->fts_path);
  + rpmlog(RPMLOG_ERR, "Fopen: %s: %s\n", ct->p->fts_path, strerror(errno));
return RPMRC_FAIL;
   }
   
  @@ -269,8 +274,8 @@
   if (!dne) {
   #define YESNO "(y/n [n]) "
if (CP_ISSET(NOCLOBBER)) {
  - if (CP_ISSET(VERBOSE))
  - fprintf(stdout, "%s not overwritten\n", ct->p_path);
  + if (rpmIsVerbose())
  + rpmlog(RPMLOG_INFO, "%s not overwritten\n", ct->p_path);
(void) Fclose(ifd);
return RPMRC_OK;
} else if (CP_ISSET(INTERACTIVE)) {
  @@ -304,7 +309,7 @@
   if (ofd == NULL || Ferror(ofd)
|| Fchmod(ofd, st->st_mode & ~(S_ISUID | S_ISGID)))
   {
  - warn("%s", ct->p_path);
  + rpmlog(RPMLOG_ERR, "Fchmod: %s: %s\n", ct->p_path, strerror(errno));
if (ofd) (void) Fclose(ofd);
(void) Fclose(ifd);
return RPMRC_FAIL;
  @@ -334,22 +339,24 @@
if (Ferror(ofd) || wcount <= 0)
break;
wtotal += wcount;
  +#if defined(SIGINFO)
if (info) {
info = 0;
(void)fprintf(stderr, "%s -> %s %3d%%\n",
ct->p->fts_path, ct->p_path,
  

[CVS] RPM: rpm/tools/ cp.c

2009-09-03 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   03-Sep-2009 20:53:25
  Branch: HEAD Handle: 2009090318532500

  Modified files:
rpm/tools   cp.c

  Log:
- avoid err(3)/errx(3) with immediate exit. use warn(3)/warnx(3) w
error return.

  Summary:
RevisionChanges Path
2.10+42 -22 rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.9 -r2.10 cp.c
  --- rpm/tools/cp.c3 Sep 2009 17:42:57 -   2.9
  +++ rpm/tools/cp.c3 Sep 2009 18:53:25 -   2.10
  @@ -108,10 +108,10 @@
* Cp copies source files to target files.
*
* The global PATH_T structure "to" always contains the path to the
  - * current target file.  Since fts(3) does not change directories,
  + * current target file.  Since Fts(3) does not change directories,
* this path can be either absolute or dot-relative.
*
  - * The basic algorithm is to initialize "to" and use fts(3) to traverse
  + * The basic algorithm is to initialize "to" and use Fts(3) to traverse
* the file hierarchy rooted in the argument list.  A trivial case is the
* case of 'cp file1 file2'.  The more interesting case is the case of
* 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the
  @@ -525,8 +525,11 @@
   mask = ~umask(0777);
   umask(~mask);
   
  -if ((ct->t = Fts_open((char *const *)ct->av, ct->ftsoptions, mastercmp)) 
== NULL)
  - err(1, "Fts_open");
  +if ((ct->t = Fts_open((char *const *)ct->av, ct->ftsoptions, mastercmp)) 
== NULL) {
  + warn("Fts_open");
  + rval = RPMRC_FAIL;
  + goto exit;
  +}
   while ((ct->p = Fts_read(ct->t)) != NULL) {
switch (ct->p->fts_info) {
case FTS_NS:
  @@ -682,11 +685,16 @@
 * umask blocks owner writes, we fail..
 */
if (dne) {
  - if (Mkdir(ct->p_path, ct->p->fts_statp->st_mode | S_IRWXU) < 0)
  - err(1, "%s", ct->p_path);
  + if (Mkdir(ct->p_path, ct->p->fts_statp->st_mode | S_IRWXU) < 0) 
{
  + warn("%s", ct->p_path);
  + rval = RPMRC_FAIL;
  + goto exit;
  + }
} else if (!S_ISDIR(ct->sb.st_mode)) {
errno = ENOTDIR;
  - err(1, "%s", ct->p_path);
  + warn("%s", ct->p_path);
  + rval = RPMRC_FAIL;
  + goto exit;
}
/*
 * Arrange to correct directory attributes later
  @@ -727,15 +735,20 @@
(void)fprintf(stdout, "%s -> %s\n", ct->p->fts_path, ct->p_path);
   }
   
  -if (errno)
  - err(1, "Fts_read");
  -Fts_close(ct->t);
  +if (errno) {
  + warn("Fts_read");
  + rval = RPMRC_FAIL;
  + goto exit;
  +}
  +
  +exit:
  +if (ct->t != NULL)
  + Fts_close(ct->t);
   ct->t = NULL;
   ct->p = NULL;
   return rval;
   }
   
  -
   /*==*/
   
   /**
  @@ -744,8 +757,8 @@
   /*...@unused@*/ enum poptCallbackReason reason,
   const struct poptOption * opt, const char * arg,
   /*...@unused@*/ void * data)
  -/*...@globals _rpmfts, rpmioFtsOpts, h_errno, fileSystem, 
internalState @*/
  -/*...@modifies _rpmfts, rpmioFtsOpts, fileSystem, internalState @*/
  +/*...@globals _rpmct, h_errno, fileSystem, internalState @*/
  +/*...@modifies _rpmct, fileSystem, internalState @*/
   {
   rpmct ct = _ct;
   
  @@ -877,7 +890,7 @@
   poptContext optCon = rpmioInit(argc, argv, optionsTable);
   rpmct ct = _ct;
   int r, have_trailing_slash;
  -rpmRC rc = -1;
  +rpmRC rc = RPMRC_FAIL;
   
   if (sysconf(_SC_PHYS_PAGES) > PHYSPAGES_THRESHOLD)
ct->ballocated = MIN(BUFSIZE_MAX, MAXPHYS * 8);
  @@ -914,8 +927,10 @@
   
   /* Save the target base in "to". */
   {const char * target = ct->av[--ct->ac];
  - if (strlen(target) > sizeof(ct->p_path) - 2)
  - errx(1, "%s: name too long", target);
  + if (strlen(target) > sizeof(ct->p_path) - 2) {
  + warnx("%s: name too long", target);
  + goto exit;
  + }
(void) strcpy(ct->p_path, target);
   }
   ct->p_end = ct->p_path + strlen(ct->p_path);
  @@ -947,12 +962,16 @@
* In (2), the real target is not directory, but "directory/source".
*/
   r = Stat(ct->p_path, &ct->sb);
  -if (r == -1 && errno != ENOEN

[CVS] RPM: rpm/tools/ cp.c

2009-09-03 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   03-Sep-2009 19:42:57
  Branch: HEAD Handle: 2009090317425700

  Modified files:
rpm/tools   cp.c

  Log:
- use rpmacl methods to copy ACL's.

  Summary:
RevisionChanges Path
2.9 +7  -86 rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.8 -r2.9 cp.c
  --- rpm/tools/cp.c3 Sep 2009 01:23:11 -   2.8
  +++ rpm/tools/cp.c3 Sep 2009 17:42:57 -   2.9
  @@ -32,9 +32,9 @@
   
   #include "system.h"
   
  -#include 
  -
   #include 
  +#include 
  +#include 
   #include 
   #include 
   #include 
  @@ -166,86 +166,6 @@
   #define BUFSIZE_SMALL (MAXPHYS)
   
   static rpmRC
  -rpmctCopyFdAcls(rpmct ct, FD_t ifd, FD_t ofd)
  -{
  -#if defined(_PC_ACL_EXTENDED)
  -int ifdno = Fileno(ifd);
  -int ofdno = Fileno(ofd);
  -struct acl *aclp;
  -acl_t acl;
  -
  -if (fpathconf(ifdno, _PC_ACL_EXTENDED) != 1
  - || fpathconf(ofdno, _PC_ACL_EXTENDED) != 1)
  - return RPMRC_OK;
  -acl = acl_get_fd(ifdno);
  -if (acl == NULL) {
  - warn("failed to get acl entries while setting %s", ct->p_path);
  - return RPMRC_FAIL;
  -}
  -aclp = &acl->ats_acl;
  -if (aclp->acl_cnt == 3)
  - return RPMRC_OK;
  -if (acl_set_fd(ofdno, acl) < 0) {
  - warn("failed to set acl entries for %s", ct->p_path);
  - return RPMRC_FAIL;
  -}
  -#endif
  -return RPMRC_OK;
  -}
  -
  -static rpmRC
  -rpmctCopyDirAcls(rpmct ct, char *source_dir, char *dest_dir)
  -{
  -#if defined(_PC_ACL_EXTENDED)
  -struct stat * st = ct->p->fts_statp;
  -acl_t (*aclgetf)(const char *, acl_type_t);
  -int (*aclsetf)(const char *, acl_type_t, acl_t);
  -struct acl *aclp;
  -acl_t acl;
  -
  -if (pathconf(source_dir, _PC_ACL_EXTENDED) != 1
  - ||  pathconf(dest_dir, _PC_ACL_EXTENDED) != 1)
  - return RPMRC_OK;
  -/*
  -* If the file is a link we will not follow it
  -*/
  -if (S_ISLNK(st->st_mode)) {
  - aclgetf = acl_get_link_np;
  - aclsetf = acl_set_link_np;
  -} else {
  - aclgetf = acl_get_file;
  - aclsetf = acl_set_file;
  -}
  -/*
  -* Even if there is no ACL_TYPE_DEFAULT entry here, a zero
  -* size ACL will be returned. So it is not safe to simply
  -* check the pointer to see if the default ACL is present.
  -*/
  -acl = aclgetf(source_dir, ACL_TYPE_DEFAULT);
  -if (acl == NULL) {
  - warn("failed to get default acl entries on %s", source_dir);
  - return RPMRC_FAIL;
  -}
  -aclp = &acl->ats_acl;
  -if (aclp->acl_cnt != 0 && aclsetf(dest_dir, ACL_TYPE_DEFAULT, acl) < 0) {
  - warn("failed to set default acl entries on %s", dest_dir);
  - return RPMRC_FAIL;
  -}
  -acl = aclgetf(source_dir, ACL_TYPE_ACCESS);
  -if (acl == NULL) {
  - warn("failed to get acl entries on %s", source_dir);
  - return RPMRC_FAIL;
  -}
  -aclp = &acl->ats_acl;
  -if (aclsetf(dest_dir, ACL_TYPE_ACCESS, acl) < 0) {
  - warn("failed to set acl entries on %s", dest_dir);
  - return RPMRC_FAIL;
  -}
  -#endif
  -return RPMRC_OK;
  -}
  -
  -static rpmRC
   rpmctSetFile(rpmct ct, FD_t fd)
   {
   struct stat * st = ct->p->fts_statp;
  @@ -485,7 +405,7 @@
   if (!CP_ISSET(HARDLINK)) {
if (CP_ISSET(PRESERVE) && rpmctSetFile(ct, ofd))
rval = RPMRC_FAIL;
  - if (CP_ISSET(PRESERVE) && rpmctCopyFdAcls(ct, ifd, ofd) != 0)
  + if (CP_ISSET(PRESERVE) && rpmaclCopyFd(ifd, ofd) != 0)
rval = RPMRC_FAIL;
if (ofd && Fclose(ofd)) {
warn("%s", ct->p_path);
  @@ -593,7 +513,8 @@
   int badcp = 0;
   rpmRC rval = RPMRC_OK;
   size_t nlen;
  -char *p, *target_mid;
  +char *p;
  +char *target_mid;
   mode_t mask;
   mode_t mode;
   
  @@ -691,13 +612,13 @@
 * honour setuid, setgid and sticky bits, but we
 * normally want to preserve them on directories.
 */
  + mode = ct->p->fts_statp->st_mode;
if (CP_ISSET(PRESERVE)) {
if (rpmctSetFile(ct, NULL))
rval = RPMRC_FAIL;
  - if (rpmctCopyDirAcls(ct, ct->p->fts_accpath, ct->p_path) != 0)
  + if (rpmaclCopyDir(ct->p->fts_accpath, ct->p_path, mode) != 0)
rval = RPMRC_FAIL;
} else {
  - mode = ct->p->fts_statp->st_mode;
if ((mode & (S_ISUID | S_ISGID 

[CVS] RPM: rpm/tools/ cp.c

2009-09-02 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   03-Sep-2009 03:23:11
  Branch: HEAD Handle: 2009090301231100

  Modified files:
rpm/tools   cp.c

  Log:
- add option descriptions.

  Summary:
RevisionChanges Path
2.8 +18 -15 rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.7 -r2.8 cp.c
  --- rpm/tools/cp.c3 Sep 2009 00:42:48 -   2.7
  +++ rpm/tools/cp.c3 Sep 2009 01:23:11 -   2.8
  @@ -899,29 +899,32 @@
   /*...@=type@*/
   
 { NULL,'H', POPT_ARG_NONE, NULL, (int)'H',
  - NULL, NULL },
  -  { NULL,'L', POPT_ARG_NONE, NULL, (int)'L',
  - NULL, NULL },
  -  { NULL,'P', POPT_ARG_NONE, NULL, (int)'P',
  - NULL, NULL },
  -  { NULL,'R', POPT_ARG_NONE, NULL, (int)'R',
  - NULL, NULL },
  + N_("Follow command-line symbolic links"), NULL },
  +  { "dereference",'L', POPT_ARG_NONE,NULL, (int)'L',
  + N_("Always follow symbolic links"), NULL },
  +  { "nodereference",'P', POPT_ARG_NONE,  NULL, (int)'P',
  + N_("Never follow symbolic links"), NULL },
  +  { "recursive",'R', POPT_ARG_NONE,  NULL, (int)'R',
  + N_("Copy directories recursively"), NULL },
 { "archive",'a', POPT_ARG_NONE,NULL, (int)'a',
  - NULL, NULL },
  + N_("Archive mode (same as -RpP)"), NULL },
 { "force",'f', POPT_ARG_NONE,  NULL, (int)'f',
  - NULL, NULL },
  + N_("Unlink and retry if 1st open fails"), NULL },
 { "interactive",'i', POPT_ARG_NONE,NULL, (int)'i',
  - NULL, NULL },
  + N_("Prompt before overwriting a file"), NULL },
 { "link",'l', POPT_ARG_NONE,   NULL, (int)'l',
  - NULL, NULL },
  + N_("Link files instead of copying"), NULL },
 { "noclobber",'n', POPT_ARG_NONE,  NULL, (int)'n',
  - NULL, NULL },
  + N_("Do not overwrite an existing file"), NULL },
 { "preserve",'p', POPT_ARG_NONE,   NULL, (int)'p',
  - NULL, NULL },
  + N_("Preserve mode/ownership/timestamps"), NULL },
  +#ifdef   DYING
  +  /* XXX conflicts with -r, --root */
 { NULL,'r', POPT_ARG_NONE, NULL, (int)'r',
  - NULL, NULL },
  + N_("Copy directories recursively"), NULL },
  +#endif
 { "verbose",'v', POPT_ARG_NONE,NULL, (int)'v',
  - NULL, NULL },
  + N_("Explain what is being done"), NULL },
   
   #ifdef   NOTYET
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioFtsPoptTable, 0,
  @@ .
__
RPM Package Managerhttp://rpm5.org
CVS Sources Repositoryrpm-cvs@rpm5.org


[CVS] RPM: rpm/tools/ cp.c

2009-09-02 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   03-Sep-2009 02:42:48
  Branch: HEAD Handle: 2009090300424800

  Modified files:
rpm/tools   cp.c

  Log:
- enable URI's and rpmio common options.

  Summary:
RevisionChanges Path
2.7 +2  -3  rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.6 -r2.7 cp.c
  --- rpm/tools/cp.c2 Sep 2009 23:36:59 -   2.6
  +++ rpm/tools/cp.c3 Sep 2009 00:42:48 -   2.7
  @@ -331,7 +331,7 @@
   char *p;
   #endif
   
  -ifd = Fopen(ct->p->fts_path, "r");
  +ifd = Fopen(ct->p->fts_path, "r.ufdio");
   if (ifd == NULL || Ferror(ifd)) {
if (ifd) (void) Fclose(ifd);
warn("%s", ct->p->fts_path);
  @@ -929,14 +929,13 @@
   
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioDigestPoptTable, 0,
N_("Available digests:"), NULL },
  +#endif
   
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0,
N_("Common options for all rpmio executables:"),
NULL },
   
 POPT_AUTOALIAS
  -#endif
  -
 POPT_AUTOHELP
   
 { NULL, (char)-1, POPT_ARG_INCLUDE_TABLE, NULL, 0,
  @@ .
__
RPM Package Managerhttp://rpm5.org
CVS Sources Repositoryrpm-cvs@rpm5.org


[CVS] RPM: rpm/tools/ cp.c

2009-09-02 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   03-Sep-2009 01:37:00
  Branch: HEAD Handle: 2009090223365900

  Modified files:
rpm/tools   cp.c

  Log:
- rpmRC returns, use Fopen et al, Slovak function naming.

  Summary:
RevisionChanges Path
2.6 +142 -123   rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.5 -r2.6 cp.c
  --- rpm/tools/cp.c2 Sep 2009 21:31:19 -   2.5
  +++ rpm/tools/cp.c2 Sep 2009 23:36:59 -   2.6
  @@ -80,7 +80,7 @@
   /**
* Bit field enum for copy CLI options.
*/
  -enum copyFlags_e {
  +enum rpmctFlags_e {
   COPY_FLAGS_NONE  = 0,
   COPY_FLAGS_FOLLOWARGS= _MFB( 0), /*!< -H ... */
   COPY_FLAGS_FOLLOW= _MFB( 1), /*!< -L ... */
  @@ -102,7 +102,7 @@
*/
   typedef struct rpmct_s * rpmct;
   
  -enum copyType_e { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
  +enum rpmctType_e { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
   
   /*
* Cp copies source files to target files.
  @@ -119,8 +119,8 @@
* in "to") to form the final target path.
*/
   struct rpmct_s {
  -enum copyFlags_e flags;
  -enum copyType_e type;
  +enum rpmctFlags_e flags;
  +enum rpmctType_e type;
   const char ** av;
   int ac;
   int ftsoptions;
  @@ -131,8 +131,8 @@
   size_t blen;
   size_t ballocated;
   struct timeval tv[2];
  -char *p_end; /* pointer to NULL at end of path */
  -char *target_end;/* pointer to end of target base */
  +char * p_end;/* pointer to NULL at end of path */
  +char * target_end;   /* pointer to end of target base */
   char p_path[PATH_MAX];   /* pointer to the start of a path */
   };
   
  @@ -165,34 +165,36 @@
* smaller than MAXPHYS */
   #define BUFSIZE_SMALL (MAXPHYS)
   
  -static int
  -preserve_fd_acls(rpmct ct, int source_fd, int dest_fd)
  +static rpmRC
  +rpmctCopyFdAcls(rpmct ct, FD_t ifd, FD_t ofd)
   {
   #if defined(_PC_ACL_EXTENDED)
  +int ifdno = Fileno(ifd);
  +int ofdno = Fileno(ofd);
   struct acl *aclp;
   acl_t acl;
   
  -if (fpathconf(source_fd, _PC_ACL_EXTENDED) != 1
  - || fpathconf(dest_fd, _PC_ACL_EXTENDED) != 1)
  - return 0;
  -acl = acl_get_fd(source_fd);
  +if (fpathconf(ifdno, _PC_ACL_EXTENDED) != 1
  + || fpathconf(ofdno, _PC_ACL_EXTENDED) != 1)
  + return RPMRC_OK;
  +acl = acl_get_fd(ifdno);
   if (acl == NULL) {
warn("failed to get acl entries while setting %s", ct->p_path);
  - return 1;
  + return RPMRC_FAIL;
   }
   aclp = &acl->ats_acl;
   if (aclp->acl_cnt == 3)
  - return 0;
  -if (acl_set_fd(dest_fd, acl) < 0) {
  + return RPMRC_OK;
  +if (acl_set_fd(ofdno, acl) < 0) {
warn("failed to set acl entries for %s", ct->p_path);
  - return 1;
  + return RPMRC_FAIL;
   }
   #endif
  -return 0;
  +return RPMRC_OK;
   }
   
  -static int
  -preserve_dir_acls(rpmct ct, char *source_dir, char *dest_dir)
  +static rpmRC
  +rpmctCopyDirAcls(rpmct ct, char *source_dir, char *dest_dir)
   {
   #if defined(_PC_ACL_EXTENDED)
   struct stat * st = ct->p->fts_statp;
  @@ -203,7 +205,7 @@
   
   if (pathconf(source_dir, _PC_ACL_EXTENDED) != 1
||  pathconf(dest_dir, _PC_ACL_EXTENDED) != 1)
  - return 0;
  + return RPMRC_OK;
   /*
   * If the file is a link we will not follow it
   */
  @@ -222,34 +224,35 @@
   acl = aclgetf(source_dir, ACL_TYPE_DEFAULT);
   if (acl == NULL) {
warn("failed to get default acl entries on %s", source_dir);
  - return 1;
  + return RPMRC_FAIL;
   }
   aclp = &acl->ats_acl;
   if (aclp->acl_cnt != 0 && aclsetf(dest_dir, ACL_TYPE_DEFAULT, acl) < 0) {
warn("failed to set default acl entries on %s", dest_dir);
  - return 1;
  + return RPMRC_FAIL;
   }
   acl = aclgetf(source_dir, ACL_TYPE_ACCESS);
   if (acl == NULL) {
warn("failed to get acl entries on %s", source_dir);
  - return 1;
  + return RPMRC_FAIL;
   }
   aclp = &acl->ats_acl;
   if (aclsetf(dest_dir, ACL_TYPE_ACCESS, acl) < 0) {
warn("failed to set acl entries on %s", dest_dir);
  - return 1;
  + return RPMRC_FAIL;
   }
   #endif
  -return 0;
  +return RPMRC_OK;
   }
   
  -static int
  -setfile(rpmct ct, int fd)
  +static rpmRC
  +rpmctSetFile(rpmct ct, FD_t fd)
   {
   struct stat * 

[CVS] RPM: rpm/tools/ cp.c

2009-09-02 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   02-Sep-2009 23:31:19
  Branch: HEAD Handle: 2009090221311900

  Modified files:
rpm/tools   cp.c

  Log:
- move global variables into a structure.

  Summary:
RevisionChanges Path
2.5 +319 -310   rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.4 -r2.5 cp.c
  --- rpm/tools/cp.c2 Sep 2009 17:30:52 -   2.4
  +++ rpm/tools/cp.c2 Sep 2009 21:31:19 -   2.5
  @@ -96,10 +96,13 @@
/* 10-31 unused */
   };
   
  -static enum copyFlags_e copyFlags;
  -#define CP_ISSET(_FLAG) ((copyFlags & ((COPY_FLAGS_##_FLAG) & ~0x4000)) 
!= COPY_FLAGS_NONE)
  +#define CP_ISSET(_FLAG) ((ct->flags & ((COPY_FLAGS_##_FLAG) & ~0x4000)) 
!= COPY_FLAGS_NONE)
   
  -static char emptystring[] = "";
  +/**
  + */
  +typedef struct rpmct_s * rpmct;
  +
  +enum copyType_e { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
   
   /*
* Cp copies source files to target files.
  @@ -115,19 +118,34 @@
* path (relative to the root of the traversal) is appended to dir (stored
* in "to") to form the final target path.
*/
  +struct rpmct_s {
  +enum copyFlags_e flags;
  +enum copyType_e type;
  +const char ** av;
  +int ac;
  +int ftsoptions;
  +FTS * t;
  +FTSENT * p;
  +struct stat sb;
  +char * b;
  +size_t blen;
  +size_t ballocated;
  +struct timeval tv[2];
  +char *p_end; /* pointer to NULL at end of path */
  +char *target_end;/* pointer to end of target base */
  +char p_path[PATH_MAX];   /* pointer to the start of a path */
  +};
   
  -typedef struct {
  - char*p_end; /* pointer to NULL at end of path */
  - char*target_end;/* pointer to end of target base */
  - charp_path[PATH_MAX];   /* pointer to the start of a path */
  -} PATH_T;
  +/**
  + */
  +static struct rpmct_s __ct = {
  +.flags = COPY_FLAGS_NONE
  +};
   
  -static PATH_T to = { to.p_path, emptystring, "" };
  +static rpmct _ct = &__ct;
   
   static volatile sig_atomic_t info;
   
  -enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
  -
   /* - utils.c */
   
   #if !defined(MAXPHYS)
  @@ -148,105 +166,103 @@
   #define BUFSIZE_SMALL (MAXPHYS)
   
   static int
  -preserve_fd_acls(int source_fd, int dest_fd)
  +preserve_fd_acls(rpmct ct, int source_fd, int dest_fd)
   {
   #if defined(_PC_ACL_EXTENDED)
  - struct acl *aclp;
  - acl_t acl;
  +struct acl *aclp;
  +acl_t acl;
   
  - if (fpathconf(source_fd, _PC_ACL_EXTENDED) != 1 ||
  - fpathconf(dest_fd, _PC_ACL_EXTENDED) != 1)
  - return 0;
  - acl = acl_get_fd(source_fd);
  - if (acl == NULL) {
  - warn("failed to get acl entries while setting %s", to.p_path);
  - return 1;
  - }
  - aclp = &acl->ats_acl;
  - if (aclp->acl_cnt == 3)
  - return 0;
  - if (acl_set_fd(dest_fd, acl) < 0) {
  - warn("failed to set acl entries for %s", to.p_path);
  - return 1;
  - }
  -#endif
  +if (fpathconf(source_fd, _PC_ACL_EXTENDED) != 1
  + || fpathconf(dest_fd, _PC_ACL_EXTENDED) != 1)
  + return 0;
  +acl = acl_get_fd(source_fd);
  +if (acl == NULL) {
  + warn("failed to get acl entries while setting %s", ct->p_path);
  + return 1;
  +}
  +aclp = &acl->ats_acl;
  +if (aclp->acl_cnt == 3)
return 0;
  +if (acl_set_fd(dest_fd, acl) < 0) {
  + warn("failed to set acl entries for %s", ct->p_path);
  + return 1;
  +}
  +#endif
  +return 0;
   }
   
   static int
  -preserve_dir_acls(struct stat *fs, char *source_dir, char *dest_dir)
  +preserve_dir_acls(rpmct ct, char *source_dir, char *dest_dir)
   {
   #if defined(_PC_ACL_EXTENDED)
  - acl_t (*aclgetf)(const char *, acl_type_t);
  - int (*aclsetf)(const char *, acl_type_t, acl_t);
  - struct acl *aclp;
  - acl_t acl;
  -
  - if (pathconf(source_dir, _PC_ACL_EXTENDED) != 1 ||
  - pathconf(dest_dir, _PC_ACL_EXTENDED) != 1)
  - return 0;
  - /*
  -  * If the file is a link we will not follow it
  -  */
  - if (S_ISLNK(fs->st_mode)) {
  - aclgetf = acl_get_link_np;
  - aclsetf = acl_set_link_np;
  - } else {
  - aclgetf = acl_get_file;
  - aclsetf = acl_set_file;
  - }
  - /*
  -  * Even if there is no ACL_TYPE_DEF

[CVS] RPM: rpm/tools/ cp.c

2009-09-02 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   02-Sep-2009 19:30:52
  Branch: HEAD Handle: 2009090217305200

  Modified files:
rpm/tools   cp.c

  Log:
- use popt, drill in rpmio syscalls.

  Summary:
RevisionChanges Path
2.4 +722 -671   rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.3 -r2.4 cp.c
  --- rpm/tools/cp.c2 Sep 2009 15:17:02 -   2.3
  +++ rpm/tools/cp.c2 Sep 2009 17:30:52 -   2.4
  @@ -33,27 +33,18 @@
   #include "system.h"
   
   #include 
  -#include 
   
  +#include 
  +#include 
   #include 
  -#define  fts_openFts_open
  -#define  fts_readFts_read
  -#define  fts_set Fts_set
  -#define  fts_close   Fts_close
  -
  -#include 
  -#include 
  -
  -#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
  -#include 
  -#endif
  +#include 
   
   #if defined(__linux__)
   #include 
   #define st_atimespecst_atim
   #define st_mtimespecst_mtim
   /* XXX FIXME */
  -#define  lchmod(_fn, _mode)  chmod((_fn), (_mode))
  +#define  lchmod(_fn, _mode)  Chmod((_fn), (_mode))
   #endif
   
   #include "debug.h"
  @@ -78,7 +69,7 @@
   
   #define  STRIP_TRAILING_SLASH(p) {   
\
   while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/')   \
  -*--(p).p_end = 0;\
  +*--(p).p_end = '\0'; \
   }
   
   /*==*/
  @@ -94,22 +85,20 @@
   COPY_FLAGS_FOLLOWARGS= _MFB( 0), /*!< -H ... */
   COPY_FLAGS_FOLLOW= _MFB( 1), /*!< -L ... */
   COPY_FLAGS_RECURSE   = _MFB( 2), /*!< -R ... */
  -COPY_FLAGS_ARCHIVE   = _MFB( 3), /*!< -a ... */
  -COPY_FLAGS_FORCE = _MFB( 4), /*!< -f ... */
  -COPY_FLAGS_INTERACTIVE   = _MFB( 5), /*!< -i ... */
  -COPY_FLAGS_HARDLINK  = _MFB( 6), /*!< -l ... */
  -COPY_FLAGS_NOCLOBBER = _MFB( 7), /*!< -n ... */
  -COPY_FLAGS_PRESERVE  = _MFB( 8), /*!< -p ... */
  +COPY_FLAGS_ARCHIVE   = _MFB( 3), /*!< -a,--archive ... */
  +COPY_FLAGS_FORCE = _MFB( 4), /*!< -f,--force ... */
  +COPY_FLAGS_INTERACTIVE   = _MFB( 5), /*!< -i,--interactive ... */
  +COPY_FLAGS_HARDLINK  = _MFB( 6), /*!< -l,--link ... */
  +COPY_FLAGS_NOCLOBBER = _MFB( 7), /*!< -n,--noclobber ... */
  +COPY_FLAGS_PRESERVE  = _MFB( 8), /*!< -p,--preserve ... */
   
  -COPY_FLAGS_VERBOSE   = _MFB( 9), /*!< -v ... */
  +COPY_FLAGS_VERBOSE   = _MFB( 9), /*!< -v,--verbose ... */
/* 10-31 unused */
   };
   
   static enum copyFlags_e copyFlags;
   #define CP_ISSET(_FLAG) ((copyFlags & ((COPY_FLAGS_##_FLAG) & ~0x4000)) 
!= COPY_FLAGS_NONE)
   
  -static int fts_options;
  -
   static char emptystring[] = "";
   
   /*
  @@ -241,309 +230,308 @@
   static int
   setfile(struct stat *fs, int fd)
   {
  - static struct timeval tv[2];
  - struct stat ts;
  - int rval, gotstat, islink, fdval;
  -
  - rval = 0;
  - fdval = fd != -1;
  - islink = !fdval && S_ISLNK(fs->st_mode);
  - fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX |
  -S_IRWXU | S_IRWXG | S_IRWXO;
  -
  - TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec);
  - TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec);
  - if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
  - warn("%sutimes: %s", islink ? "l" : "", to.p_path);
  +static struct timeval tv[2];
  +struct stat ts;
  +int rval = 0;
  +int fdval = fd != -1;
  +int islink = !fdval && S_ISLNK(fs->st_mode);
  +int gotstat;
  +
  +fs->st_mode &= S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO;
  +
  +TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec);
  +TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec);
  +if (islink ? lutimes(to.p_path, tv) : utimes(to.p_path, tv)) {
  + warn("%sutimes: %s", islink ? "l" : "", to.p_path);
  + rval = 1;
  +}
  +if (fdval ? fstat(fd, &ts) :
  + (islink ? Lstat(to.p_path, &ts) : Stat(to.p_path, &ts)))
  + gotstat = 0;
  +else {
  + gotstat = 1;
  + ts.st_mode &= S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO;
  +}
  +
  +/*
  +* Changing the ownership probably won't succeed, unless we're 

[CVS] RPM: rpm/tools/ cp.c

2009-09-02 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   02-Sep-2009 17:17:03
  Branch: HEAD Handle: 2009090215170200

  Modified files:
rpm/tools   cp.c

  Log:
- use bits for flags.

  Summary:
RevisionChanges Path
2.3 +138 -121   rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.2 -r2.3 cp.c
  --- rpm/tools/cp.c1 Sep 2009 22:00:55 -   2.2
  +++ rpm/tools/cp.c2 Sep 2009 15:17:02 -   2.3
  @@ -30,46 +30,19 @@
* SUCH DAMAGE.
*/
   
  -#include 
  -
  -/*
  - * Cp copies source files to target files.
  - *
  - * The global PATH_T structure "to" always contains the path to the
  - * current target file.  Since fts(3) does not change directories,
  - * this path can be either absolute or dot-relative.
  - *
  - * The basic algorithm is to initialize "to" and use fts(3) to traverse
  - * the file hierarchy rooted in the argument list.  A trivial case is the
  - * case of 'cp file1 file2'.  The more interesting case is the case of
  - * 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the
  - * path (relative to the root of the traversal) is appended to dir (stored
  - * in "to") to form the final target path.
  - */
  +#include "system.h"
   
   #include 
  -#include 
  -#include 
  -#include 
  -#include 
  -
   #include 
  -#include 
  -#include 
   
  -#ifdef   NOTYET
   #include 
  -#else
  -#include "/usr/include/fts.h"
  -#endif
  +#define  fts_openFts_open
  +#define  fts_readFts_read
  +#define  fts_set Fts_set
  +#define  fts_close   Fts_close
   
  -#include 
   #include 
  -#include 
  -#include 
  -#include 
   #include 
  -#include 
   
   #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
   #include 
  @@ -83,6 +56,8 @@
   #define  lchmod(_fn, _mode)  chmod((_fn), (_mode))
   #endif
   
  +#include "debug.h"
  +
   #if !defined(TIMESPEC_TO_TIMEVAL)
   #define TIMESPEC_TO_TIMEVAL(tv, ts) \
   do {\
  @@ -106,8 +81,52 @@
   *--(p).p_end = 0;\
   }
   
  +/*==*/
  +
  +#define  _KFB(n) (1U << (n))
  +#define  _MFB(n) (_KFB(n) | 0x4000)
  +
  +/**
  + * Bit field enum for copy CLI options.
  + */
  +enum copyFlags_e {
  +COPY_FLAGS_NONE  = 0,
  +COPY_FLAGS_FOLLOWARGS= _MFB( 0), /*!< -H ... */
  +COPY_FLAGS_FOLLOW= _MFB( 1), /*!< -L ... */
  +COPY_FLAGS_RECURSE   = _MFB( 2), /*!< -R ... */
  +COPY_FLAGS_ARCHIVE   = _MFB( 3), /*!< -a ... */
  +COPY_FLAGS_FORCE = _MFB( 4), /*!< -f ... */
  +COPY_FLAGS_INTERACTIVE   = _MFB( 5), /*!< -i ... */
  +COPY_FLAGS_HARDLINK  = _MFB( 6), /*!< -l ... */
  +COPY_FLAGS_NOCLOBBER = _MFB( 7), /*!< -n ... */
  +COPY_FLAGS_PRESERVE  = _MFB( 8), /*!< -p ... */
  +
  +COPY_FLAGS_VERBOSE   = _MFB( 9), /*!< -v ... */
  + /* 10-31 unused */
  +};
  +
  +static enum copyFlags_e copyFlags;
  +#define CP_ISSET(_FLAG) ((copyFlags & ((COPY_FLAGS_##_FLAG) & ~0x4000)) 
!= COPY_FLAGS_NONE)
  +
  +static int fts_options;
  +
   static char emptystring[] = "";
   
  +/*
  + * Cp copies source files to target files.
  + *
  + * The global PATH_T structure "to" always contains the path to the
  + * current target file.  Since fts(3) does not change directories,
  + * this path can be either absolute or dot-relative.
  + *
  + * The basic algorithm is to initialize "to" and use fts(3) to traverse
  + * the file hierarchy rooted in the argument list.  A trivial case is the
  + * case of 'cp file1 file2'.  The more interesting case is the case of
  + * 'cp file1 file2 ... fileN dir' where the hierarchy is traversed and the
  + * path (relative to the root of the traversal) is appended to dir (stored
  + * in "to") to form the final target path.
  + */
  +
   typedef struct {
char*p_end; /* pointer to NULL at end of path */
char*target_end;/* pointer to end of target base */
  @@ -116,8 +135,6 @@
   
   static PATH_T to = { to.p_path, emptystring, "" };
   
  -static int fflag, iflag, lflag, nflag, pflag, vflag;
  -static int Rflag, rflag;
   static volatile sig_atomic_t info;
   
   enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
  @@ -150,21 +167,21 @@

[CVS] RPM: rpm/tools/ cp.c

2009-09-01 Thread Jeff Johnson
  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  

  Server: rpm5.org Name:   Jeff Johnson
  Root:   /v/rpm/cvs   Email:  j...@rpm5.org
  Module: rpm  Date:   02-Sep-2009 00:00:55
  Branch: HEAD Handle: 2009090122005500

  Modified files:
rpm/tools   cp.c

  Log:
- cp(1) porting.

  Summary:
RevisionChanges Path
2.2 +388 -441   rpm/tools/cp.c
  

  patch -p0 <<'@@ .'
  Index: rpm/tools/cp.c
  
  $ cvs diff -u -r2.1 -r2.2 cp.c
  --- rpm/tools/cp.c1 Sep 2009 21:20:19 -   2.1
  +++ rpm/tools/cp.c1 Sep 2009 22:00:55 -   2.2
  @@ -47,61 +47,40 @@
* in "to") to form the final target path.
*/
   
  +#include 
  +#include 
   #include 
   #include 
   #include 
   
   #include 
   #include 
  +#include 
  +
   #ifdef   NOTYET
   #include 
   #else
   #include "/usr/include/fts.h"
   #endif
  +
   #include 
   #include 
   #include 
   #include 
   #include 
  +#include 
   #include 
   
  -#if defined(__linux__)
  -#include 
  -
  -/*
  - * Copy src to string dst of size siz.  At most siz-1 characters
  - * will be copied.  Always NUL terminates (unless siz == 0).
  - * Returns strlen(src); if retval >= siz, truncation occurred.
  - */
  -static size_t
  -strlcpy(char * __restrict dst, const char * __restrict src, size_t siz)
  -{
  - char *d = dst;
  - const char *s = src;
  - size_t n = siz;
  -
  - /* Copy as many bytes as will fit */
  - if (n != 0) {
  - while (--n != 0) {
  - if ((*d++ = *s++) == '\0')
  - break;
  - }
  - }
  -
  - /* Not enough room in dst, add NUL and traverse rest of src */
  - if (n == 0) {
  - if (siz != 0)
  - *d = '\0';  /* NUL-terminate dst */
  - while (*s++)
  - ;
  - }
  -
  - return(s - src - 1);/* count does not include NUL */
  -}
  +#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
  +#include 
   #endif
   
  -#if !defined(MAXPHYS)
  -#define  MAXPHYS (128 * 1024)/* max raw I/O transfer size */
  +#if defined(__linux__)
  +#include 
  +#define st_atimespecst_atim
  +#define st_mtimespecst_mtim
  +/* XXX FIXME */
  +#define  lchmod(_fn, _mode)  chmod((_fn), (_mode))
   #endif
   
   #if !defined(TIMESPEC_TO_TIMEVAL)
  @@ -118,22 +97,16 @@
   #undef  HAVE_ST_FLAGS   /* XXX TODO: should be AutoFu test */
   #endif
   
  -#if defined(__linux__)
  -#define st_atimespecst_atim
  -#define st_mtimespecst_mtim
  -/* XXX FIXME */
  -#define  lchmod(_fn, _mode)  chmod((_fn), (_mode))
  -#endif
  -
   #if !defined(S_ISTXT) && defined(S_ISVTX)   /* XXX linux != BSD */
   #define S_ISTXT S_ISVTX
   #endif
   
  -#if !defined(__unused)
  -#define __unused __attribute__((__unused__))
  -#endif
  +#define  STRIP_TRAILING_SLASH(p) {   
\
  +while ((p).p_end > (p).p_path + 1 && (p).p_end[-1] == '/')   \
  +*--(p).p_end = 0;\
  +}
   
  -/* - extern.h */
  +static char emptystring[] = "";
   
   typedef struct {
char*p_end; /* pointer to NULL at end of path */
  @@ -141,32 +114,20 @@
charp_path[PATH_MAX];   /* pointer to the start of a path */
   } PATH_T;
   
  -extern PATH_T to;
  -extern int fflag, iflag, lflag, nflag, pflag, vflag;
  -extern volatile sig_atomic_t info;
  -
  -__BEGIN_DECLS
  -int  copy_fifo(struct stat *, int);
  -int  copy_file(const FTSENT *, int);
  -int  copy_link(const FTSENT *, int);
  -int  copy_special(struct stat *, int);
  -int  setfile(struct stat *, int);
  -int  preserve_dir_acls(struct stat *, char *, char *);
  -int  preserve_fd_acls(int, int);
  -void usage(void);
  -__END_DECLS
  +static PATH_T to = { to.p_path, emptystring, "" };
  +
  +static int fflag, iflag, lflag, nflag, pflag, vflag;
  +static int Rflag, rflag;
  +static volatile sig_atomic_t info;
  +
  +enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
   
   /* - utils.c */
   
  -#include 
  -#include 
  -#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
  -#include 
  +#if !defined(MAXPHYS)
  +#define  MAXPHYS (128 * 1024)/* max raw I/O transfer size */
   #endif
   
  -#include 
  -#include 
  -
   #define  cp_pct(x, y)((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
   
   /* Memory strategy threshold, in pages: if physmem is larger then this, use 
a 
  @@ -180,7 +141,153 @@
* smaller than MAXPHYS */
   #define BUFSIZE_SMALL (MAXPHYS)
   
  -int
  +static int
  +preserve