static void catch_up(const FileData *local_file_data, int host) { int i, j; FileData remote_file_data; printf(_("Rebuilding cache as all files are updated...\n")); remote_file_data.path_state = str_malloc(sizeof(PathState) * (local_file_data->num_paths)); remote_file_data.num_paths = local_file_data->num_paths; for (i = 0; i < local_file_data->num_paths; i++) { remote_file_data.path_state[i].path = str_concat(config.remote_top_dir[host], local_file_data->path_state[i].path + strlen(config.local_top_dir[host]), NULL); remote_file_data.path_state[i].isremoved = local_file_data->path_state[i].isremoved; remote_file_data.path_state[i].num_files = local_file_data->path_state[i].num_files; remote_file_data.path_state[i].file_state = str_malloc(sizeof(FileState) * (local_file_data->path_state[i].num_files)); for (j = 0; j < local_file_data->path_state[i].num_files; j++) { remote_file_data.path_state[i].file_state[j].time = local_file_data->path_state[i].file_state[j].time; remote_file_data.path_state[i].file_state[j].size = local_file_data->path_state[i].file_state[j].size; remote_file_data.path_state[i].file_state[j].mode = local_file_data->path_state[i].file_state[j].mode; remote_file_data.path_state[i].file_state[j].isdir = local_file_data->path_state[i].file_state[j].isdir; remote_file_data.path_state[i].file_state[j].isremoved = local_file_data->path_state[i].file_state[j].isremoved; remote_file_data.path_state[i].file_state[j].name = str_dup(local_file_data->path_state[i].file_state[j].name); } } save_cache(&remote_file_data, host); free_file_data(&remote_file_data); }
void load_database_t::refresh_cache(HWND wnd, ipod_device_ptr_ref_t p_ipod, bool b_CheckIfFilesChanged, threaded_process_v2_t & p_status, abort_callback & p_abort) { p_status.checkpoint(); load_cache(wnd, p_ipod, b_CheckIfFilesChanged, p_status, p_abort); p_status.checkpoint(); if (!m_writing) save_cache(wnd, p_ipod, p_status, p_abort); p_status.checkpoint(); }
void in_received_handler(DictionaryIterator *iter, void *context) { #ifdef ENABLE_LOGS APP_LOG(APP_LOG_LEVEL_DEBUG, "Watch: Message received"); #endif int x = 0; //processing usernames for (x=0;x<MAX_NUM_USERS;x++){ Tuple *tuple = dict_find(iter, CONST_FRIEND1+x); if (tuple){ set_username_for_friend_at_index(tuple->value->cstring,x); } } //processing ids for (x=0;x<MAX_NUM_USERS;x++){ Tuple *tuple = dict_find(iter, CONST_FRIEND1+x+100); if (tuple){ set_id_for_friend_at_index(tuple->value->cstring,x); } } //processing number of friends received, this message should be the last one done in JS Tuple *tuple = dict_find(iter, CONST_FRIENDS_COUNT); if (tuple){ set_num_friends(tuple->value->int32); save_cache(); } //Confirmation of Sending Message Tuple *tuple2 = dict_find(iter, CONST_STATUS); if (tuple2){ int error = tuple2->value->int32; if (error == STYLE_ERROR) { vibes_long_pulse(); show_message_window(_("Message|Failed"),STYLE_ERROR); } else { vibes_short_pulse(); show_message_window(_("Message|Sent"),STYLE_SUCCESS); } } //Confirmation of Sending Message Tuple *tuple3 = dict_find(iter, CONST_ERROR_UPDATING_TOKEN); if (tuple3){ int error = tuple3->value->int32; if (error == STYLE_ERROR) { vibes_long_pulse(); show_message_window(_("Failed|to Sync"),STYLE_ERROR); } else { vibes_short_pulse(); show_message_window(_("Sync|Succeed"),STYLE_SUCCESS); } } }
static int bee_dep_remove(int argc, char *argv[]) { int i, c, help, print; struct hash *graph; char *pkg; struct option long_options[] = { {"help", 0, &help, 1}, {"print", 0, &print, 1}, {0, 0, 0, 0} }; help = print = 0; while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { switch (c) { case '?': usage_remove(); return 1; } } if (help) { usage_remove(); return 0; } if (optind == argc) { fprintf(stderr, "bee-dep: pkgname needed\n"); return 1; } graph = get_cache(); for (i = optind; i < argc; i++) { pkg = argv[i]; if (print && print_removable(graph, pkg)) { hash_free(graph); return 1; } if (remove_package(graph, pkg)) { hash_free(graph); return 1; } } if (save_cache(graph, cache_filename())) { hash_free(graph); return 1; } hash_free(graph); return 0; }
static void rebuild_cache(int host) { FileData remote_file_data; printf(_("Rebuilding cache...\n")); if (connect_to_remote_host(host) != 0) { return; } get_remote_file_data(&remote_file_data, host); disconnect_from_remote_host(host); save_cache(&remote_file_data, host); free_file_data(&remote_file_data); }
int vpbp_dclose(SceUID fd) { int result; struct IoDirentEntry *entry; lock(); entry = dirent_search(fd); if (entry != NULL && strlen(entry->path) > 4 && 0 == stricmp(entry->path+4, "/PSP/GAME")) { save_cache(); } result = sceIoDclose(fd); unlock(); return result; }
static int bee_dep_update(int argc, char *argv[]) { int c, help; char *pkg; char path[PATH_MAX + 1]; struct hash *graph; struct stat st; struct option long_options[] = { {"help", 0, &help, 1}, {0, 0, 0, 0} }; help = 0; while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { switch (c) { case '?': usage_update(); return 1; } } if (help) { usage_update(); return 0; } if (argc == 1) { graph = get_cache(); if (update_cache(graph) || save_cache(graph, cache_filename())) { hash_free(graph); return 1; } hash_free(graph); return 0; } if (argc < 2) { fprintf(stderr, "bee-dep: pkgname needed\n"); return 1; } if (argc > 2) { fprintf(stderr, "bee-dep: too many arguments\n"); return 1; } pkg = argv[1]; if (sprintf(path, "%s/%s/DEPENDENCIES", bee_metadir(), pkg) < 0) { perror("bee-dep: sprintf"); return 1; } graph = get_cache(); if (stat(path, &st) != -1) { if (hash_search(graph, pkg)) { hash_free(graph); return 0; } if (graph_insert_nodes(graph, path)) { hash_free(graph); return 1; } } else { if (remove_package(graph, pkg)) { hash_free(graph); return 1; } } if (save_cache(graph, cache_filename())) { hash_free(graph); return 1; } hash_free(graph); return 0; }
static struct hash *init_cache(void) { struct dirent **package; int i, pkg_cnt; char path[PATH_MAX + 1]; struct stat st; struct hash *graph; if (stat(bee_metadir(), &st) == -1) return NULL; if ((pkg_cnt = scandir(bee_metadir(), &package, 0, alphasort)) < 0) { perror("bee-dep: init_cache: scandir"); return NULL; } graph = hash_new(); /* skip . and .. */ free(package[0]); free(package[1]); for (i = 2; i < pkg_cnt; i++) { sprintf(path, "%s/%s", bee_metadir(), package[i]->d_name); if (stat(path, &st) == -1) { perror("bee-dep: init_cache: stat"); hash_free(graph); return NULL; } if (S_ISDIR(st.st_mode)) { strcat(path, "/DEPENDENCIES"); if (stat(path, &st) == -1) { fprintf(stderr, "bee-dep: init_cache: missing " "DEPENDENCIES file for package \"%s\"\n", package[i]->d_name); hash_free(graph); return NULL; } if (graph_insert_nodes(graph, path)) { hash_free(graph); return NULL; } } free(package[i]); } free(package); if (save_cache(graph, cache_filename())) { hash_free(graph); return NULL; } return graph; }
int main(int argc, char **argv) { unsigned char buf[256]; int size, s, cntrl_s, cntrl_fd; socklen_t cntrl_len; struct sockaddr_un cntrl_addr; fd_set read_fds, write_fds; int fd_max; if (ax25_config_load_ports() == 0) { fprintf(stderr, "ax25rtd: no AX.25 port configured\n"); return 1; } load_config(); load_cache(); if (fork()) return 0; if ((s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_AX25))) == -1) { perror("AX.25 socket"); return 1; } if ((cntrl_s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { perror("Control socket"); return 1; } unlink(DATA_AX25ROUTED_CTL_SOCK); cntrl_addr.sun_family = AF_UNIX; strcpy(cntrl_addr.sun_path, DATA_AX25ROUTED_CTL_SOCK); cntrl_len = sizeof(cntrl_addr.sun_family) + strlen(DATA_AX25ROUTED_CTL_SOCK); if (bind(cntrl_s, (struct sockaddr *) &cntrl_addr, cntrl_len) < 0) { perror("bind Control socket"); daemon_shutdown(1); } chmod(DATA_AX25ROUTED_CTL_SOCK, 0600); listen(cntrl_s, 1); signal(SIGUSR1, sig_debug); signal(SIGHUP, sig_reload); signal(SIGTERM, sig_term); cntrl_fd = -1; for (;;) { fd_max = 0; FD_ZERO(&read_fds); FD_ZERO(&write_fds); FD_MAX(s); if (cntrl_fd > 0) { FD_MAX(cntrl_fd); FD_SET(cntrl_fd, &write_fds); } else { FD_MAX(cntrl_s); } if (select(fd_max + 1, &read_fds, NULL, &write_fds, NULL) < 0) { if (errno == EINTR) /* woops! */ continue; if (!FD_ISSET(cntrl_fd, &write_fds)) { perror("select"); save_cache(); daemon_shutdown(1); } else { close(cntrl_fd); cntrl_fd = -1; continue; } } if (cntrl_fd > 0) { if (FD_ISSET(cntrl_fd, &read_fds)) { size = read(cntrl_fd, buf, sizeof(buf)); if (size > 0) { buf[size] = '\0'; interpret_command(cntrl_fd, buf); } else { close(cntrl_fd); cntrl_fd = -1; } } } else if (FD_ISSET(cntrl_s, &read_fds)) { if ((cntrl_fd = accept(cntrl_s, (struct sockaddr *) &cntrl_addr, &cntrl_len)) < 0) { perror("accept Control"); save_cache(); daemon_shutdown(1); } } if (reload) reload_config(); if (FD_ISSET(s, &read_fds)) ax25_receive(s); } return 0; /* what ?! */ }
void sig_term(int d) { save_cache(); daemon_shutdown(0); }
/** @ignore yes */ void dest_me() { save_cache(); destruct(this_object()); } /* dest_me() */
void main_loop(int argc, char *argv[], int max_hosts) { int i; int host; int *targeted_host; FileData local_file_data; FileData remote_file_data; Order *order; Direction direction; bool use_cache; char *top_dir; FtpInit(); targeted_host = get_targeted_host(argc, argv, max_hosts); for (i = 0;; i++) { host = targeted_host[i]; if (host == -1) { break; } message(PROCESS, cfgSectionNumberToName(host), 0, host); direction = get_direction(host); get_local_file_data(&local_file_data, host); if (command_line_option.rebuild_cache) { /* -r | --rebuild-cache */ rebuild_cache(host); free_file_data(&local_file_data); continue; } if (command_line_option.catch_up) { /* -R | --catch-up */ catch_up(&local_file_data, host); free_file_data(&local_file_data); continue; } if (direction == DOWNLOAD || !does_cache_exist(host)) { if (direction == DOWNLOAD) { printf(_("Rebuilding cache for downloading...\n")); } else { printf(_("Cache file is not found.\nCreating a new one...\n")); } if (connect_to_remote_host(host) != 0) { free_file_data(&local_file_data); continue; } get_remote_file_data(&remote_file_data, host); use_cache = FALSE; } else { load_cache(&remote_file_data, host); use_cache = TRUE; } order = compare_both_hosts_and_generate_order(&local_file_data, &remote_file_data, config.local_top_dir[host], config.remote_top_dir[host], direction, host); if (!does_need_update(order)) { disconnect_from_remote_host(host); if (direction == UPLOAD) { printf(_("The remote host doesn't need updating.\n")); } else { printf(_("The local host doesn't need updating.\n")); } if (!use_cache) { save_cache(&remote_file_data, host); } free_file_data(&remote_file_data); free_file_data(&local_file_data); continue; } if(command_line_option.list) { disconnect_from_remote_host(host); put_listing_of_updated_file(order, direction); free_file_data(&remote_file_data); free_file_data(&local_file_data); continue; } if(command_line_option.nlist) { disconnect_from_remote_host(host); put_the_number_of_updated_file(order, direction); free_file_data(&remote_file_data); free_file_data(&local_file_data); continue; } if (!use_cache) { printf("\n"); } put_num_updated_file(order, direction); if (connect_to_remote_host(host) != 0) { free_file_data(&remote_file_data); free_file_data(&local_file_data); continue; } if (direction == UPLOAD) { top_dir = str_concat(config.remote_top_dir[host], "/", NULL); } else { top_dir = str_concat(config.local_top_dir[host], "/", NULL); } message(ENTER, top_dir, 0, host); execute_order(order, &remote_file_data, direction, host); message(LEAVE, top_dir, 0, host); free(top_dir); free_order(order); disconnect_from_remote_host(host); save_cache(&remote_file_data, host); free_file_data(&remote_file_data); free_file_data(&local_file_data); } free(targeted_host); }