示例#1
0
/**
 * Iterates over an enumerator obtained from a directory.
 * @param main_struct : main structure of the program
 * @param directory is the directory we are iterating over
 * @param file_enum is the enumerator obtained when opening a directory
 *        to carve it.
 */
static void iterate_over_enum(main_struct_t *main_struct, gchar *directory, GFileEnumerator *file_enum)
{
    GError *error = NULL;
    GFileInfo *fileinfo = NULL;
    file_event_t *file_event = NULL;

    if (main_struct != NULL && file_enum != NULL)
    {
        fileinfo = g_file_enumerator_next_file(file_enum, NULL, &error);

        while (error == NULL && fileinfo != NULL)
        {
            /* file_event is used and freed in the thread
             * save_one_file_threaded where the queue save_queue
             * is used
             */
            file_event = new_file_event_t(directory, fileinfo);
            g_async_queue_push(main_struct->save_queue, file_event);

            fileinfo = free_object(fileinfo);

            fileinfo = g_file_enumerator_next_file(file_enum, NULL, &error);
        }
    }
}
示例#2
0
/**
 * Prepares everything in order to call save_one_file function that does
 * everything to save one file !
 * @param main_struct : main structure of the program
 * @param path is the entire path and name of the considered file.
 */
static void prepare_before_saving(main_struct_t *main_struct, gchar *path)
{
    gchar *directory = NULL;
    GFileInfo *fileinfo = NULL;
    GFile *file = NULL;
    GError *error = NULL;
    file_event_t *file_event = NULL;

    if (main_struct != NULL && path != NULL)
        {
            directory = g_path_get_dirname(path);
            file = g_file_new_for_path(path);
            fileinfo = g_file_query_info(file, "*", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);

            if (error == NULL && fileinfo != NULL)
                {
                    /* file_event is used and freed in the thread
                     * save_one_file_threaded where the queue save_queue
                     * is used
                     */
                    file_event = new_file_event_t(directory, fileinfo);
                    g_async_queue_push(main_struct->save_queue, file_event);

                    fileinfo = free_object(fileinfo);
                    file = free_object(file);
                    free_variable(directory);
                }
            else
                {
                    print_error(__FILE__, __LINE__, _("Unable to get meta data for file %s: %s\n"), path, error->message);
                    error = free_error(error);
                }
        }
}