VirtualBox

Changeset 3131 in kBuild for trunk/src


Ignore:
Timestamp:
Feb 9, 2018 1:19:39 PM (7 years ago)
Author:
bird
Message:
kmk_md5sum: Added -mmanifest option to generate the fetch manifest syntax kBuild uses.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/md5sum.c

    r2984 r3131  
    4141#include "kmkbuiltin.h"
    4242#include "../../lib/md5.h"
     43#include <k/kTypes.h>
    4344
    4445/*#define MD5SUM_USE_STDIO*/
     
    6162            " -b, --binary      Read files in binary mode. (default)\n"
    6263            " -t, --text        Read files in text mode.\n"
     64            " -m, --manifest    Output in kBuild fetch 'manifest' format.\n"
    6365            " -p, --progress    Show progress indicator on large files.\n"
    6466            " -o, --output      Name of the output list file. Useful with -p.\n"
     
    262264 * @param   pvFile          The opaque pointer returned by open_file
    263265 */
    264 static double size_file(void *pvFile)
     266static KU64 size_file(void *pvFile)
    265267{
    266268#if defined(_MSC_VER)
     
    272274# endif
    273275    if (cb >= 0)
    274         return (double)cb;
     276        return cb;
    275277
    276278#elif defined(MD5SUM_USE_STDIO)
     
    295297 * @param   pDigest     Where to store the MD5 digest.
    296298 * @param   fProgress   Whether to show a progress bar.
    297  */
    298 static int calc_md5sum(void *pvFile, unsigned char pDigest[16], unsigned fProgress)
     299 * @param   pcbFile     Where to return the file size. Optional.
     300 */
     301static int calc_md5sum(void *pvFile, unsigned char pDigest[16], unsigned fProgress, KU64 *pcbFile)
    299302{
    300303    int cb;
     
    302305    struct MD5Context Ctx;
    303306    unsigned uPercent = 0;
    304     double off = 0.0;
    305     double cbFile = size_file(pvFile);
     307    KU64 off = 0;
     308    KU64 const cbFile = size_file(pvFile);
    306309
    307310    /* Get a decent sized buffer assuming we'll be spending more time reading
     
    346349            break;
    347350        }
     351        off += cb;
    348352
    349353        /* update the progress indicator. */
     
    351355        {
    352356            unsigned uNewPercent;
    353             off += cb;
    354             uNewPercent = (unsigned)((off / cbFile) * 100);
     357            uNewPercent = (unsigned)(((double)off / cbFile) * 100);
    355358            if (uNewPercent != uPercent)
    356359            {
     
    365368    MD5Final(pDigest, &Ctx);
    366369
     370    if (pcbFile)
     371        *pcbFile = off;
     372
    367373    if (fProgress)
    368374        printf("\b\b\b\b    \b\b\b\b");
     
    386392    int rc;
    387393
    388     rc = calc_md5sum(pvFile, DigestFile, fProgress);
     394    rc = calc_md5sum(pvFile, DigestFile, fProgress, NULL);
    389395    if (!rc)
    390396        rc = memcmp(Digest, DigestFile, 16) ? -1 : 0;
     
    583589 * @param   fText           The mode to open the file in.
    584590 * @param   fQuiet          Whether to be quiet or verbose about errors.
     591 * @param   fManifest       Whether to format the output like a fetch manifest.
    585592 * @param   fProgress       Whether to show an progress indicator on large files.
    586593 * @param   pOutput         Where to write the list. Progress is always written to stdout.
    587594 */
    588 static int md5sum_file(const char *pszFilename, unsigned fText, unsigned fQuiet, unsigned fProgress, FILE *pOutput)
     595static int md5sum_file(const char *pszFilename, unsigned fText, unsigned fQuiet, unsigned fProgress,
     596                       unsigned fManifest, FILE *pOutput)
    589597{
    590598    int rc;
     
    598606    {
    599607        unsigned char Digest[16];
     608        KU64 cbFile = 0;
    600609
    601610        if (fProgress && pOutput)
    602611            fprintf(stdout, "%s: ", pszFilename);
    603612
    604         rc = calc_md5sum(pvFile, Digest, fProgress);
     613        rc = calc_md5sum(pvFile, Digest, fProgress, &cbFile);
    605614        close_file(pvFile);
    606615
     
    616625            char szDigest[36];
    617626            digest_to_string(Digest, szDigest);
     627            if (!fManifest)
     628            {
     629                if (pOutput)
     630                    fprintf(pOutput, "%s %s%s\n", szDigest, fText ? "" : "*", pszFilename);
     631                fprintf(stdout, "%s %s%s\n", szDigest, fText ? "" : "*", pszFilename);
     632            }
     633            else
     634            {
     635                if (pOutput)
     636                    fprintf(pOutput, "%s_SIZE := %" KU64_PRI "\n%s_MD5  := %s\n", pszFilename, cbFile, pszFilename, szDigest);
     637                fprintf(stdout, "%s_SIZE := %" KU64_PRI "\n%s_MD5  := %s\n", pszFilename, cbFile, pszFilename, szDigest);
     638            }
    618639            if (pOutput)
    619             {
    620                 fprintf(pOutput, "%s %s%s\n", szDigest, fText ? "" : "*", pszFilename);
    621640                fflush(pOutput);
    622             }
    623             fprintf(stdout, "%s %s%s\n", szDigest, fText ? "" : "*", pszFilename);
    624641            fflush(stdout);
    625642        }
     
    654671    int fQuiet = 0;
    655672    int fChecking = 0;
     673    int fManifest  = 0;
    656674    int fProgress = 0;
    657675    int fNoMoreOptions = 0;
     
    691709                else if (!strcmp(psz, "-check-file"))
    692710                    psz = "C";
     711                else if (!strcmp(psz, "-manifest"))
     712                    psz = "m";
    693713                else if (!strcmp(psz, "-output"))
    694714                    psz = "o";
     
    722742                        fText = 1;
    723743                        fBinaryTextOpt = 1;
     744                        break;
     745
     746                    case 'm':
     747                        fManifest = 1;
    724748                        break;
    725749
     
    822846            }
    823847
    824             rc |= md5sum_file(argv[i], fText, fQuiet, fProgress && !fQuiet, pOutput);
     848            rc |= md5sum_file(argv[i], fText, fQuiet, fProgress && !fQuiet && !fManifest, fManifest, pOutput);
    825849        }
    826850        i++;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette