IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 33205


Ignore:
Timestamp:
Feb 6, 2012, 11:41:28 AM (14 years ago)
Author:
eugene
Message:

ongoing work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c

    r33204 r33205  
    1818  for (i = 0; i < skylist->Nregions; i++) {
    1919   
    20     // assign or re-assign? if a region is already assigned, do we keep it?
     20    // move each table from CATDIR/name to table->hosts[].pathname/name
    2121
    22     // unassigned
     22    // XXX assign or re-assign? if a region is already assigned, do we keep it?
     23
     24    // skip unassigned tables
    2325    if (!skylist->regions[i]->hostID) continue;
    24     if (skylist->regions[i]->hostID < 0) continue;
    2526
     27    // find the host for the table
    2628    short index = table->index[skylist->regions[i]->hostID];
    2729    HostInfo *host = &table->hosts[index];
    2830
    29     // move from CATDIR/name to table->hosts[].pathname/name
    30     sprintf (srcname, "%s/%s", CATDIR, skylist->regions[i]->name);
    31     sprintf (tgtname, "%s/%s", host->pathname, skylist->regions[i]->name);
     31    char extname[4][16] = {"cpm", "cpt", "cps", "cpn"};
     32    for (j = 0; j < 4; j++) {
    3233
    33     // does srcname exist & can it be read?
     34        // set the in and out table names
     35        sprintf (srcname, "%s/%s.%s", CATDIR, skylist->regions[i]->name, extname);
     36        sprintf (tgtname, "%s/%s.%s", host->pathname, skylist->regions[i]->name, extname);
    3437
    35     // check permission to read file
    36     int status = stat (srcname, &filestat);
    37     if (!status) continue;  // file does not exist (check error stats for other issues?)
     38        // does srcname exist & can it be read?
     39
     40        // check permission to read file
     41        int status = stat (srcname, &filestat);
     42        if (!status) continue;  // file does not exist (check error stats for other issues?)
    3843   
    39     // can we read the file
    40     if (uid == filestat.st_uid) {
    41       if (filestat.st_mode & S_IRUSR) goto valid;
    42     }
    43     if (gid == filestat.st_gid) {
    44       if (filestat.st_mode & S_IRGRP) goto valid;
    45     }
    46     if (filestat.st_mode & S_IROTH) goto valid;
     44        // can we read the file
     45        if (uid == filestat.st_uid) {
     46            if (filestat.st_mode & S_IRUSR) goto valid;
     47        }
     48        if (gid == filestat.st_gid) {
     49            if (filestat.st_mode & S_IRGRP) goto valid;
     50        }
     51        if (filestat.st_mode & S_IROTH) goto valid;
    4752   
    48     fprintf (stderr, "cannot read file %s, skipping\n", srcname);
    49     continue;
     53        fprintf (stderr, "cannot read file %s, skipping\n", srcname);
     54        continue;
    5055
    51   valid:
    52     // since we have to open and read the whole file anyway,
    53     // perhaps we should just write the output file?
     56    valid:
     57        // XXX since we have to open and read the whole file anyway,
     58        // XXX perhaps we should just write the output file?
     59       
     60        // read srcname, write to tgtname, get MD5 sum for srcname as we go:
     61       
     62        // open the src file
     63        FILE *fInput = fopen (srcname, "r");
     64        int fdInput = fileno (fInput);
     65       
     66        // open the tgt file
     67        FILE *fOutput = fopen (tgtname, "w");
     68        int fdOutput = fileno (fOutput);
    5469
    55     // read srcname, write to tgtname, get MD5 sum for srcname as we go:
     70        int n;
     71        MD5_CTX c;
     72        char buf[512];
     73        ssize_t nbytes;
    5674
    57     // open the src file
    58     FILE *fInput = fopen (srcname, "r");
    59     int fdInput = fileno (fInput);
     75        MD5_Init(&c);
     76        while ((nbytes = read (fd, buf, 512)) > 0) {
     77            MD5_Update(&c, buf, nbytes);
     78            nbytes = write (fd, buf, 512);
     79        }
     80        MD5_Final(out, &c);
    6081
    61     // open the tgt file
    62     FILE *fOutput = fopen (srcname, "w");
    63     int fdOutput = fileno (fInput);
    64 
    65     int n;
    66     MD5_CTX c;
    67     char buf[512];
    68     ssize_t nbytes;
    69 
    70     MD5_Init(&c);
    71     for (; (nbytes = read (fd, buf, 512)) > 0;) {
    72       MD5_Update(&c, buf, nbytes);
    73       nbytes = write (fd, buf, 512);
    74     }
    75     MD5_Final(out, &c);
    76 
    77     for (n = 0; n < MD5_DIGEST_LENGTH; n++) {
    78       fprintf (stderr, "%02x", out[n]);
    79     }
    80     fclose (f);
    81     flush (f);
     82        for (n = 0; n < MD5_DIGEST_LENGTH; n++) {
     83            fprintf (stderr, "%02x", out[n]);
     84        }
     85        fclose (f);
     86        flush (f);
    8287
    8388    // need to re-open and re-read tgtname to check md5sum
Note: See TracChangeset for help on using the changeset viewer.