コード例 #1
0
ファイル: commands.c プロジェクト: stroxler/lcthw
int Command_install(
        apr_pool_t *p, const char *url, const char *configure_opts,
        const char *make_opts, const char *install_opts
) {
    int rc = 0;
    // first clean up
    check(Shell_exec(CLEANUP_SH, NULL) == 0,
          "Faild to clean up before building.");
    // next, make sure it isn't already installed
    rc = DB_find(url);
    check(rc != -1, "Error checking the installed database");
    if (rc == 1) {
        log_info("Package already installed.");
        return 0;
    }
    // it isn't installed. So, fetch.
    rc = Command_fetch(p, url, 0);
    // if fetch worked, build.
    if (rc == 1) {
        rc = Command_build(p, url, configure_opts, make_opts, install_opts);
    } else if (rc == 0) {
        // no install needed... I haven't read fetch yet so I'm not sure how
        // this would happen.
        log_info("Depends successfully installed: %s", url);
    } else {
        sentinel("Install failed: %s", url);
    }
    // cleanup again. It doesn't matter whether we check errors this time.
    Shell_exec(CLEANUP_SH, NULL);
    return 0;
error:
    return -1;
}
コード例 #2
0
ファイル: db.c プロジェクト: alex-heritier/devpkg
int DB_add(Database *db, const char *data)
{
	assert(db);
	assert(data);
	
	if(DB_find(db, data)) return 0;
	for (int i = 0; i < MAX_ENTRIES; i++) {
		if (is_empty(db->entries[i].data)) {
			memcpy(&db->entries[i], data, MAX_DATA);
			db->entry_num++;
			return 1;
		}
	}
	return 1;
}
コード例 #3
0
ファイル: db.c プロジェクト: fbmnds/lcthw
int DB_update(const char *url) {
    if(DB_find(url)) {
        log_info("Already recorded as installed: %s", url);
    }
    FILE *db = DB_open(DB_FILE, "a+");
    check(db, "Failed to open DB file: %s", DB_FILE);
    bstring line = bfromcstr(url);
    bconchar(line, '\n');
    int rc = fwrite(line->data, blength(line), 1, db);
    check(rc == 1, "Failed to append to the db.");
    return 0;
error:
    if(db) DB_close(db);
    return -1;
}
コード例 #4
0
ファイル: db.c プロジェクト: maxbeutel/learn-c-the-hard-way
int DB_update(const char *url)
{
    bool found = false;
    assert(DB_find(url, &found) == 0);
    
    if (found) {
        printf("INFO: Already recorded as installed: %s\n", url);
    }
    
    FILE *db = DB_open(DB_FILE, "a+");
    assert(db != NULL);
    
    bstring line = bfromcstr(url);
    bconchar(line, '\n');
    
    int rc = fwrite(line->data, blength(line), 1, db);
    assert(rc == 1);
    
    bdestroy(line);
    
    DB_close(db);
    
    return 0;
}