コード例 #1
0
AssetHash getIntensityLocalAssetHash(const AssetId& id, AssetManager* manager)
{
    std::string path = manager->getLocalAssetPath(id);

    REFLECT_PYTHON( calculate_file_hash );

    std::string hash = python::extract<std::string>( calculate_file_hash(path) );

    Logging::log(Logging::DEBUG, "Calculated IntensityHash: %s ==== %s\r\n", id.c_str(), hash.c_str());

    return hash;
}
コード例 #2
0
ファイル: auditlib.c プロジェクト: niraj17/work
/* This reads the audit data into a global variable */
int bcfs_read_audit_data(char *target_relative_path, struct audit_info *data)
{
    struct audit_info *ai = (struct audit_info *) data;
    int fd = 0, i =0, j =0, ret=0;
    char line[AUDIT_PATH_MAX], *c = NULL, full_path[AUDIT_PATH_MAX];
    struct stat st_buf;
    int already_found = 0;

    int creat_count = 0, creat_found = 0;
    char creat_list[MAX_CREAT][AUDIT_PATH_MAX]; /* list of files created */
    int unlink_count = 0, unlink_found = 0;
    char unlink_list[MAX_CREAT][AUDIT_PATH_MAX]; /* list of files unlinked */

    if (debug_auditlib) printf("bcfs_read_audit_data  called\n");
    sprintf(ar.workspace_path, "%s", ai->workspace_path);
    sprintf(ar.target_relative_path, "%s", target_relative_path);
 
    if (debug_auditlib) printf("bcfs_read_audit_data  called: audit_file_path=%s\n",
           ai->audit_file_path);

    fd  = open(ai->audit_file_path, O_RDONLY);
    if (fd < 0) {
        perror("write failed");
        return 1;
    }

    ar.count = 0;

    while (readline(fd, line, AUDIT_PATH_MAX) > 0) {
	creat_found = 0;
	already_found = 0;

        c   = strtok(line, ":"); /*a_pid*/
        if (c == NULL) return 0;
        c   = strtok(NULL, ":"); /*pid*/
        if (c == NULL) return 0;

        c   = strtok(NULL, ":"); /*ops*/
        if (c == NULL) return 0;

	if (strcmp (c, "creat") == 0) {
            c = strtok(NULL, ":"); /*path*/
            if (c == NULL) continue;
	    if (creat_count < MAX_CREAT) {
                strcpy(creat_list[creat_count], c);
                if (debug_auditlib) printf("Added to creat list: %s\n", creat_list[creat_count]);
	        creat_count++;
	    } else {
		printf("Warning: MAX create count exceeded. Target=%s\n",target_relative_path);
	    }
	    continue;
	}
	if (strcmp (c, "unlink") == 0) {
            c = strtok(NULL, ":"); /*path*/
            if (c == NULL) continue;
	    if (unlink_count < MAX_UNLINK) {
                strcpy(unlink_list[unlink_count], c);
                if (debug_auditlib) printf("Added to unlink list: %s\n", unlink_list[unlink_count]);
	        unlink_count++;
	    } else {
		printf("Warning: MAX unlink count exceeded. Target=%s\n", target_relative_path);
	    }
	    continue;
	}

        if (strcmp(c,"read") == 0)
        {
	    ar.ad[ar.count].type = AUDIT_DEPS;
            c = strtok(NULL, ":"); /*path*/
            if (c == NULL) return 0;

	    /* If this file was created in this build, then it should
	       not be included as a dependency */
	    for (i = 0; i < creat_count; i++)
	    {
		if (strcmp(creat_list[i], c) == 0) {
		    creat_found = 1;
                    if (debug_auditlib) printf("creat_found: %s\n", c);
		    break;
		}
	    }
	    if (creat_found) continue;

	    /* If this file has already been included as a dependency,
	       then skip it */
	    for (i = 0; i < ar.count; i++)
	    {
		if (strcmp(ar.ad[i].path, c) == 0) {
		    already_found = 1;
                    if (debug_auditlib) printf("already_found: %s\n", c);
		    break;
		}
	    }
	    if (already_found) continue;

            strcpy(ar.ad[ar.count].path, c);

	    /* skip if this file is same as the target being
	       built */
	    if (strcmp(ar.ad[ar.count].path + 1, target_relative_path) == 0) continue;

	    sprintf(full_path, "%s%s", ar.workspace_path, ar.ad[ar.count].path);
	    if (debug_auditlib) printf("full_path = %send\n", full_path);
	    if (stat(full_path, &st_buf) == 0) {
               ar.ad[ar.count].st_size  = st_buf.st_size;
	       if (debug_auditlib) printf("size is %d\n", ar.ad[ar.count].st_size);
	    }

	    /* Calculate a checksum (MD5) for the file and store it*/
	    calculate_file_hash(full_path, ar.ad[ar.count].hash, AUDIT_HASH_SIZE);

            if (debug_auditlib) printf("ar.ad.path = %s\n", ar.ad[ar.count].path);
            ar.count++;
	    if (ar.count == MAX_AUDIT) {
                printf("Warning : MAX audit limit exceeded: Target = %s\n",
			target_relative_path);
		break;
	    }
        }
    }


    /* files which are created but not unlinked should be listed as DO*/
    for (i = 0; i < creat_count; i++) {
	unlink_found = 0;
        for (j = 0; j < unlink_count; j++) {
	    if (strcmp(creat_list[i], unlink_list[j]) == 0) {
	        unlink_found = 1;
	        break;
	    }
	}
	if (unlink_count == 0) {
	    if ( ar.count == MAX_AUDIT) { 
                printf("Warning : MAX AUDIT limit exceeded at DO: Target = %s\n",
			target_relative_path);
	    }
	    /* TODO: add creat_list[i] as a DO */
	    ar.ad[ar.count].type = AUDIT_DO;
	    sprintf(ar.ad[ar.count].path, "%s", creat_list[i]);
	    ar.count++;
            if (debug_auditlib) printf("Added DO : %s\n", creat_list[i]);
	}
    }


    ar.length = 3 * sizeof(int) + 2 * AUDIT_PATH_MAX + ar.count * sizeof(struct audit_data);

    close(fd);
    if (debug_auditlib) printf("ar.count = %d\n",ar.count);
    return 0;
}