Пример #1
0
static void
list__process_line (char     *line,
		    gpointer  data)
{
	FileData      *fdata;
	FrCommand     *comm = FR_COMMAND (data);
	FrCommandIso  *comm_iso = FR_COMMAND_ISO (comm);
	char         **fields;
	const char    *name_field;

	g_return_if_fail (line != NULL);

	if (line[0] == 'd') /* Ignore directories. */
		return;

	if (line[0] == 'D') {
		g_free (comm_iso->cur_path);
		comm_iso->cur_path = g_strdup (get_last_field (line, 4));

	} else if (line[0] == '-') { /* Is file */
		const char *last_field, *first_bracket;

		fdata = file_data_new ();

		fields = split_line (line, 8);
		fdata->size = g_ascii_strtoull (fields[4], NULL, 10);
		fdata->modified = mktime_from_string (fields[5], fields[6], fields[7]);
		g_strfreev (fields);

		/* Full path */

		last_field = get_last_field (line, 9);
		first_bracket = strchr (last_field, ']');
		if (first_bracket == NULL) {
			file_data_free (fdata);
			return;
		}

		name_field = eat_spaces (first_bracket + 1);
		if ((name_field == NULL)
		    || (strcmp (name_field, ".") == 0)
		    || (strcmp (name_field, "..") == 0)) {
			file_data_free (fdata);
			return;
		}

		if (comm_iso->cur_path[0] != '/')
			fdata->full_path = g_strstrip (g_strconcat ("/", comm_iso->cur_path, name_field, NULL));
		else
			fdata->full_path = g_strstrip (g_strconcat (comm_iso->cur_path, name_field, NULL));
		fdata->original_path = fdata->full_path;
		fdata->name = g_strdup (file_name_from_path (fdata->full_path));
		fdata->path = remove_level_from_path (fdata->full_path);

		fr_command_add_file (comm, fdata);
	}
}
Пример #2
0
static void
process_line (char *line, gpointer data)
{
   GimvImageInfo *fdata = NULL;
   FRCommand *comm = FR_COMMAND (data);
   char **fields;
   char *name_field;
   char *filename;
   struct stat st;

   g_return_if_fail (line != NULL);

   fields = split_line (line, 5);
   memset (&st, 0, sizeof (struct stat));
   st.st_size = atol (fields[2]);
   st.st_mtime = mktime_from_string (fields[3], fields[4]);
   mkugid_from_string (fields[1], &st.st_uid, &st.st_gid);
   st.st_mode = mkmode_from_string (fields[0]);
   g_strfreev (fields);

   /* Full path */

   name_field = get_last_field (line);
   fields = g_strsplit (name_field, " -> ", 2);

   if (!fields[1]) {
      g_strfreev (fields);
      fields = g_strsplit (name_field, " link to ", 2);
   }

   if (*(fields[0]) == '/') {
      filename = fields[0] + 1;
   } else {
      filename = fields[0];
   }

   if (*filename && *comm->filename) {
      fdata = gimv_image_info_get_with_archive (filename,
                                                FR_ARCHIVE (comm->archive),
                                                &st);
   }
   if (fdata) {
      if (fields[1])
         gimv_image_info_set_link (fdata, fields[1]);
      comm->file_list = g_list_prepend (comm->file_list, fdata);
   }

   g_strfreev (fields);
}
static void
process_metadata_line (char      *line,
                       FrCommand *comm)
{
        FileData    *fdata;
        char       **fields;
        char        *name;

        g_return_if_fail (line != NULL);

        fields = split_line (line, 6);
        if (!fields[1] || !g_str_equal (fields[1], "bytes,")) {
                g_strfreev (fields);
                return;
        }

        fdata = file_data_new ();
        fdata->size = g_ascii_strtoull (fields[0], NULL, 10);

        if (fields[5] && g_str_equal (fields[4],"*")) {
                name = g_strdup (fields[5]);
        } else {
                name = g_strdup (get_last_field (line, 5));
        }
        g_strstrip (name);

        fdata->full_path = g_strconcat ("/DEBIAN/", name, NULL);
        fdata->original_path = fdata->full_path + 1;

        g_strfreev (fields);
        g_free (name);

        fdata->name = g_strdup (name);
        fdata->path = g_strdup ("DEBIAN");
        fr_command_add_file (comm, fdata);
}
static void
process_data_line (char     *line,
                   gpointer  data)
{
        FileData    *fdata;
        FrCommand   *comm = FR_COMMAND (data);
        char       **fields;
        char       **tmfields;
        struct tm    tm = {0, };
        const char  *name;

        g_return_if_fail (line != NULL);

        if (line[0] == ' ') {
                /* This is the output of dpkg-deb -I */
                process_metadata_line (line, comm);
                return;
        }

        fdata = file_data_new ();

        fields = split_line (line, 5);
        fdata->size = g_ascii_strtoull (fields[2], NULL, 10);
        tmfields = g_strsplit(fields[3], "-", 3);
        if (tmfields[2]) {
                tm.tm_year = atoi (tmfields[0]) - 1900;
                tm.tm_mon = atoi (tmfields[1]);
                tm.tm_mday = atoi (tmfields[2]);
        }
        g_strfreev (tmfields);
        tmfields = g_strsplit (fields[4], ":", 2);
        if (tmfields[1]) {
                tm.tm_hour = atoi (tmfields[0]);
                tm.tm_min = atoi (tmfields[1]);
        }
        g_strfreev (tmfields);
        fdata->modified = mktime (&tm);
        g_strfreev (fields);

        name = get_last_field (line, 6);
        fields = g_strsplit (name, " -> ", 2);

        fdata->dir = line[0] == 'd';
        name = fields[0];
        if (g_str_has_prefix (name, "./")) { /* Should generally be the case */
                fdata->full_path = g_strdup (name + 1);
                fdata->original_path = fdata->full_path + 1;
        } else if (name[0] == '/') {
                fdata->full_path = g_strdup (name);
                fdata->original_path = fdata->full_path;
        } else {
                fdata->full_path = g_strconcat ("/", name, NULL);
                fdata->original_path = fdata->full_path + 1;
        }
        if (fdata->dir && (name[strlen (name) - 1] != '/')) {
                char *old_full_path = fdata->full_path;
                fdata->full_path = g_strconcat (old_full_path, "/", NULL);
                g_free (old_full_path);
                fdata->original_path = g_strdup (name);
                fdata->free_original_path = TRUE;
        }

        if (fields[1] != NULL)
                fdata->link = g_strdup (fields[1]);
        g_strfreev (fields);

        if (fdata->dir)
                fdata->name = dir_name_from_path (fdata->full_path);
        else
                fdata->name = g_strdup (file_name_from_path (fdata->full_path));
        fdata->path = remove_level_from_path (fdata->full_path);

        if (*fdata->name == 0)
                file_data_free (fdata);
        else
                fr_command_add_file (comm, fdata);
}
Пример #5
0
static void
process_line (char     *line,
	      gpointer  data)
{
	FileData      *fdata;
	FrCommandAce  *ace_comm = FR_COMMAND_ACE (data);
	FrCommand     *comm = FR_COMMAND (data);
	char         **fields = NULL;
	const char    *field_name = NULL;

	g_return_if_fail (line != NULL);

	if (ace_comm->command_type == FR_ACE_COMMAND_UNKNOWN) {
		if (g_str_has_prefix (line, "UNACE")) {
			if (strstr (line, "public version") != NULL)
				ace_comm->command_type = FR_ACE_COMMAND_PUBLIC;
			else
				ace_comm->command_type = FR_ACE_COMMAND_NONFREE;
		}
		return;
	}

	if (! ace_comm->list_started) {
		if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) {
			if (g_str_has_prefix (line, "Date"))
				ace_comm->list_started = TRUE;
		}
		else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE) {
			if (g_str_has_prefix (line, "  Date"))
				ace_comm->list_started = TRUE;
		}
		return;
	}

	fdata = file_data_new ();

	if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC)
		fields = g_strsplit (line, "|", 6);
	else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE)
		fields = split_line (line, 5);

	if ((fields == NULL) || (fields[0] == NULL) || (n_fields (fields) < 5))
		return;

	fdata->size = g_ascii_strtoull (fields[3], NULL, 10);
	fdata->modified = mktime_from_string (fields[0], fields[1]);

	if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) {
		field_name = fields[5];
		field_name = field_name + 1;
	}
	else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE)
		field_name = get_last_field (line, 6);

        g_assert (field_name != NULL);
	if (field_name[0] != '/') {
		fdata->full_path = g_strconcat ("/", field_name, NULL);
		fdata->original_path = fdata->full_path + 1;
	}
	else {
		fdata->full_path = g_strdup (field_name);
		fdata->original_path = fdata->full_path;
	}

	g_strfreev (fields);

	fdata->name = g_strdup (file_name_from_path (fdata->full_path));
	fdata->path = remove_level_from_path (fdata->full_path);

	if (*fdata->name == 0)
		file_data_free (fdata);
	else
		fr_command_add_file (comm, fdata);
}
Пример #6
0
static void
list__process_line (char     *line,
		    gpointer  data)
{
	FileData    *fdata;
	FrCommand   *comm = FR_COMMAND (data);
	char       **fields;
	const char  *name_field;
	char        *name;
	int          ofs = 0;

	g_return_if_fail (line != NULL);

	fdata = file_data_new ();

#ifdef __sun
	fields = split_line (line, 9);
	fdata->size = g_ascii_strtoull (fields[4], NULL, 10);
	fdata->modified = mktime_from_string (fields[5], fields[6], fields[8]);
	g_strfreev (fields);

	name_field = get_last_field (line, 10);
#else /* !__sun */
	/* Handle char and block device files */
	if ((line[0] == 'c') || (line[0] == 'b')) {
		fields = split_line (line, 9);
		ofs = 1;
		fdata->size = 0;
		/* FIXME: We should also specify the content type */
	}
	else {
		fields = split_line (line, 8);
		fdata->size = g_ascii_strtoull (fields[4], NULL, 10);
	}
	fdata->modified = mktime_from_string (fields[5+ofs], fields[6+ofs], fields[7+ofs]);
	g_strfreev (fields);

	name_field = get_last_field (line, 9+ofs);
#endif /* !__sun */

	fields = g_strsplit (name_field, " -> ", 2);

	if (fields[1] == NULL) {
		g_strfreev (fields);
		fields = g_strsplit (name_field, " link to ", 2);
	}

	fdata->dir = line[0] == 'd';

	name = g_strcompress (fields[0]);
	if (*(fields[0]) == '/') {
		fdata->full_path = g_strdup (name);
		fdata->original_path = fdata->full_path;
	}
	else {
		fdata->full_path = g_strconcat ("/", name, NULL);
		fdata->original_path = fdata->full_path + 1;
	}

	if (fdata->dir && (name[strlen (name) - 1] != '/')) {
		char *old_full_path = fdata->full_path;
		fdata->full_path = g_strconcat (old_full_path, "/", NULL);
		g_free (old_full_path);
		fdata->original_path = g_strdup (name);
		fdata->free_original_path = TRUE;
	}
	g_free (name);

	if (fields[1] != NULL)
		fdata->link = g_strcompress (fields[1]);
	g_strfreev (fields);

	if (fdata->dir)
		fdata->name = dir_name_from_path (fdata->full_path);
	else
		fdata->name = g_strdup (file_name_from_path (fdata->full_path));
	fdata->path = remove_level_from_path (fdata->full_path);

	if (*fdata->name == 0)
		file_data_free (fdata);
	else
		fr_command_add_file (comm, fdata);
}
Пример #7
0
static void
list__process_line (char     *line,
		    gpointer  data)
{
	FileData    *fdata;
	FrCommand   *comm = FR_COMMAND (data);
	char       **fields;
	const char  *name_field;
	gint         line_l;

	g_return_if_fail (line != NULL);

	/* check whether unzip gave the empty archive warning. */

	if (FR_COMMAND_ZIP (comm)->is_empty)
		return;

	line_l = strlen (line);

	if (line_l == 0)
		return;

	if (strcmp (line, EMPTY_ARCHIVE_WARNING) == 0) {
		FR_COMMAND_ZIP (comm)->is_empty = TRUE;
		return;
	}

	/* ignore lines that do not describe a file or a
	 * directory. */
	if ((line[0] != '?') && (line[0] != 'd') && (line[0] != '-'))
		return;

	/**/

	fdata = file_data_new ();

	fields = split_line (line, 7);
	fdata->size = g_ascii_strtoull (fields[3], NULL, 10);
	fdata->modified = mktime_from_string (fields[6]);
	fdata->encrypted = (*fields[4] == 'B') || (*fields[4] == 'T');
	g_strfreev (fields);

	/* Full path */

	name_field = get_last_field (line, 8);

	if (*name_field == '/') {
		fdata->full_path = g_strdup (name_field);
		fdata->original_path = fdata->full_path;
	} else {
		fdata->full_path = g_strconcat ("/", name_field, NULL);
		fdata->original_path = fdata->full_path + 1;
	}

	fdata->link = NULL;

	fdata->dir = line[0] == 'd';
	if (fdata->dir)
		fdata->name = dir_name_from_path (fdata->full_path);
	else
		fdata->name = g_strdup (file_name_from_path (fdata->full_path));
	fdata->path = remove_level_from_path (fdata->full_path);

	if (*fdata->name == 0)
		file_data_free (fdata);
	else
		fr_command_add_file (comm, fdata);
}
Пример #8
0
/**
 * Internal function, used by other functions to read archive
 *
 * @param data Should contain AM_Archive type of data
 * @return TRUE if succeed, otherwise FAILED
 *
 */
