Changeset 33205
- Timestamp:
- Feb 6, 2012, 11:41:28 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/Ohana/src/photdbc/src/CopyToHostLocation.c
r33204 r33205 18 18 for (i = 0; i < skylist->Nregions; i++) { 19 19 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 21 21 22 // unassigned 22 // XXX assign or re-assign? if a region is already assigned, do we keep it? 23 24 // skip unassigned tables 23 25 if (!skylist->regions[i]->hostID) continue; 24 if (skylist->regions[i]->hostID < 0) continue;25 26 27 // find the host for the table 26 28 short index = table->index[skylist->regions[i]->hostID]; 27 29 HostInfo *host = &table->hosts[index]; 28 30 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++) { 32 33 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); 34 37 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?) 38 43 39 // can we read the file40 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; 47 52 48 fprintf (stderr, "cannot read file %s, skipping\n", srcname);49 continue;53 fprintf (stderr, "cannot read file %s, skipping\n", srcname); 54 continue; 50 55 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); 54 69 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; 56 74 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); 60 81 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); 82 87 83 88 // need to re-open and re-read tgtname to check md5sum
Note:
See TracChangeset
for help on using the changeset viewer.
