int create_sync_list() { #if MEM_POOL_ENABLE mem_pool_init(); printf("######eable mem pool######\n"); #endif local_sync = 0; server_sync = 1; finished_initial = 0; LOCAL_FILE.path = NULL; int i; int num=asus_cfg.dir_number; g_pSyncList = (sync_list **)malloc(sizeof(sync_list *)*num); memset(g_pSyncList,0,sizeof(sync_list *)*num); #if TOKENFILE sighandler_finished = 0; #endif for(i=0;i<asus_cfg.dir_number;i++) { g_pSyncList[i] = (sync_list *)malloc(sizeof(sync_list)); memset(g_pSyncList[i],0,sizeof(sync_list)); g_pSyncList[i]->receve_socket = 0; g_pSyncList[i]->have_local_socket = 0; g_pSyncList[i]->first_sync = 1; g_pSyncList[i]->no_local_root = 0; g_pSyncList[i]->init_completed = 0; #if TOKENFILE g_pSyncList[i]->sync_disk_exist = 0; #endif // sprintf(g_pSyncList[i]->temp_path,"%s/.smartsync/dropbox",asus_cfg.prule[i]->base_path); // my_mkdir_r(g_pSyncList[i]->temp_path); //have mountpath // snprintf(g_pSyncList[i]->conflict_file,255,"%s/conflict_%s", // g_pSyncList[i]->temp_path,asus_cfg.prule[i]->rooturl+1); g_pSyncList[i]->ServerRootNode = NULL; g_pSyncList[i]->OldServerRootNode = NULL; g_pSyncList[i]->VeryOldServerRootNode = NULL; g_pSyncList[i]->SocketActionList = queue_create(); g_pSyncList[i]->unfinished_list = create_action_item_head(); g_pSyncList[i]->up_space_not_enough_list = create_action_item_head(); g_pSyncList[i]->server_action_list = create_action_item_head(); g_pSyncList[i]->copy_file_list = create_action_item_head(); g_pSyncList[i]->access_failed_list = create_action_item_head(); if(asus_cfg.prule[i]->rule == 1) { g_pSyncList[i]->download_only_socket_head = create_action_item_head(); } else { g_pSyncList[i]->download_only_socket_head = NULL; } #if TOKENFILE tokenfile_info_tmp = tokenfile_info_start->next; while(tokenfile_info_tmp != NULL) { //printf("asus_cfg.prule[%d]->rooturl=%s,asus_cfg.user=%s\n",i,asus_cfg.prule[i]->rooturl,asus_cfg.user); //printf("tokenfile_info_tmp->folder=%s,tokenfile_info_tmp->url=%s\n",tokenfile_info_tmp->folder,tokenfile_info_tmp->url); if(!strcmp(tokenfile_info_tmp->folder,asus_cfg.prule[i]->rooturl) && !strcmp(tokenfile_info_tmp->url,asus_cfg.user)) { g_pSyncList[i]->sync_disk_exist = 1; /* fix below bug: rm sync dir,change the sync dir,can not create sync dir */ if(access(asus_cfg.prule[i]->path,F_OK)) { my_mkdir_r(asus_cfg.prule[i]->path); } break; } tokenfile_info_tmp = tokenfile_info_tmp->next; } #endif } }
int main(int argc, char *argv[]) { //base_path = argv[1]; //initConfig2(CONFIG_GER_PATH); /* if(argc < 2) { printf("usage: inotify path\n"); return -1; } */ strcpy(base_path,"/tmp/Cloud"); //printf("inotify base path is %s\n",base_path); //if(NULL == opendir(base_path)) //mkdir(base_path,0777); sprintf(inotify_path,"%s/%s",base_path,"inotify_file"); my_mkdir_r(inotify_path); sprintf(moved_from_file,"%s/%s",inotify_path,"moved_from"); sprintf(moved_to_file,"%s/%s",inotify_path,"moved_to"); //if(NULL == opendir(BASIC_PATH)) //mkdir(BASIC_PATH,0777); if(NULL == opendir(inotify_path)) mkdir(inotify_path,0777); keep_running = 1; /* Set a ctrl-c signal handler */ if (signal (SIGINT, signal_handler) == SIG_IGN) { /* Reset to SIG_IGN (ignore) if that was the prior state */ signal (SIGINT, SIG_IGN); } pthread_t newthid1,newthid2; if( pthread_create(&newthid1,NULL,(void *)watch_socket,NULL) != 0) { printf("thread creation failder\n"); exit(1); } if( pthread_create(&newthid2,NULL,(void *)watch_folder,NULL) != 0) { printf("thread creation failder\n"); exit(1); } //sleep(1); pthread_join(newthid2,NULL); return 0; }