Ejemplo n.º 1
0
//int get_all_folders(char *dirname,int *num,char **folder_list)
int get_all_folders(const char *dirname,Folders *allfolderlist,int offset,int type)
{
    struct dirent* ent = NULL;
    DIR *pDir;
    char temp_dir[1024];
    int num ;

    //printf("dis %s\n",dirname);

#if 0
    if(offset == 0)
    {
        strcpy(allfolderlist->folderlist[0].name,dirname);

    }
    else if(offset > 0)
        strcpy(allfolderlist->folderlist[offset].name,dirname);
#endif

    if(offset != -1)
    {
        strcpy(allfolderlist->folderlist[offset].name,dirname);
        allfolderlist->number++;
    }



    //allfolderlist->folderlist[0].name

    //if(offset != -1)
    //allfolderlist->number++;

    //allfolderlist.number = 1;

    pDir=opendir(dirname);
    if(pDir != NULL )
    {
        while (NULL != (ent=readdir(pDir)))
        {
            //printf("ent->d_name is %s\n",ent->d_name);

            //if(ent->d_name[0] == '.')
            //continue;
            if(!strcmp(ent->d_name,".") || !strcmp(ent->d_name,".."))
                continue;

            if( !strcmp(dirname,mount_path) && !strcmp(ent->d_name,"smartcloud") )
            {
                continue;
            }

            if(ent->d_type == DT_DIR)
            {
                num = allfolderlist->number;
                memset(temp_dir,0,sizeof(temp_dir));
                sprintf(temp_dir,"%s/%s",dirname,ent->d_name);

                strcpy(allfolderlist->folderlist[num].name,temp_dir);
                allfolderlist->folderlist[num].type = type;
                //printf("folder name is %s,num is %d\n",temp_dir,num);

                allfolderlist->number++;
                get_all_folders(temp_dir,allfolderlist,-1,type);
            }

        }
        closedir(pDir);
    }
    else
        printf("open %s fail \n",dirname);

    return 0;
}
Ejemplo n.º 2
0
int inotifyStart()
{
    int inotify_fd;
    int i;
    //Folders allfolderlist;

    keep_running = 1;
    need_restart_inotify = 0;
    add_new_watch_item = 0;

    /* First we open the inotify dev entry */
    inotify_fd = open_inotify_fd ();
    if (inotify_fd > 0)
    {

        queue_t q;
        q = queue_create (128);

        int wd;

        wd = 0;

        memset(&allfolderlist,0,sizeof(Folders));

        //printf("list num is %d\n",pathlist.number);

        for( i = 0 ; i < pathlist.number; i++)
        {
            //printf("list is %s\n",pathlist.folderlist[i].name);
            get_all_folders(pathlist.folderlist[i].name,&allfolderlist,allfolderlist.number);
        }

       //for( i = 0 ; i < number; i++)uploadFile


        //strcpy(allfolderlist.folderlist[0].name,dirname);
        //allfolderlist.number = 1;



        printf("\n");
        for( i = 0; (i<allfolderlist.number) && (wd >= 0);i++)
        {
            wd = watch_dir (inotify_fd, allfolderlist.folderlist[i].name, IN_ALL_EVENTS);
            //printf("minitor path is %s\n",allfolderlist.folderlist[i].name);
        }

        if (wd > 0)
        {

            process_inotify_events (q, inotify_fd);
        }
        printf ("\nTerminating\n");
        close_inotify_fd (inotify_fd);
        queue_destroy (q);

        if(need_restart_inotify == 1)
            inotifyStart();
    }
    return 0;
}