static gboolean SevenZipOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
{
	indicateProcessingData(TRUE);
	AM_Archive *archive = data;
	gchar **fields = NULL;
	gchar *filename = NULL;
	gchar *line = NULL;
	GtkTreeIter iter;
	GIOStatus status = G_IO_STATUS_NORMAL;

	if (cond & (G_IO_IN | G_IO_PRI) )
	{
		do
		{
			/* This to avoid inserting in the liststore 7zip's message */
			if (jump_header == FALSE )
			{
				for ( x = 0; x <= 7; x++)
				{
					status = g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
					g_free (line);
				}
				jump_header = TRUE;
			}
			status = g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
			if ( line == NULL )
				break;

			/* This to avoid inserting the last line of output */
			if (strncmp (line, "-----------------", 17) == 0 || strncmp (line, "\x0a",1) == 0)
			{
				g_free (line);
				status = g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
				g_free (line);
				break;
			}

			fields = split_line ( line , 5 );
			filename = get_last_field ( line , 6);
			gtk_list_store_append (archive->liststore, &iter);
			if ( g_str_has_prefix(fields[2] , "D") == FALSE)
				archive->nr_of_files++;
			else
				archive->nr_of_dirs++;
			for ( x = 0; x < 5; x++)
			{
				if (x == 3)
					gtk_list_store_set (archive->liststore, &iter,1,strtoll(fields[3],NULL,0),-1);
				else if (x == 4)
					gtk_list_store_set (archive->liststore, &iter,2,strtoll(fields[4],NULL,0),-1);
				else
					gtk_list_store_set (archive->liststore, &iter,(5-x),fields[x],-1);
			}
			archive->dummy_size += strtoll(fields[3],NULL,0);
			if ( filename == NULL )
				gtk_list_store_set (archive->liststore, &iter,0,fields[4],-1);
			else
				gtk_list_store_set (archive->liststore, &iter,0,filename,-1);
			g_strfreev ( fields );

			while (gtk_events_pending() )
				gtk_main_iteration();
			g_free (line);
		}
		while (status == G_IO_STATUS_NORMAL);
		if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
			goto done;
	}
	else if (cond & (G_IO_ERR | G_IO_HUP) )
	{
done:	g_io_channel_shutdown ( ioc,TRUE,NULL );
		g_io_channel_unref (ioc);
		gtk_tree_view_set_model (GTK_TREE_VIEW(archive->treeview), archive->model);
		g_object_unref (archive->model);
		indicateProcessingData(FALSE);
		return FALSE;
	}
	indicateProcessingData(FALSE);
	return TRUE;
}
Пример #9
0
static void
list__process_line (char     *line,
		    gpointer  data)
{
	FrCommand     *comm = FR_COMMAND (data);
	FrCommandArj  *arj_comm = FR_COMMAND_ARJ (comm);

	g_return_if_fail (line != NULL);

	if (! arj_comm->list_started) {
		if (strncmp (line, "--------", 8) == 0) {
			arj_comm->list_started = TRUE;
			arj_comm->line_no = 1;
		}
		return;
	}

	if (strncmp (line, "--------", 8) == 0) {
		arj_comm->list_started = FALSE;
		return;
	}

	if (g_regex_match (arj_comm->filename_line_regex, line, 0, NULL)) { /* Read the filename. */
		FileData   *fdata;
		const char *name_field;

		arj_comm->line_no = 1;

		arj_comm->fdata = fdata = file_data_new ();

		name_field = get_last_field (line, 2);

		if (*name_field == '/') {
			fdata->full_path = g_strdup (name_field);
			fdata->original_path = fdata->full_path;
		}
		else {
			fdata->full_path = g_strconcat ("/", name_field, NULL);
			fdata->original_path = fdata->full_path + 1;
		}

		fdata->link = NULL;

		fdata->name = g_strdup (file_name_from_path (fdata->full_path));
		fdata->path = remove_level_from_path (fdata->full_path);
	}
	else if (arj_comm->line_no == 2) { /* Read file size and date. */
		FileData  *fdata;
		char     **fields;

		fdata = arj_comm->fdata;

		/* read file info. */

		fields = split_line (line, 10);
		fdata->size = g_ascii_strtoull (fields[2], NULL, 10);
		fdata->modified = mktime_from_string (fields[5], fields[6]);
		if ((strcmp (fields[1], "MS-DOS") == 0) || (strcmp (fields[1], "WIN32") == 0))
			fdata->encrypted = (g_ascii_strcasecmp (fields[7], "11") == 0);
		else
			fdata->encrypted = (g_ascii_strcasecmp (fields[9], "11") == 0);
		g_strfreev (fields);

		if (*fdata->name == 0)
			file_data_free (fdata);
		else
			fr_command_add_file (comm, fdata);
		arj_comm->fdata = NULL;
	}

	arj_comm->line_no++;
}