Esempio n. 1
0
gboolean recurse(struct catalog *catalog,
                 const char *directory,
                 GPatternSpec **ignore_patterns,
                 int maxdepth,
                 gboolean slow,
                 int source_id,
                 handle_file_f callback,
                 gpointer userdata,
                 GError **err)
{
        DIR *dir;

        catalog_index_init();

        dir = opendir_witherrors(directory, err);
        if(dir) {
                return _recurse(catalog,
                                directory,
                                dir,
                                ignore_patterns,
                                maxdepth,
                                slow,
                                source_id,
                                callback,
                                userdata,
                                err);
        } else {
                return FALSE;
        }
}
unsigned long _recurse(int x, int y, int N)
{
	unsigned long cnt = 0;

	if (x == N-1 && y == N-1) {
		// At bottom edge corner
		cnt = 1;
	} else if (x == N-1) {
		// Along right edge
		cnt += _recurse(x, y+1, N);
	} else if (y == N-1) {
		// At bottom edge
		cnt += _recurse(x+1, y, N);
	} else {
		// In the middle or start
		cnt += _recurse(x+1, y, N);
		cnt += _recurse(x, y+1, N);
	}

	return(cnt);
}
Esempio n. 3
0
/**
 * Recurse through directories.
 *
 * @param catalog
 * @param directory full path to the directory represented by dirhandle
 * @param dirhandle handle on a directory (which will be closed by this function)
 * @param ignore_patterns additional patterns to ignore (or NULL)
 * @param maxdepth maximum depth to go through 0=> do not look into sub directories, -1=> infinite
 * @param slow if true, slow down search
 * @param cmd source ID
 * @param callback
 * @param userdata
 * @parma err
 * @return true if it worked
 */
static gboolean _recurse(struct catalog *catalog,
                         const char *directory,
                         DIR *dirhandle,
                         GPatternSpec **ignore_patterns,
                         int maxdepth,
                         gboolean slow,
                         int cmd,
                         handle_file_f callback,
                         gpointer userdata,
                         GError **err)
{
        GPtrArray *subdirectories;
        gboolean error;
        struct dirent *dirent;

        if(maxdepth==0) {
                return TRUE;
        }
        if(maxdepth>0) {
                maxdepth--;
        }

        subdirectories =  NULL;
        if(maxdepth!=0)
                subdirectories = g_ptr_array_new();
        error = FALSE;
        while( !error && (dirent=readdir(dirhandle)) != NULL )
        {
                const char *filename;
                char *current_path;
                mode_t mode;

                filename =  dirent->d_name;
                if(*filename=='.' || to_ignore(filename, DEFAULT_IGNORE) || to_ignore(filename, ignore_patterns))
                        continue;

                current_path=g_malloc(strlen(directory)+1+strlen(filename)+1);
                strcpy(current_path, directory);
                if(current_path[strlen(current_path)-1]!='/')
                        strcat(current_path, "/");
                strcat(current_path, filename);

                if(getmode(current_path, &mode)) {
                        gboolean acc_dir=is_accessible_directory(mode);
                        gboolean acc_file=is_accessible_file(mode);

                        if(acc_dir && maxdepth!=0) {
                                char *current_path_dup = g_strdup(current_path);
                                g_ptr_array_add(subdirectories, current_path_dup);
                        }
                        if(acc_dir || acc_file) {
                                if(!callback(catalog, cmd, current_path, filename, err, userdata))
                                        error=TRUE;
                        }
                }
                g_free(current_path);
        }
        closedir(dirhandle);

        if(subdirectories)
        {
                int i;
                for(i=0; i<subdirectories->len; i++) {
                        char *current_path = subdirectories->pdata[i];
                        DIR *subdir = opendir(current_path);
                        if(subdir!=NULL) {
                                if(!_recurse(catalog,
                                                current_path,
                                                subdir,
                                                ignore_patterns,
                                                maxdepth,
                                                slow,
                                                cmd,
                                                callback,
                                                userdata,
                                                err)) {
                                        error=TRUE;
                                } else {
                                        doze_off(slow);
                                }
                        }
                        g_free(current_path);
                }
                g_ptr_array_free(subdirectories, TRUE/*free segments*/);
        }

        return !error;
}