RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  [email protected]
  Module: rpm                              Date:   26-Mar-2010 15:10:33
  Branch: HEAD                             Handle: 2010032614103200

  Modified files:
    rpm/tools               .cvsignore nix-channel.c nix-copy-closure.c
                            nix-install-package.c nix-prefetch-url.c
                            nix-pull.c nix-push.c

  Log:
    - nix: WIP.

  Summary:
    Revision    Changes     Path
    1.45        +2  -0      rpm/tools/.cvsignore
    2.3         +17 -2      rpm/tools/nix-channel.c
    2.4         +2  -2      rpm/tools/nix-copy-closure.c
    2.2         +214 -95    rpm/tools/nix-install-package.c
    2.6         +3  -3      rpm/tools/nix-prefetch-url.c
    2.7         +37 -73     rpm/tools/nix-pull.c
    2.6         +22 -8      rpm/tools/nix-push.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/tools/.cvsignore
  ============================================================================
  $ cvs diff -u -r1.44 -r1.45 .cvsignore
  --- rpm/tools/.cvsignore      24 Mar 2010 18:42:00 -0000      1.44
  +++ rpm/tools/.cvsignore      26 Mar 2010 14:10:32 -0000      1.45
  @@ -17,6 +17,8 @@
   grep
   mtree
   nix-build
  +nix-channel
  +nix-collect-garbage
   nix-copy-closure
   nix-hash
   nix-install-package
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/nix-channel.c
  ============================================================================
  $ cvs diff -u -r2.2 -r2.3 nix-channel.c
  --- rpm/tools/nix-channel.c   26 Mar 2010 00:09:17 -0000      2.2
  +++ rpm/tools/nix-channel.c   26 Mar 2010 14:10:32 -0000      2.3
  @@ -34,7 +34,7 @@
       RPMNIX_FLAGS_STRICT              = _DFB(20),     /*    --strict */
       RPMNIX_FLAGS_SHOWTRACE   = _DFB(21),     /*    --show-trace */
   
  -    RPMNIX_FLAGS_SKIPWRONGSTORE      = _DFB(30)      /*    
--skip-wrong-store */
  +    RPMNIX_FLAGS_SKIPWRONGSTORE      = _DFB(24)      /*    
--skip-wrong-store */
   };
   
   /**
  @@ -76,8 +76,18 @@
   static const char * stateDir = "/nix/var/nix";
   static const char * rootsDir = "/nix/var/nix/gcroots";
   
  +static const char * channelCache;
  +
   #define      DBG(_l) if (_debug) fprintf _l
   /*==============================================================*/
  +
  +static char * _freeCmd(const char * cmd)
  +{
  +DBG((stderr, "\t%s\n", cmd));
  +    cmd = _free(cmd);
  +    return NULL;
  +}
  +
   /* Reads the list of channels from the file $channelsList. */
   static void readChannels(rpmnix nix)
        /*...@*/
  @@ -251,7 +261,7 @@
            }
            rval = _free(rval);
   #endif
  -         cmd = _free(cmd);
  +         cmd = _freeCmd(cmd);
        }
       }
       dn = _free(dn);
  @@ -405,6 +415,7 @@
       int ac = argvCount(av);
       const char * s;
       int ec = 1;              /* assume failure */
  +    int xx;
   
       if ((s = getenv("NIX_BIN_DIR"))) binDir = s;
       if ((s = getenv("NIX_STATE_DIR"))) stateDir = s;
  @@ -417,6 +428,10 @@
   $ENV{'NIX_DOWNLOAD_CACHE'} = $channelCache if -W $channelCache;
   */
   #endif
  +    channelCache = rpmGetPath(stateDir, "/channel-cache", NULL);
  +    xx = rpmioMkpath(channelCache, 0755, (uid_t)-1, (gid_t)-1);
  +    if (!Access(channelCache, W_OK))
  +     xx = setenv("NIX_DOWNLOAD_CACHE", channelCache, 0);
   
       /* Figure out the name of the `.nix-channels' file to use. */
       if ((s = getenv("HOME"))) homeDir = s;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/nix-copy-closure.c
  ============================================================================
  $ cvs diff -u -r2.3 -r2.4 nix-copy-closure.c
  --- rpm/tools/nix-copy-closure.c      26 Mar 2010 00:09:17 -0000      2.3
  +++ rpm/tools/nix-copy-closure.c      26 Mar 2010 14:10:32 -0000      2.4
  @@ -30,8 +30,8 @@
       RPMNIX_FLAGS_STRICT              = _DFB(20),     /*    --strict */
       RPMNIX_FLAGS_SHOWTRACE   = _DFB(21),     /*    --show-trace */
   
  -    RPMNIX_FLAGS_SIGN                = _DFB(29),     /*    --sign */
  -    RPMNIX_FLAGS_GZIP                = _DFB(30)      /*    --gzip */
  +    RPMNIX_FLAGS_SIGN                = _DFB(24),     /*    --sign */
  +    RPMNIX_FLAGS_GZIP                = _DFB(25)      /*    --gzip */
   };
   
   /**
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/nix-install-package.c
  ============================================================================
  $ cvs diff -u -r2.1 -r2.2 nix-install-package.c
  --- rpm/tools/nix-install-package.c   24 Mar 2010 16:35:21 -0000      2.1
  +++ rpm/tools/nix-install-package.c   26 Mar 2010 14:10:32 -0000      2.2
  @@ -9,6 +9,8 @@
   
   #include "debug.h"
   
  +static int _debug = -1;
  +
   #define _KFB(n) (1U << (n))
   #define _DFB(n) (_KFB(n) | 0x40000000)
   
  @@ -30,7 +32,7 @@
       RPMNIX_FLAGS_STRICT              = _DFB(20),     /*    --strict */
       RPMNIX_FLAGS_SHOWTRACE   = _DFB(21),     /*    --show-trace */
   
  -    RPMNIX_FLAGS_INTERACTIVE = _DFB(30)      /*    --non-interactive */
  +    RPMNIX_FLAGS_INTERACTIVE = _DFB(24)      /*    --non-interactive */
   };
   
   /**
  @@ -61,7 +63,119 @@
        .flags = RPMNIX_FLAGS_INTERACTIVE
   };
   
  +static const char * tmpDir;
  +static const char * binDir   = "/usr/bin";
  +
  +#define DBG(_l) if (_debug) fprintf _l
   /*==============================================================*/
  +
  +static char * _freeCmd(const char * cmd)
  +{
  +DBG((stderr, "\t%s\n", cmd));
  +    cmd = _free(cmd);
  +    return NULL;
  +}
  +
  +#ifdef       REFERENCE
  +/*
  +sub barf {
  +    my $msg = shift;
  +    print "$msg\n";
  +    <STDIN> if $interactive;
  +    exit 1;
  +}
  +*/
  +#endif
  +
  +/*==============================================================*/
  +
  +#ifdef       UNUSED
  +static int verbose = 0;
  +#endif
  +
  +static void nixInstantiateArgCallback(poptContext con,
  +                /*...@unused@*/ enum poptCallbackReason reason,
  +                const struct poptOption * opt, const char * arg,
  +                /*...@unused@*/ void * data)
  +     /*...@*/
  +{
  +#ifdef       UNUSED
  +    rpmnix nix = &_nix;
  +#endif
  +
  +    /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
  +    if (opt->arg == NULL)
  +    switch (opt->val) {
  +    default:
  +     fprintf(stderr, _("%s: Unknown callback(0x%x)\n"), __FUNCTION__, 
(unsigned) opt->val);
  +     poptPrintUsage(con, stderr, 0);
  +     /*...@-exitarg@*/ exit(2); /*...@=exitarg@*/
  +     /*...@notreached@*/ break;
  +    }
  +}
  +
  +static struct poptOption nixInstantiateOptions[] = {
  +/*...@-type@*/ /* FIX: cast? */
  + { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | 
POPT_CBFLAG_CONTINUE,
  +     nixInstantiateArgCallback, 0, NULL, NULL },
  +/*...@=type@*/
  +
  + { "profile", 'p', POPT_ARG_ARGV,    &_nix.profiles, 0,
  +     N_("FIXME"), NULL },
  + { "non-interactive", '\0', POPT_BIT_CLR, &_nix.flags, 
RPMNIX_FLAGS_INTERACTIVE,
  +     N_("FIXME"), NULL },
  + { "url", '\0', POPT_ARG_STRING,     &_nix.url, 0,
  +     N_("FIXME"), NULL },
  +
  +#ifdef       NOTYET
  + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0,
  +     N_("Common options for all rpmio executables:"), NULL },
  +#endif
  +
  +  POPT_AUTOHELP
  +
  +  { NULL, (char)-1, POPT_ARG_INCLUDE_TABLE, NULL, 0,
  +     N_("\
  +Usage: nix-install-package (FILE | --url URL)\n\
  +\n\
  +Install a Nix Package (.nixpkg) either directly from FILE or by\n\
  +downloading it from URL.\n\
  +\n\
  +Flags:\n\
  +  --profile / -p LINK: install into the specified profile\n\
  +  --non-interactive: don't run inside a new terminal\n\
  +"), NULL },
  +
  +  POPT_TABLEEND
  +};
  +
  +int
  +main(int argc, char *argv[])
  +{
  +    rpmnix nix = &_nix;
  +    poptContext optCon = rpmioInit(argc, argv, nixInstantiateOptions);
  +    int ec = 1;              /* assume failure */
  +    const char * rval;
  +    const char * cmd;
  +    const char * s;
  +#ifdef       UNUSED
  +    ARGV_t av = poptGetArgs(optCon);
  +    int ac = argvCount(av);
  +#endif
  +    int xx;
  +
  +const char * version = "?version?";
  +const char * manifestURL= "?manifestURL?";
  +const char * drvName = "?drvName?";
  +const char * system  = "?system?";
  +const char * drvPath = "?drvPath?";
  +const char * outPath = "?outPath?";
  +
  +const char * source  = "?source?";
  +const char * pkgFile = "?pkgFile?";
  +
  +const char ** extraNixEnvArgs = NULL;
  +
   #ifdef       REFERENCE
   /*
   #! /usr/bin/perl -w
  @@ -70,8 +184,12 @@
   use File::Temp qw(tempdir);
   
   my $binDir = $ENV{"NIX_BIN_DIR"} || "/usr/bin";
  +*/
  +#endif
  +    if ((s = getenv("NIX_BIN_DIR"))) binDir = s;
   
  -
  +#ifdef       REFERENCE
  +/*
   sub usageError {
       print STDERR <<EOF;
   Usage: nix-install-package (FILE | --url URL)
  @@ -120,31 +238,43 @@
   
   usageError unless defined $source;
   
  +*/
  +#endif
   
  -# Re-execute in a terminal, if necessary, so that if we're executed
  -# from a web browser, the user gets to see us.
  -if ($interactive && !defined $ENV{"NIX_HAVE_TERMINAL"}) {
  +    /*
  +     * Re-execute in a terminal, if necessary, so that if we're executed
  +     * from a web browser, the user gets to see us.
  +     */
  +    if (F_ISSET(nix, INTERACTIVE) && (s=getenv("NIX_HAVE_TERMINAL")) == 
NULL) {
  +#ifdef       REFERENCE
  +/*
       $ENV{"NIX_HAVE_TERMINAL"} = "1";
       $ENV{"LD_LIBRARY_PATH"} = "";
       foreach my $term ("xterm", "konsole", "gnome-terminal", "xterm") {
           exec($term, "-e", "$binDir/nix-install-package", @ARGV);
       }
       die "cannot execute `xterm'";
  -}
  +*/
  +#endif
  +    }
   
   
  +#ifdef       REFERENCE
  +/*
   my $tmpDir = tempdir("nix-install-package.XXXXXX", CLEANUP => 1, TMPDIR => 1)
       or die "cannot create a temporary directory";
  +*/
  +#endif
  +    if (!((s = getenv("TMPDIR")) != NULL && *s != '\0'))
  +     s = "/tmp";
  +    tmpDir = mkdtemp(rpmGetPath(s, "/nix-pull.XXXXXX", NULL));
  +    if (tmpDir == NULL) {
  +     fprintf(stderr, _("cannot create a temporary directory\n"));
  +     goto exit;
  +    }
   
  -
  -sub barf {
  -    my $msg = shift;
  -    print "$msg\n";
  -    <STDIN> if $interactive;
  -    exit 1;
  -}
  -
  -
  +#ifdef       REFERENCE
  +/*
   # Download the package description, if necessary.
   my $pkgFile = $source;
   if ($fromURL) {
  @@ -152,13 +282,21 @@
       system("/usr/bin/curl", "--silent", $source, "-o", $pkgFile) == 0
           or barf "curl failed: $?";
   }
  +*/
  +#endif
   
   
  +#ifdef       REFERENCE
  +/*
   # Read and parse the package file.
   open PKGFILE, "<$pkgFile" or barf "cannot open `$pkgFile': $!";
   my $contents = <PKGFILE>;
   close PKGFILE;
  +*/
  +#endif
   
  +#ifdef       REFERENCE
  +/*
   my $urlRE = "(?: 
[a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\...@\&\=\+\$\,\-\_\.\!\~\*\']+ 
)";
   my $nameRE = "(?: [A-Za-z0-9\+\-\.\_\?\=]+ )"; # see checkStoreName()
   my $systemRE = "(?: [A-Za-z0-9\+\-\_]+ )";
  @@ -176,117 +314,98 @@
   my $system = $4;
   my $drvPath = $5;
   my $outPath = $6;
  +*/
  +#endif
   
  +#ifdef       REFERENCE
  +/*
   barf "invalid package version `$version'" unless $version eq "NIXPKG1";
  +*/
  +#endif
   
   
  -if ($interactive) {
  -    # Ask confirmation.
  +    if (F_ISSET(nix, INTERACTIVE)) {
  +     /* Ask confirmation. */
  +#ifdef       REFERENCE
  +/*
       print "Do you want to install `$drvName' (Y/N)? ";
       my $reply = <STDIN>;
       chomp $reply;
       exit if $reply ne "y" && $reply ne "Y";
  -}
  +*/
  +#endif
  +    }
   
   
  -# Store the manifest in the temporary directory so that we don't
  -# pollute /nix/var/nix/manifests.
  +    /*
  +     * Store the manifest in the temporary directory so that we don't
  +     * pollute /nix/var/nix/manifests.
  +     */
  +#ifdef       REFERENCE
  +/*
   $ENV{NIX_MANIFESTS_DIR} = $tmpDir;
  +*/
  +#endif
  +    xx = setenv("NIX_MANIFEST_DIR", tmpDir, 1);
   
   
  -print "\nPulling manifests...\n";
  +    fprintf(stdout, "\nPulling manifests...\n");
  +#ifdef       REFERENCE
  +/*
   system("$binDir/nix-pull", $manifestURL) == 0
       or barf "nix-pull failed: $?";
  +*/
  +#endif
  +    cmd = rpmExpand(binDir, "/nix-pull ", manifestURL, "; echo $?", NULL);
  +    rval = rpmExpand("%(", cmd, ")", NULL);
  +    if (strcmp(rval, "0")) {
  +     fprintf(stderr, "nix-pull failed: %s\n", rval);
  +     goto exit;
  +    }
  +    rval = _free(rval);
  +    cmd = _freeCmd(cmd);
   
   
  -print "\nInstalling package...\n";
  +    fprintf(stdout, "\nInstalling package...\n");
  +#ifdef       REFERENCE
  +/*
   system("$binDir/nix-env", "--install", $outPath, "--force-name", $drvName, 
@extraNixEnvArgs) == 0
       or barf "nix-env failed: $?";
  +*/
  +#endif
  +    s = argvJoin(extraNixEnvArgs, ' ');
  +    cmd = rpmExpand(binDir, "/nix-env --install ", outPath,
  +                     " --force-name ", drvName, " ", s, "; echo $?", NULL);
  +    s = _free(s);
  +    rval = rpmExpand("%(", cmd, ")", NULL);
  +    if (strcmp(rval, "0")) {
  +     fprintf(stderr, "nix-env failed: %s\n", rval);
  +     goto exit;
  +    }
  +    rval = _free(rval);
  +    cmd = _freeCmd(cmd);
   
   
  -if ($interactive) {
  +    if (F_ISSET(nix, INTERACTIVE)) {
  +#ifdef       REFERENCE
  +/*
       print "\nInstallation succeeded! Press Enter to continue.\n";
       <STDIN>;
  -}
   */
   #endif
  -
  -/*==============================================================*/
  -
  -#ifdef       UNUSED
  -static int verbose = 0;
  -#endif
  -
  -static void nixInstantiateArgCallback(poptContext con,
  -                /*...@unused@*/ enum poptCallbackReason reason,
  -                const struct poptOption * opt, const char * arg,
  -                /*...@unused@*/ void * data)
  -     /*...@*/
  -{
  -#ifdef       UNUSED
  -    rpmnix nix = &_nix;
  -#endif
  -
  -    /* XXX avoid accidental collisions with POPT_BIT_SET for flags */
  -    if (opt->arg == NULL)
  -    switch (opt->val) {
  -    default:
  -     fprintf(stderr, _("%s: Unknown callback(0x%x)\n"), __FUNCTION__, 
(unsigned) opt->val);
  -     poptPrintUsage(con, stderr, 0);
  -     /*...@-exitarg@*/ exit(2); /*...@=exitarg@*/
  -     /*...@notreached@*/ break;
       }
  -}
  -
  -static struct poptOption nixInstantiateOptions[] = {
  -/*...@-type@*/ /* FIX: cast? */
  - { NULL, '\0', POPT_ARG_CALLBACK | POPT_CBFLAG_INC_DATA | 
POPT_CBFLAG_CONTINUE,
  -     nixInstantiateArgCallback, 0, NULL, NULL },
  -/*...@=type@*/
  -
  - { "profile", 'p', POPT_ARG_ARGV,    &_nix.profiles, 0,
  -     N_("FIXME"), NULL },
  - { "non-interactive", '\0', POPT_BIT_CLR, &_nix.flags, 
RPMNIX_FLAGS_INTERACTIVE,
  -     N_("FIXME"), NULL },
  - { "url", '\0', POPT_ARG_STRING,     &_nix.url, 0,
  -     N_("FIXME"), NULL },
   
  -#ifdef       NOTYET
  - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0,
  -     N_("Common options for all rpmio executables:"), NULL },
  -#endif
  -
  -  POPT_AUTOHELP
  -
  -  { NULL, (char)-1, POPT_ARG_INCLUDE_TABLE, NULL, 0,
  -     N_("\
  -Usage: nix-install-package (FILE | --url URL)\n\
  -\n\
  -Install a Nix Package (.nixpkg) either directly from FILE or by\n\
  -downloading it from URL.\n\
  -\n\
  -Flags:\n\
  -  --profile / -p LINK: install into the specified profile\n\
  -  --non-interactive: don't run inside a new terminal\n\
  -"), NULL },
  +    ec = 0;  /* XXX success */
   
  -  POPT_TABLEEND
  -};
  +exit:
   
  -int
  -main(int argc, char *argv[])
  -{
  -    rpmnix nix = &_nix;
  -    poptContext optCon = rpmioInit(argc, argv, nixInstantiateOptions);
  -    int ec = 1;              /* assume failure */
  -#ifdef       UNUSED
  -    ARGV_t av = poptGetArgs(optCon);
  -    int ac = argvCount(av);
  -    int xx;
  +#ifdef       REFERENCE
  +/*
  +my $tmpDir = tempdir("nix-install-package.XXXXXX", CLEANUP => 1, TMPDIR => 1)
  +    or die "cannot create a temporary directory";
  +*/
   #endif
   
  -    ec = 0;  /* XXX success */
  -
       nix->profiles = argvFree(nix->profiles);
   
       optCon = rpmioFini(optCon);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/nix-prefetch-url.c
  ============================================================================
  $ cvs diff -u -r2.5 -r2.6 nix-prefetch-url.c
  --- rpm/tools/nix-prefetch-url.c      26 Mar 2010 00:09:17 -0000      2.5
  +++ rpm/tools/nix-prefetch-url.c      26 Mar 2010 14:10:32 -0000      2.6
  @@ -32,7 +32,6 @@
       RPMNIX_FLAGS_STRICT              = _DFB(20),     /*    --strict */
       RPMNIX_FLAGS_SHOWTRACE   = _DFB(21),     /*    --show-trace */
   
  -    RPMNIX_FLAGS_SKIPWRONGSTORE      = _DFB(30)      /*    
--skip-wrong-store */
   };
   
   /**
  @@ -95,6 +94,7 @@
       cmd = _free(cmd);
       return NULL;
   }
  +
   /**
    * Copy source string to target, substituting for URL characters.
    * @param t          target xml string
  @@ -176,7 +176,7 @@
       rval = rpmExpand("%(", cmd, ")", NULL);
       rval = _free(rval);
   
  -DBG((stderr, "<-- %s(%p)\n\t%s\n", __FUNCTION__, nix, cmd));
  +DBG((stderr, "<-- %s(%p)\n", __FUNCTION__, nix));
   
       cmd = _freeCmd(cmd);
   }
  @@ -320,7 +320,7 @@
        s = _free(s);
   
        fn = rpmGetPath(nix->tmpPath, "/urls", NULL);
  -     fd = Fopen(fn, "r");
  +     fd = Fopen(fn, "r.fpio");
        if (fd == NULL || Ferror(fd)) {
            fprintf(stderr, _("Fopen(%s, \"r\") failed\n"), fn);
            if (fd) xx = Fclose(fd);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/nix-pull.c
  ============================================================================
  $ cvs diff -u -r2.6 -r2.7 nix-pull.c
  --- rpm/tools/nix-pull.c      26 Mar 2010 00:09:17 -0000      2.6
  +++ rpm/tools/nix-pull.c      26 Mar 2010 14:10:32 -0000      2.7
  @@ -33,7 +33,7 @@
       RPMNIX_FLAGS_STRICT              = _DFB(20),     /*    --strict */
       RPMNIX_FLAGS_SHOWTRACE   = _DFB(21),     /*    --show-trace */
   
  -    RPMNIX_FLAGS_SKIPWRONGSTORE      = _DFB(30)      /*    
--skip-wrong-store */
  +    RPMNIX_FLAGS_SKIPWRONGSTORE      = _DFB(24)      /*    
--skip-wrong-store */
   };
   
   /**
  @@ -68,14 +68,22 @@
   };
   
   static const char * tmpDir;
  -static const char * binDir = "/usr/bin";
  -static const char * libexecDir = "/usr/libexec";
  -static const char * storeDir = "/nix/store";
  -static const char * stateDir = "/nix/var/nix";
  +static const char * binDir   = "/usr/bin";
  +static const char * libexecDir       = "/usr/libexec";
  +static const char * storeDir = "/nix/store";
  +static const char * stateDir = "/nix/var/nix";
   static const char * manifestDir;
   
   #define      DBG(_l) if (_debug) fprintf _l
   /*==============================================================*/
  +
  +static char * _freeCmd(const char * cmd)
  +{
  +DBG((stderr, "\t%s\n", cmd));
  +    cmd = _free(cmd);
  +    return NULL;
  +}
  +
   static int addPatch(rpmnix nix, const char * storePath, const char * patch)
        /*...@*/
   {
  @@ -280,42 +288,33 @@
   
   /*==============================================================*/
   
  -#ifdef       REFERENCE
  -/*
  -# Process the URLs specified on the command line.
  -my %narFiles;
  -my %localPaths;
  -my %patches;
  -
  -my $skipWrongStore = 0;
  -*/
  -#endif
  -
   static char * downloadFile(rpmnix nix, const char * url)
        /*...@*/
   {
       const char * cmd;
       const char * rval;
       char * path;
  +    int xx;
   
  +    xx = setenv("PRINT_PATH", "1", 0);
  +    xx = setenv("QUIET", "1", 0);
  +    cmd = rpmExpand(binDir, "/nix-prefetch-url '", url, "'", NULL);
  +
  +    rval = rpmExpand("%(", cmd, ")", NULL);
  +    /* XXX The 1st line is the hash, the 2nd line is the path ... */
  +    if ((path = strchr(rval, '\n')) == NULL) {
  +     fprintf(stderr, "nix-prefetch-url did not return a path");
  +     exit(1);
  +    }
   #ifdef       REFERENCE
   /*
  -    $ENV{"PRINT_PATH"} = 1;
  -    $ENV{"QUIET"} = 1;
  -    my ($dummy, $path) = `$binDir/nix-prefetch-url '$url'`;
  -    die "cannot fetch `$url'" if $? != 0;
  -    die "nix-prefetch-url did not return a path" unless defined $path;
       chomp $path;
  -}
   */
   #endif
  -    cmd = rpmExpand(binDir, "/nix-prefetch-url '", url, "'", NULL);
  -
  -    rval = rpmExpand("%(", cmd, ")", NULL);
  -    path = xstrdup(rval);
  +    path = xstrdup(path+1);
  +DBG((stderr, "<-- %s(%p, \"%s\") path %s\n", __FUNCTION__, nix, url, path));
       rval = _free(rval);
  -DBG((stderr, "<-- %s(%p, \"%s\") cmd: %s\n", __FUNCTION__, nix, url, cmd));
  -    cmd = _free(cmd);
  +    cmd = _freeCmd(cmd);
       return path;
   }
   
  @@ -325,7 +324,7 @@
       const char * cmd;
       const char * rval;
       int version;
  -    const char * baseName = "unnamed";
  +    const char * baseName;
       const char * urlFile;
       const char * finalPath;
       const char * hash;
  @@ -372,23 +371,17 @@
        cmd = rpmExpand("/usr/libexec/nix/bunzip2 < ", bzipped,
                " > ", manifest, "; echo $?", NULL);
        rval = rpmExpand("%(", cmd, ")", NULL);
  -     cmd = _free(cmd);
        if (strcmp(rval, "0")) {
            fprintf(stderr, "cannot decompress manifest\n");
            exit(1);
        }
        rval = _free(rval);
  +     cmd = _freeCmd(cmd);
   
  -#ifdef       REFERENCE
  -/*
  -        $manifest = (`$binDir/nix-store --add $manifest`
  -                     or die "cannot copy $manifest to the store");
  -*/
  -#endif
        cmd = rpmExpand(binDir, "/nix-store --add ", manifest, NULL);
        manifest = _free(manifest);
        manifest = rpmExpand("%(", cmd, ")", NULL);
  -     cmd = _free(cmd);
  +     cmd = _freeCmd(cmd);
   
   #ifdef       REFERENCE
   /*
  @@ -433,7 +426,7 @@
   
       cmd = rpmExpand(binDir, "/nix-hash --flat ", manifest, NULL);
       hash = rpmExpand("%(", cmd, ")", NULL);
  -    cmd = _free(cmd);
  +    cmd = _freeCmd(cmd);
       if (hash == NULL) {
        fprintf(stderr, "cannot hash `%s'\n", manifest);
        exit(1);
  @@ -454,8 +447,6 @@
        exit(1);
       }
       (void) Fwrite(url, 1, strlen(url), fd);
  -    /* XXX why bother with a newline chomp?!? */
  -    (void) Fwrite("\n", 1, 1, fd);
       xx = Fclose(fd);
       
       finalPath = rpmGetPath(manifestDir, "/",
  @@ -485,7 +476,7 @@
                continue;
   
            uav = NULL;
  -         fd = Fopen(urlFile2, "r");
  +         fd = Fopen(urlFile2, "r.fpio");
            if (fd == NULL || Ferror(fd)) {
                fprintf(stderr, "cannot create `%s'\n", urlFile2);
                if (fd) xx = Fclose(fd);
  @@ -493,7 +484,6 @@
            }
            xx = argvFgets(&uav, fd);
            xx = Fclose(fd);
  -         /* XXX why bother with a newline chomp?!? */
            url2 = xstrdup(uav[0]);
            uav = argvFree(uav);
   
  @@ -557,16 +547,18 @@
    { "skip-wrong-store", '\0', POPT_BIT_SET,   &_nix.flags, 
RPMNIX_FLAGS_SKIPWRONGSTORE,
        N_("FIXME"), NULL },
   
  -#ifdef       NOTYET
  +#ifndef      NOTYET
    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0,
        N_("Common options for all rpmio executables:"), NULL },
   #endif
   
     POPT_AUTOHELP
   
  +#ifdef       DYING
     { NULL, (char)-1, POPT_ARG_INCLUDE_TABLE, NULL, 0,
        N_("\
   "), NULL },
  +#endif
   
     POPT_TABLEEND
   };
  @@ -583,17 +575,6 @@
       int xx;
       int i;
   
  -#ifdef       REFERENCE
  -/*
  -#! /usr/bin/perl -w -I/usr/libexec/nix
  -
  -use strict;
  -use File::Temp qw(tempdir);
  -use readmanifest;
  -
  -*/
  -#endif
  -
       if (!((s = getenv("TMPDIR")) != NULL && *s != '\0'))
        s = "/tmp";
       tmpDir = mkdtemp(rpmGetPath(s, "/nix-pull.XXXXXX", NULL));
  @@ -620,29 +601,12 @@
        goto exit;
       }
   
  -#ifdef       REFERENCE
  -/*
  -while (@ARGV) {
  -    my $url = shift @ARGV;
  -    if ($url eq "--skip-wrong-store") {
  -        $skipWrongStore = 1;
  -    } else {
  -        processURL $url;
  -    }
  -}
  -*/
  -#endif
  -
       for (i = 0; i < ac; i++) {
        xx = processURL(nix, av[i]);
       }
   
  -#ifdef       REFERENCE
  -/*
  -my $size = scalar (keys %narFiles) + scalar (keys %localPaths);
  -print "$size store paths in manifest\n";
  -*/
  -#endif
  +    fprintf(stdout, "%d store paths in manifest\n", 
  +             argvCount(nix->narFiles) + argvCount(nix->localPaths));
   
       ec = 0;  /* XXX success */
   
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/tools/nix-push.c
  ============================================================================
  $ cvs diff -u -r2.5 -r2.6 nix-push.c
  --- rpm/tools/nix-push.c      25 Mar 2010 18:56:21 -0000      2.5
  +++ rpm/tools/nix-push.c      26 Mar 2010 14:10:32 -0000      2.6
  @@ -9,6 +9,8 @@
   
   #include "debug.h"
   
  +static int _debug = -1;
  +
   
   #define _KFB(n) (1U << (n))
   #define _DFB(n) (_KFB(n) | 0x40000000)
  @@ -31,7 +33,7 @@
       RPMNIX_FLAGS_STRICT              = _DFB(20),     /*    --strict */
       RPMNIX_FLAGS_SHOWTRACE   = _DFB(21),     /*    --show-trace */
   
  -    RPMNIX_FLAGS_COPY                = _DFB(30)      /*    --copy */
  +    RPMNIX_FLAGS_COPY                = _DFB(24)      /*    --copy */
   };
   
   /**
  @@ -80,8 +82,16 @@
   
   static const char * dataDir = "/usr/share";
   
  +#define DBG(_l) if (_debug) fprintf _l
   /*==============================================================*/
   
  +static char * _freeCmd(const char * cmd)
  +{
  +DBG((stderr, "\t%s\n", cmd));
  +    cmd = _free(cmd);
  +    return NULL;
  +}
  +
   static void writeManifest(rpmnix nix, const char * manifest)
        /*...@*/
   {
  @@ -94,6 +104,8 @@
       ssize_t nw;
       int xx;
   
  +DBG((stderr, "--> %s(%p, \"%s\")\n", __FUNCTION__, nix, manifest));
  +
   #ifdef       REFERENCE
   /*
       my ($manifest, $narFiles, $patches) = @_;
  @@ -198,6 +210,7 @@
       const char * rval;
       const char * cmd;
   
  +DBG((stderr, "--> %s(\"%s\", \"%s\")\n", __FUNCTION__, src, dst));
       /* XXX Ick. */
       cmd = rpmExpand("/bin/cp '", src, "' '", tfn, "'; echo $?", NULL);
       rval = rpmExpand("%(", cmd, ")", NULL);
  @@ -220,6 +233,7 @@
   static int archiveExists(rpmnix nix, const char * name)
        /*...@*/
   {
  +DBG((stderr, "--> %s(%p, \"%s\")\n", __FUNCTION__, nix, name));
   #ifdef       REFERENCE
   /*
       my $name = shift;
  @@ -394,9 +408,9 @@
   #endif
        cmd = rpmExpand(binDir, "/nix-store --query --requisites 
--force-realise --include-outputs '", path, "'", NULL);
        rval = rpmExpand("%(", cmd, ")", NULL);
  -     cmd = _free(cmd);
        xx = argvSplit(&nix->storePaths, rval, NULL);
        rval = _free(rval);
  +     cmd = _freeCmd(cmd);
       }
   
       /*
  @@ -479,9 +493,9 @@
   #endif
       cmd = rpmExpand(binDir, "/nix-instantiate ", nixExpr, NULL);
       rval = rpmExpand("%(", cmd, ")", NULL);
  -    cmd = _free(cmd);
       xx = argvSplit(&nix->storeExprs, rval, NULL);
       rval = _free(rval);
  +    cmd = _freeCmd(cmd);
   
       /* Build the derivations. */
       fprintf(stderr, "creating archives...\n");
  @@ -528,9 +542,9 @@
   #endif
        cmd = rpmExpand(binDir, "/nix-store --realise ", tmp2, NULL);
        rval = rpmExpand("%(", cmd, ")", NULL);
  -     cmd = _free(cmd);
        xx = argvSplit(&nix->narPaths, rval, NULL);
        rval = _free(rval);
  +     cmd = _freeCmd(cmd);
   
       }
   
  @@ -568,7 +582,7 @@
        /* XXX Ick. */
        cmd = rpmExpand("/bin/cat ", narDir, "/narbz2-hash", NULL);
        narbz2Hash = rpmExpand("%(", cmd, ")", NULL);
  -     cmd = _free(cmd);
  +     cmd = _freeCmd(cmd);
   
   #ifdef       REFERENCE
   /*
  @@ -582,7 +596,7 @@
        /* XXX Ick. */
        cmd = rpmExpand("/bin/cat ", narDir, "/nar-hash", NULL);
        narbz2Hash = rpmExpand("%(", cmd, ")", NULL);
  -     cmd = _free(cmd);
  +     cmd = _freeCmd(cmd);
       
        narName = rpmExpand(narbz2Hash, ".nar.bz2", NULL);
        narFile = rpmGetPath(narDir, "/", narName, NULL);
  @@ -605,7 +619,7 @@
        cmd = rpmExpand(binDir, "/nix-store --query --references '",
                storePath, "'", NULL);
        references = rpmExpand("%(", cmd, ")", NULL);
  -     cmd = _free(cmd);
  +     cmd = _freeCmd(cmd);
   
   #ifdef       REFERENCE
   /*
  @@ -618,11 +632,11 @@
        cmd = rpmExpand(binDir, "/nix-store --query --deriver '",
                storePath, "'", NULL);
        deriver = rpmExpand("%(", cmd, ")", NULL);
  -     cmd = _free(cmd);
        if (!strcmp(deriver, "unknown-deriver")) {
            deriver = _free(deriver);
            deriver = xstrdup("");
        }
  +     cmd = _freeCmd(cmd);
   
        if (localCopy)
            url = rpmGetPath(nix->targetArchivesUrl, "/", narName, NULL);
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to