static void
fr_command_lrzip_add (FrCommand  *comm,
		      const char *from_file,
		      GList      *file_list,
		      const char *base_dir,
		      gboolean    update,
		      gboolean    follow_links)
{
	fr_process_begin_command (comm->process, "lrzip");

	if (base_dir != NULL)
		fr_process_set_working_dir (comm->process, base_dir);

	/* preserve links. */

	switch (FR_ARCHIVE (comm)->compression) {
	case FR_COMPRESSION_VERY_FAST:
		fr_process_add_arg (comm->process, "-l"); break;
	case FR_COMPRESSION_FAST:
		fr_process_add_arg (comm->process, "-g"); break;
	case FR_COMPRESSION_NORMAL:
		fr_process_add_arg (comm->process, "-b"); break;
	case FR_COMPRESSION_MAXIMUM:
		fr_process_add_arg (comm->process, "-z"); break;
	}

	fr_process_add_arg (comm->process, "-o");
	fr_process_add_arg (comm->process, comm->filename);
	fr_process_add_arg (comm->process, (char *) file_list->data);

	fr_process_end_command (comm->process);
}
Example #2
0
static void
process_line__extract (char     *line,
		       gpointer  data)
{
	FrArchive *archive = FR_ARCHIVE (data);

	if (fr_archive_progress_get_total_files (archive) > 0)
		parse_progress_line (archive, "Extracting  ", _("Extracting \"%s\""), line);
}
static void
list_command_completed (gpointer data)
{
	FrCommandUnarchiver *unar_comm = FR_COMMAND_UNARCHIVER (data);
	JsonParser          *parser;
	GError              *error = NULL;

	parser = json_parser_new ();
	if (json_parser_load_from_stream (parser, unar_comm->stream, NULL, &error)) {
		JsonObject *root;

		root = json_node_get_object (json_parser_get_root (parser));

		if (json_object_get_int_member (root, "lsarFormatVersion") == LSAR_SUPPORTED_FORMAT) {
			JsonArray *content;
			int        i;

			content = json_object_get_array_member (root, "lsarContents");
			for (i = 0; i < json_array_get_length (content); i++) {
				JsonObject *entry;
				FileData   *fdata;
				const char *filename;

				entry = json_array_get_object_element (content, i);
				fdata = file_data_new ();
				fdata->size = json_object_get_int_member (entry, "XADFileSize");
				fdata->modified = mktime_from_string (json_object_get_string_member (entry, "XADLastModificationDate"));
				if (json_object_has_member (entry, "XADIsEncrypted"))
					fdata->encrypted = json_object_get_int_member (entry, "XADIsEncrypted") == 1;

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

				fdata->link = NULL;
				if (json_object_has_member (entry, "XADIsDirectory"))
					fdata->dir = json_object_get_int_member (entry, "XADIsDirectory") == 1;
				if (fdata->dir)
					fdata->name = _g_path_get_dir_name (fdata->full_path);
				else
					fdata->name = g_strdup (_g_path_get_basename (fdata->full_path));
				fdata->path = _g_path_remove_level (fdata->full_path);

				fr_archive_add_file (FR_ARCHIVE (unar_comm), fdata);
			}
		}
	}

	g_object_unref (parser);
}
Example #4
0
static void
fr_command_7z_delete (FrCommand  *command,
		      const char *from_file,
		      GList      *file_list)
{
	FrArchive *archive = FR_ARCHIVE (command);
	GList     *scan;

	fr_command_7z_begin_command (command);
	fr_process_add_arg (command->process, "d");
	fr_process_add_arg (command->process, "-bd");
	fr_process_add_arg (command->process, "-y");
	if (_g_mime_type_matches (FR_ARCHIVE (command)->mime_type, "application/x-ms-dos-executable"))
		fr_process_add_arg (command->process, "-sfx");

	if (_g_mime_type_matches (archive->mime_type, "application/zip")
	    || _g_mime_type_matches (archive->mime_type, "application/x-cbz"))
	{
		fr_process_add_arg (command->process, "-tzip");
	}

	if (from_file != NULL)
		fr_process_add_arg_concat (command->process, "-i@", from_file, NULL);

	if (from_file == NULL)
		for (scan = file_list; scan; scan = scan->next)
			/* Files prefixed with '@' need to be handled specially */
			if (g_str_has_prefix (scan->data, "@"))
				fr_process_add_arg_concat (command->process, "-i!", scan->data, NULL);

	add_password_arg (command, FR_ARCHIVE (command)->password, FALSE);

	fr_process_add_arg (command->process, "--");
	fr_process_add_arg (command->process, command->filename);

	if (from_file == NULL)
		for (scan = file_list; scan; scan = scan->next)
			/* Skip files prefixed with '@', already added */
			if (!g_str_has_prefix (scan->data, "@"))
				fr_process_add_arg (command->process, scan->data);

	fr_process_end_command (command->process);
}
static gboolean
fr_command_unarchiver_list (FrCommand  *comm)
{
	FrCommandUnarchiver *unar_comm = FR_COMMAND_UNARCHIVER (comm);

	_g_object_unref (unar_comm->stream);
	unar_comm->stream = g_memory_input_stream_new ();

	fr_process_set_out_line_func (comm->process, process_line, comm);

	fr_process_begin_command (comm->process, "lsar");
	fr_process_set_end_func (comm->process, list_command_completed, comm);
	fr_process_add_arg (comm->process, "-j");
	if ((FR_ARCHIVE (comm)->password != NULL) && (FR_ARCHIVE (comm)->password[0] != '\0'))
		fr_process_add_arg_concat (comm->process, "-password=", FR_ARCHIVE (comm)->password, NULL);
	fr_process_add_arg (comm->process, comm->filename);
	fr_process_end_command (comm->process);

	return TRUE;
}
static void
fr_command_unarchiver_extract (FrCommand  *comm,
			       const char *from_file,
			       GList      *file_list,
			       const char *dest_dir,
			       gboolean    overwrite,
			       gboolean    skip_older,
			       gboolean    junk_paths)
{
	FrCommandUnarchiver *unar_comm = FR_COMMAND_UNARCHIVER (comm);
	GList               *scan;

	unar_comm->n_line = 0;

	fr_process_use_standard_locale (comm->process, TRUE);
	fr_process_set_out_line_func (comm->process,
				      process_line__extract,
				      comm);

	fr_process_begin_command (comm->process, "unar");

	if (overwrite)
		fr_process_add_arg (comm->process, "-f");
	else
		fr_process_add_arg (comm->process, "-s");

	fr_process_add_arg (comm->process, "-D");

	if ((FR_ARCHIVE (comm)->password != NULL) && (FR_ARCHIVE (comm)->password[0] != '\0'))
		fr_process_add_arg_concat (comm->process, "-password="******"-output-directory=", dest_dir, NULL);

	fr_process_add_arg (comm->process, comm->filename);

	for (scan = file_list; scan; scan = scan->next)
		fr_process_add_arg (comm->process, scan->data);

	fr_process_end_command (comm->process);
}
Example #7
0
static void
fr_command_ace_init (FrCommandAce *self)
{
	FrArchive *base = FR_ARCHIVE (self);

	base->propAddCanUpdate             = TRUE;
	base->propAddCanReplace            = TRUE;
	base->propExtractCanAvoidOverwrite = FALSE;
	base->propExtractCanSkipOlder      = FALSE;
	base->propExtractCanJunkPaths      = TRUE;
	base->propPassword                 = FALSE;
	base->propTest                     = TRUE;
}
Example #8
0
static void
fr_command_7z_extract (FrCommand  *command,
		       const char *from_file,
		       GList      *file_list,
		       const char *dest_dir,
		       gboolean    overwrite,
		       gboolean    skip_older,
		       gboolean    junk_paths)
{
	FrArchive *archive = FR_ARCHIVE (command);
	GList     *scan;

	fr_process_use_standard_locale (command->process, TRUE);
	fr_process_set_out_line_func (command->process,
				      process_line__extract,
				      command);
	fr_command_7z_begin_command (command);

	if (junk_paths)
		fr_process_add_arg (command->process, "e");
	else
		fr_process_add_arg (command->process, "x");

	fr_process_add_arg (command->process, "-bd");
	fr_process_add_arg (command->process, "-y");
	add_password_arg (command, archive->password, FALSE);

	if (dest_dir != NULL)
		fr_process_add_arg_concat (command->process, "-o", dest_dir, NULL);

	if (from_file != NULL)
		fr_process_add_arg_concat (command->process, "-i@", from_file, NULL);

	if (from_file == NULL)
		for (scan = file_list; scan; scan = scan->next)
			/* Files prefixed with '@' need to be handled specially */
			if (g_str_has_prefix (scan->data, "@"))
				fr_process_add_arg_concat (command->process, "-i!", scan->data, NULL);


	fr_process_add_arg (command->process, "--");
	fr_process_add_arg (command->process, command->filename);

	if (from_file == NULL)
		for (scan = file_list; scan; scan = scan->next)
			/* Skip files prefixed with '@', already added */
			if (!g_str_has_prefix (scan->data, "@"))
				fr_process_add_arg (command->process, scan->data);

	fr_process_end_command (command->process);
}
Example #9
0
static void
fr_command_7z_handle_error (FrCommand *command,
			    FrError   *error)
{
	FrArchive *archive = FR_ARCHIVE (command);

	if (error->type == FR_ERROR_NONE) {
		FileData *first;
		char     *basename;
		char     *testname;

		/* This is a way to fix bug #582712. */

		if (archive->files->len != 1)
			return;

		if (! g_str_has_suffix (command->filename, ".001"))
			return;

		first = g_ptr_array_index (archive->files, 0);
		basename = g_path_get_basename (command->filename);
		testname = g_strconcat (first->original_path, ".001", NULL);

		if (strcmp (basename, testname) == 0)
			fr_error_take_gerror (error, g_error_new_literal (FR_ERROR, FR_ERROR_ASK_PASSWORD, ""));

		g_free (testname);
		g_free (basename);

		return;
	}

	if (error->status <= 1) {
		/* ignore warnings */
		fr_error_clear_gerror (error);
	}
	else {
		GList *scan;

		for (scan = g_list_last (command->process->out.raw); scan; scan = scan->prev) {
			char *line = scan->data;

			if ((strstr (line, "Wrong password?") != NULL)
			    || (strstr (line, "Enter password") != NULL))
			{
				fr_error_take_gerror (error, g_error_new_literal (FR_ERROR, FR_ERROR_ASK_PASSWORD, ""));
				break;
			}
		}
	}
}
Example #10
0
static void
fr_command_cpio_init (FrCommandCpio *self)
{
	FrArchive *base = FR_ARCHIVE (self);

	base->propAddCanUpdate             = FALSE;
	base->propAddCanReplace            = FALSE;
	base->propAddCanStoreFolders       = FALSE;
	base->propExtractCanAvoidOverwrite = FALSE;
	base->propExtractCanSkipOlder      = FALSE;
	base->propExtractCanJunkPaths      = FALSE;
	base->propPassword                 = FALSE;
	base->propTest                     = FALSE;
}
Example #11
0
static void
fr_command_7z_test (FrCommand *command)
{
	FrArchive *archive = FR_ARCHIVE (command);

	fr_command_7z_begin_command (command);
	fr_process_add_arg (command->process, "t");
	fr_process_add_arg (command->process, "-bd");
	fr_process_add_arg (command->process, "-y");
	add_password_arg (command, archive->password, FALSE);
	fr_process_add_arg (command->process, "--");
	fr_process_add_arg (command->process, command->filename);
	fr_process_end_command (command->process);
}
static void
fr_command_unarchiver_init (FrCommandUnarchiver *self)
{
	FrArchive *base = FR_ARCHIVE (self);

	base->propExtractCanAvoidOverwrite = TRUE;
	base->propExtractCanSkipOlder      = FALSE;
	base->propExtractCanJunkPaths      = FALSE;
	base->propPassword                 = TRUE;
	base->propTest                     = FALSE;
	base->propListFromFile             = FALSE;

	self->stream = NULL;
}
Example #13
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
list__process_line (char     *line,
		    gpointer  data)
{
	FileData  *fdata;
	FrCommand *comm = FR_COMMAND (data);

	g_return_if_fail (line != NULL);

	if (strlen (line) == 0)
		return;

	if (! g_str_has_prefix (line, "Decompressed file size:"))
		return;

	fdata = file_data_new ();
	fdata->size = g_ascii_strtoull (_g_str_get_last_field (line, 4), NULL, 10);

	struct stat st;
	if (stat (comm->filename, &st) == 0)
		fdata->modified = st.st_mtim.tv_sec;
	else
		time(&(fdata->modified));

	fdata->encrypted = FALSE;

	char *new_fname = g_strdup (_g_path_get_basename (comm->filename));
	if (g_str_has_suffix (new_fname, ".lrz"))
		new_fname[strlen (new_fname) - 4] = '\0';

	if (*new_fname == '/') {
		fdata->full_path = g_strdup (new_fname);
		fdata->original_path = fdata->full_path;
	}
	else {
		fdata->full_path = g_strconcat ("/", new_fname, NULL);
		fdata->original_path = fdata->full_path + 1;
	}
	fdata->path = _g_path_remove_level (fdata->full_path);
	fdata->name = new_fname;
	fdata->dir = FALSE;
	fdata->link = NULL;

	if (fdata->name == 0)
		file_data_free (fdata);
	else
		fr_archive_add_file (FR_ARCHIVE (comm), fdata);
}
Example #15
0
static gboolean
fr_command_7z_list (FrCommand *command)
{
	rar_check_multi_volume (command);

	fr_process_set_out_line_func (command->process, list__process_line, command);

	fr_command_7z_begin_command (command);
	fr_process_set_begin_func (command->process, list__begin, command);
	fr_process_add_arg (command->process, "l");
	fr_process_add_arg (command->process, "-slt");
	fr_process_add_arg (command->process, "-bd");
	fr_process_add_arg (command->process, "-y");
	add_password_arg (command, FR_ARCHIVE (command)->password, FALSE);
	fr_process_add_arg (command->process, "--");
	fr_process_add_arg (command->process, command->filename);
	fr_process_end_command (command->process);

	return TRUE;
}
static void
add_compress_arg (FrCommand *comm)
{
	FrArchive *archive = FR_ARCHIVE (comm);

	if (_g_mime_type_matches (archive->mime_type, "application/x-compressed-tar"))
		fr_process_add_arg (comm->process, "-z");

	else if (_g_mime_type_matches (archive->mime_type, "application/x-bzip-compressed-tar"))
		fr_process_add_arg (comm->process, "--use-compress-program=bzip2");

	else if (_g_mime_type_matches (archive->mime_type, "application/x-tarz")) {
		if (_g_program_is_in_path ("gzip"))
			fr_process_add_arg (comm->process, "-z");
		else
			fr_process_add_arg (comm->process, "-Z");
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lrzip-compressed-tar"))
		fr_process_add_arg (comm->process, "--use-compress-program=lrzip");

	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzip-compressed-tar"))
		fr_process_add_arg (comm->process, "--use-compress-program=lzip");

	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzma-compressed-tar"))
		fr_process_add_arg (comm->process, "--use-compress-program=lzma");

	else if (_g_mime_type_matches (archive->mime_type, "application/x-xz-compressed-tar"))
		fr_process_add_arg (comm->process, "--use-compress-program=xz");

	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzop-compressed-tar"))
		fr_process_add_arg (comm->process, "--use-compress-program=lzop");

	else if (_g_mime_type_matches (archive->mime_type, "application/x-7z-compressed-tar")) {
		FrCommandTar *comm_tar = (FrCommandTar*) comm;
		char         *option;

		option = g_strdup_printf ("--use-compress-program=%s", comm_tar->compress_command);
		fr_process_add_arg (comm->process, option);
		g_free (option);
	}
}
Example #17
0
static void
process_line__add (char     *line,
		   gpointer  data)
{
	FrCommand *command = FR_COMMAND (data);
	FrArchive *archive = FR_ARCHIVE (data);

	if ((archive->volume_size > 0) && (strncmp (line, "Creating archive ", 17) == 0)) {
		char  *volume_filename;
		GFile *volume_file;

		volume_filename = g_strconcat (command->filename, ".001", NULL);
		volume_file = g_file_new_for_path (volume_filename);
		fr_archive_set_multi_volume (archive, volume_file);

		g_object_unref (volume_file);
		g_free (volume_filename);
	}

	if (fr_archive_progress_get_total_files (archive) > 0)
		parse_progress_line (archive, "Compressing  ", _("Adding \"%s\""), line);
}
static void
process_line__extract (char     *line,
		       gpointer  data)
{
	FrCommand           *comm = FR_COMMAND (data);
	FrArchive           *archive = FR_ARCHIVE (comm);
	FrCommandUnarchiver *unar_comm = FR_COMMAND_UNARCHIVER (comm);

	if (line == NULL)
		return;

	unar_comm->n_line++;

	/* the first line is the name of the archive */
	if (unar_comm->n_line == 1)
		return;

	if (fr_archive_progress_get_total_files (archive) > 1)
		fr_archive_progress (archive, fr_archive_progress_inc_completed_files (archive, 1));
	else
		fr_archive_message (archive, line);
}
static void
process_line__generic (char     *line,
		       gpointer  data,
		       char     *message_format)
{
	FrCommand *comm = FR_COMMAND (data);
	FrArchive *archive = FR_ARCHIVE (comm);

	if (line == NULL)
		return;

	if (line[strlen (line) - 1] == '/') /* ignore directories */
		return;

	if (fr_archive_progress_get_total_files (archive) > 1) {
		fr_archive_progress (archive, fr_archive_progress_inc_completed_files (archive, 1));
	}
	else {
		char *msg = g_strdup_printf (message_format, _g_path_get_basename (line), NULL);
		fr_archive_message (archive, msg);
		g_free (msg);
	}
}
Example #20
0
static void
fr_command_7z_add (FrCommand  *command,
		   const char *from_file,
		   GList      *file_list,
		   const char *base_dir,
		   gboolean    update,
		   gboolean    follow_links)
{
	FrArchive *archive = FR_ARCHIVE (command);
	GList     *scan;

	fr_process_use_standard_locale (command->process, TRUE);
	fr_process_set_out_line_func (command->process,
				      process_line__add,
				      command);

	fr_command_7z_begin_command (command);

	if (update)
		fr_process_add_arg (command->process, "u");
	else
		fr_process_add_arg (command->process, "a");

	if (base_dir != NULL)
		fr_process_set_working_dir (command->process, base_dir);

	if (_g_mime_type_matches (archive->mime_type, "application/zip")
	    || _g_mime_type_matches (archive->mime_type, "application/x-cbz"))
	{
		fr_process_add_arg (command->process, "-tzip");
		fr_process_add_arg (command->process, "-mem=AES128");
	}

	fr_process_add_arg (command->process, "-bd");
	fr_process_add_arg (command->process, "-y");
	if (follow_links)
		fr_process_add_arg (command->process, "-l");
	add_password_arg (command, archive->password, FALSE);
	if ((archive->password != NULL)
	    && (*archive->password != 0)
	    && archive->encrypt_header
	    && fr_archive_is_capable_of (archive, FR_ARCHIVE_CAN_ENCRYPT_HEADER))
	{
		fr_process_add_arg (command->process, "-mhe=on");
	}

	/* fr_process_add_arg (command->process, "-ms=off"); FIXME: solid mode off? */

	switch (archive->compression) {
	case FR_COMPRESSION_VERY_FAST:
		fr_process_add_arg (command->process, "-mx=1");
		break;
	case FR_COMPRESSION_FAST:
		fr_process_add_arg (command->process, "-mx=5");
		break;
	case FR_COMPRESSION_NORMAL:
		fr_process_add_arg (command->process, "-mx=7");
		break;
	case FR_COMPRESSION_MAXIMUM:
		fr_process_add_arg (command->process, "-mx=9");
		if (! _g_mime_type_matches (archive->mime_type, "application/zip")
		    && ! _g_mime_type_matches (archive->mime_type, "application/x-cbz"))
		{
			fr_process_add_arg (command->process, "-m0=lzma2");;
		}
		break;
	}

	if (_g_mime_type_matches (archive->mime_type, "application/x-ms-dos-executable"))
		fr_process_add_arg (command->process, "-sfx");

	if (archive->volume_size > 0)
		fr_process_add_arg_printf (command->process, "-v%ub", archive->volume_size);

	if (from_file != NULL)
		fr_process_add_arg_concat (command->process, "-i@", from_file, NULL);

	if (from_file == NULL)
		for (scan = file_list; scan; scan = scan->next)
			/* Files prefixed with '@' need to be handled specially */
			if (g_str_has_prefix (scan->data, "@"))
				fr_process_add_arg_concat (command->process, "-i!", scan->data, NULL);

	fr_process_add_arg (command->process, "--");
	fr_process_add_arg (command->process, command->filename);

	if (from_file == NULL)
		for (scan = file_list; scan; scan = scan->next)
			/* Skip files prefixed with '@', already added */
			if (!g_str_has_prefix (scan->data, "@"))
				fr_process_add_arg (command->process, scan->data);

	fr_process_end_command (command->process);
}
Example #21
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;
	const char    *field_name;

	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 = _g_str_split_line (line, 5);
	else
		fields = NULL;

	if ((fields == NULL) || (fields[0] == NULL) || (g_strv_length (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 = _g_str_get_last_field (line, 6);
	else
		g_assert_not_reached ();

	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 (_g_path_get_basename (fdata->full_path));
	fdata->path = _g_path_remove_level (fdata->full_path);

	if (*fdata->name == 0)
		file_data_free (fdata);
	else
		fr_archive_add_file (FR_ARCHIVE (comm), fdata);
}
Example #22
0
static void
list__process_line (char     *line,
		    gpointer  data)
{
	FrCommand7z  *self = FR_COMMAND_7Z (data);
	FrArchive    *archive = FR_ARCHIVE (data);
	char        **fields;
	FileData     *fdata;

	g_return_if_fail (line != NULL);

	if (! self->list_started) {
		if (strncmp (line, "p7zip Version ", 14) == 0) {
			const char *ver_start;
			int         ver_len;
			char        version[256];

			ver_start = _g_str_eat_spaces (line + 14);
			ver_len = strchr (ver_start, ' ') - ver_start;
			strncpy (version, ver_start, ver_len);
			version[ver_len] = 0;

			if (strcmp (version, "4.55") < 0)
				self->old_style = TRUE;
			else
				self->old_style = FALSE;
		}
		else if (self->old_style && (strncmp (line, "Listing archive: ", 17) == 0))
			self->list_started = TRUE;
		else if (! self->old_style && (strcmp (line, "----------") == 0))
			self->list_started = TRUE;
		else if (strncmp (line, "Multivolume = ", 14) == 0) {
			fields = g_strsplit (line, " = ", 2);
			archive->multi_volume = (strcmp (fields[1], "+") == 0);
			g_strfreev (fields);
		}
		return;
	}

	if (strcmp (line, "") == 0) {
		if (self->fdata != NULL) {
			if (self->fdata->original_path == NULL) {
				file_data_free (self->fdata);
				self->fdata = NULL;
			}
			else {
				fdata = self->fdata;
				if (fdata->dir)
					fdata->name = _g_path_get_dir_name (fdata->full_path);
				else
					fdata->name = g_strdup (_g_path_get_basename (fdata->full_path));
				fdata->path = _g_path_remove_level (fdata->full_path);
				fr_archive_add_file (archive, fdata);
				self->fdata = NULL;
			}
		}
		return;
	}

	if (self->fdata == NULL)
		self->fdata = file_data_new ();

	fields = g_strsplit (line, " = ", 2);

	if (g_strv_length (fields) < 2) {
		g_strfreev (fields);
		return;
	}

	fdata = self->fdata;

	if (strcmp (fields[0], "Path") == 0) {
		fdata->free_original_path = TRUE;
		fdata->original_path = g_strdup (fields[1]);
		fdata->full_path = g_strconcat ((fdata->original_path[0] != '/') ? "/" : "",
						fdata->original_path,
						(fdata->dir && (fdata->original_path[strlen (fdata->original_path) - 1] != '/')) ? "/" : "",
						NULL);
	}
	else if (strcmp (fields[0], "Folder") == 0) {
		fdata->dir = (strcmp (fields[1], "+") == 0);
	}
	else if (strcmp (fields[0], "Size") == 0) {
		fdata->size = g_ascii_strtoull (fields[1], NULL, 10);
	}
	else if (strcmp (fields[0], "Modified") == 0) {
		char **modified_fields;

		modified_fields = g_strsplit (fields[1], " ", 2);
		if (modified_fields[0] != NULL)
			fdata->modified = mktime_from_string (modified_fields[0], modified_fields[1]);
		g_strfreev (modified_fields);
	}
	else if (strcmp (fields[0], "Encrypted") == 0) {
		if (strcmp (fields[1], "+") == 0)
			fdata->encrypted = TRUE;
	}
	else if (strcmp (fields[0], "Method") == 0) {
		if (strstr (fields[1], "AES") != NULL)
			fdata->encrypted = TRUE;
	}
	else if (strcmp (fields[0], "Attributes") == 0) {
		if (fields[1][0] == 'D')
			fdata->dir = TRUE;
	}
	g_strfreev (fields);
}
static void
fr_command_tar_recompress (FrCommand *comm)
{
	FrCommandTar *c_tar = FR_COMMAND_TAR (comm);
	FrArchive    *archive = FR_ARCHIVE (comm);
	char         *new_name = NULL;

	if (can_create_a_compressed_archive (comm))
		return;

	if (_g_mime_type_matches (archive->mime_type, "application/x-compressed-tar")) {
		fr_process_begin_command (comm->process, "gzip");
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		fr_process_set_continue_func (comm->process, gzip_continue_func, comm);
		switch (archive->compression) {
		case FR_COMPRESSION_VERY_FAST:
			fr_process_add_arg (comm->process, "-1"); break;
		case FR_COMPRESSION_FAST:
			fr_process_add_arg (comm->process, "-3"); break;
		case FR_COMPRESSION_NORMAL:
			fr_process_add_arg (comm->process, "-6"); break;
		case FR_COMPRESSION_MAXIMUM:
			fr_process_add_arg (comm->process, "-9"); break;
		}
		fr_process_add_arg (comm->process, "-f");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		new_name = g_strconcat (c_tar->uncomp_filename, ".gz", NULL);
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-bzip-compressed-tar")) {
		fr_process_begin_command (comm->process, "bzip2");
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		switch (archive->compression) {
		case FR_COMPRESSION_VERY_FAST:
			fr_process_add_arg (comm->process, "-1"); break;
		case FR_COMPRESSION_FAST:
			fr_process_add_arg (comm->process, "-3"); break;
		case FR_COMPRESSION_NORMAL:
			fr_process_add_arg (comm->process, "-6"); break;
		case FR_COMPRESSION_MAXIMUM:
			fr_process_add_arg (comm->process, "-9"); break;
		}
		fr_process_add_arg (comm->process, "-f");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		new_name = g_strconcat (c_tar->uncomp_filename, ".bz2", NULL);
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-tarz")) {
		fr_process_begin_command (comm->process, "compress");
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		fr_process_add_arg (comm->process, "-f");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		new_name = g_strconcat (c_tar->uncomp_filename, ".Z", NULL);
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lrzip-compressed-tar")) {
		fr_process_begin_command (comm->process, "lrzip");
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		switch (archive->compression) {
		case FR_COMPRESSION_VERY_FAST:
			fr_process_add_arg (comm->process, "-l"); break;
		case FR_COMPRESSION_FAST:
			fr_process_add_arg (comm->process, "-g"); break;
		case FR_COMPRESSION_NORMAL:
			fr_process_add_arg (comm->process, "-b"); break;
		case FR_COMPRESSION_MAXIMUM:
			fr_process_add_arg (comm->process, "-z"); break;
		}
		fr_process_add_arg (comm->process, "-o");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		new_name = g_strconcat (c_tar->uncomp_filename, ".lrz", NULL);
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzip-compressed-tar")) {
		fr_process_begin_command (comm->process, "lzip");
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		switch (archive->compression) {
		case FR_COMPRESSION_VERY_FAST:
			fr_process_add_arg (comm->process, "-1"); break;
		case FR_COMPRESSION_FAST:
			fr_process_add_arg (comm->process, "-3"); break;
		case FR_COMPRESSION_NORMAL:
			fr_process_add_arg (comm->process, "-6"); break;
		case FR_COMPRESSION_MAXIMUM:
			fr_process_add_arg (comm->process, "-9"); break;
		}
		fr_process_add_arg (comm->process, "-f");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		new_name = g_strconcat (c_tar->uncomp_filename, ".lz", NULL);
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzma-compressed-tar")) {
		fr_process_begin_command (comm->process, "lzma");
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		switch (archive->compression) {
		case FR_COMPRESSION_VERY_FAST:
			fr_process_add_arg (comm->process, "-1"); break;
		case FR_COMPRESSION_FAST:
			fr_process_add_arg (comm->process, "-3"); break;
		case FR_COMPRESSION_NORMAL:
			fr_process_add_arg (comm->process, "-6"); break;
		case FR_COMPRESSION_MAXIMUM:
			fr_process_add_arg (comm->process, "-9"); break;
		}
		fr_process_add_arg (comm->process, "-f");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		new_name = g_strconcat (c_tar->uncomp_filename, ".lzma", NULL);
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-xz-compressed-tar")) {
		fr_process_begin_command (comm->process, "xz");
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		switch (archive->compression) {
		case FR_COMPRESSION_VERY_FAST:
			fr_process_add_arg (comm->process, "-1"); break;
		case FR_COMPRESSION_FAST:
			fr_process_add_arg (comm->process, "-3"); break;
		case FR_COMPRESSION_NORMAL:
			fr_process_add_arg (comm->process, "-6"); break;
		case FR_COMPRESSION_MAXIMUM:
			fr_process_add_arg (comm->process, "-9"); break;
		}
		fr_process_add_arg (comm->process, "-f");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		new_name = g_strconcat (c_tar->uncomp_filename, ".xz", NULL);
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzop-compressed-tar")) {
		fr_process_begin_command (comm->process, "lzop");
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		switch (archive->compression) {
		case FR_COMPRESSION_VERY_FAST:
			fr_process_add_arg (comm->process, "-1"); break;
		case FR_COMPRESSION_FAST:
			fr_process_add_arg (comm->process, "-3"); break;
		case FR_COMPRESSION_NORMAL:
			fr_process_add_arg (comm->process, "-6"); break;
		case FR_COMPRESSION_MAXIMUM:
			fr_process_add_arg (comm->process, "-9"); break;
		}
		fr_process_add_arg (comm->process, "-fU");
		fr_process_add_arg (comm->process, "--no-stdin");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		new_name = g_strconcat (c_tar->uncomp_filename, ".lzo", NULL);
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-7z-compressed-tar")) {
		FrCommandTar *comm_tar = (FrCommandTar*) comm;

		fr_process_begin_command (comm->process, comm_tar->compress_command);
		fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
		switch (archive->compression) {
		case FR_COMPRESSION_VERY_FAST:
			fr_process_add_arg (comm->process, "-mx=1"); break;
		case FR_COMPRESSION_FAST:
			fr_process_add_arg (comm->process, "-mx=5"); break;
		case FR_COMPRESSION_NORMAL:
			fr_process_add_arg (comm->process, "-mx=5"); break;
		case FR_COMPRESSION_MAXIMUM:
			fr_process_add_arg (comm->process, "-mx=7"); break;
		}
		fr_process_add_arg (comm->process, "a");
		fr_process_add_arg (comm->process, "-bd");
		fr_process_add_arg (comm->process, "-y");
		fr_process_add_arg (comm->process, "-l");

		new_name = g_strconcat (c_tar->uncomp_filename, ".7z", NULL);
		fr_process_add_arg_concat (comm->process, new_name, NULL);

		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);

		/* remove the uncompressed tar */

		fr_process_begin_command (comm->process, "rm");
		fr_process_add_arg (comm->process, "-f");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
		fr_process_end_command (comm->process);
	}

	if (c_tar->name_modified) {
		char *tmp_dir;

		/* Restore original name. */

		fr_process_begin_command (comm->process, "mv");
		fr_process_add_arg (comm->process, "-f");
		fr_process_add_arg (comm->process, "--");
		fr_process_add_arg (comm->process, new_name);
		fr_process_add_arg (comm->process, comm->filename);
		fr_process_end_command (comm->process);

		tmp_dir = _g_path_remove_level (new_name);

		fr_process_begin_command (comm->process, "rm");
		fr_process_set_sticky (comm->process, TRUE);
		fr_process_add_arg (comm->process, "-fr");
		fr_process_add_arg (comm->process, tmp_dir);
		fr_process_end_command (comm->process);

		g_free (tmp_dir);
	}

	g_free (new_name);
	g_free (c_tar->uncomp_filename);
	c_tar->uncomp_filename = NULL;
}
static gboolean
can_create_a_compressed_archive (FrCommand *comm)
{
	return comm->creating_archive && ! _g_mime_type_matches (FR_ARCHIVE (comm)->mime_type, "application/x-7z-compressed-tar");
}
Example #25
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 = _g_str_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 = _g_str_get_last_field (line, 10);
#else /* !__sun */
	/* Handle char and block device files */
	if ((line[0] == 'c') || (line[0] == 'b')) {
		fields = _g_str_split_line (line, 9);
		ofs = 1;
		fdata->size = 0;
		/* FIXME: We should also specify the content type */
	}
	else {
		fields = _g_str_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 = _g_str_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 = _g_path_get_dir_name (fdata->full_path);
	else
		fdata->name = g_strdup (_g_path_get_basename (fdata->full_path));
	fdata->path = _g_path_remove_level (fdata->full_path);

	if (*fdata->name == 0)
		file_data_free (fdata);
	else
		fr_archive_add_file (FR_ARCHIVE (comm), fdata);
}
static void
process_line (char     *line,
	      gpointer  data)
{
	FileData    *fdata;
	FrCommand   *comm = FR_COMMAND (data);
	char       **fields;
	int          date_idx;
	char        *field_date, *field_time, *field_size, *field_name;
	char        *name;

	g_return_if_fail (line != NULL);

	date_idx = _g_line_get_index_from_pattern (line, "%n%n%n%n-%n%n-%n%n %n%n:%n%n");
	if (date_idx < 0)
		return;

	fdata = file_data_new ();

	field_size = _g_line_get_prev_field (line, date_idx, 1);
	fdata->size = g_ascii_strtoull (field_size, NULL, 10);
	g_free (field_size);

	field_date = _g_line_get_next_field (line, date_idx, 1);
	field_time = _g_line_get_next_field (line, date_idx, 2);
	fdata->modified = mktime_from_string (field_date, field_time);
	g_free (field_date);
	g_free (field_time);

	/* Full path */

	field_name = tar_get_last_field (line, date_idx, 3);
	fields = g_strsplit (field_name, " -> ", 2);

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

	name = g_strcompress (fields[0]);
	if (*name == '/') {
		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;
	}
	g_free (name);
	name = g_filename_from_utf8 (fdata->original_path, -1, NULL, NULL, NULL);
	if (name)
		fdata->original_path = name;

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

	fdata->dir = line[0] == 'd';
	if (fdata->dir)
		fdata->name = _g_path_get_dir_name (fdata->full_path);
	else
		fdata->name = g_strdup (_g_path_get_basename (fdata->full_path));
	fdata->path = _g_path_remove_level (fdata->full_path);

	if (*fdata->name == 0)
		file_data_free (fdata);
	else
		fr_archive_add_file (FR_ARCHIVE (comm), fdata);
}
static char *
get_uncompressed_name (FrCommandTar *c_tar,
		       const char   *e_filename)
{
	FrCommand *comm = FR_COMMAND (c_tar);
	FrArchive *archive = FR_ARCHIVE (comm);
	char      *new_name = g_strdup (e_filename);
	int        l = strlen (new_name);

	if (_g_mime_type_matches (archive->mime_type, "application/x-compressed-tar")) {
		/* X.tgz     -->  X.tar
		 * X.tar.gz  -->  X.tar */
		if (_g_filename_has_extension (e_filename, ".tgz")) {
			new_name[l - 2] = 'a';
			new_name[l - 1] = 'r';
		}
		else if (_g_filename_has_extension (e_filename, ".tar.gz"))
			new_name[l - 3] = 0;
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-bzip-compressed-tar")) {
		/* X.tbz2    -->  X.tar
		 * X.tar.bz2 -->  X.tar */
		if (_g_filename_has_extension (e_filename, ".tbz2")) {
			new_name[l - 3] = 'a';
			new_name[l - 2] = 'r';
			new_name[l - 1] = 0;
		}
		else if (_g_filename_has_extension (e_filename, ".tar.bz2"))
			new_name[l - 4] = 0;
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-tarz")) {
		/* X.taz   -->  X.tar
		 * X.tar.Z -->  X.tar */
		if (_g_filename_has_extension (e_filename, ".taz"))
			new_name[l - 1] = 'r';
		else if (_g_filename_has_extension (e_filename, ".tar.Z"))
			new_name[l - 2] = 0;
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lrzip-compressed-tar")) {
		/* X.tlrz     -->  X.tar
		 * X.tar.lrz  -->  X.tar */
		if (_g_filename_has_extension (e_filename, ".tlrz")) {
			new_name[l - 3] = 'a';
			new_name[l - 2] = 'r';
			new_name[l - 1] = 0;
		}
		else if (_g_filename_has_extension (e_filename, ".tar.lrz"))
			new_name[l - 4] = 0;
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzip-compressed-tar")) {
		/* X.tlz     -->  X.tar
		 * X.tar.lz  -->  X.tar */
		if (_g_filename_has_extension (e_filename, ".tlz")) {
			new_name[l - 2] = 'a';
			new_name[l - 1] = 'r';
		}
		else if (_g_filename_has_extension (e_filename, ".tar.lz"))
			new_name[l - 3] = 0;
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzma-compressed-tar")) {
		/* X.tar.lzma --> X.tar
		 * (There doesn't seem to be a shorthand suffix) */
		if (_g_filename_has_extension (e_filename, ".tar.lzma"))
			new_name[l - 5] = 0;
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-xz-compressed-tar")) {
		/* X.tar.xz --> X.tar
		 * (There doesn't seem to be a shorthand suffix) */
		if (_g_filename_has_extension (e_filename, ".tar.xz"))
			new_name[l - 3] = 0;
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-lzop-compressed-tar")) {
		/* X.tzo     -->  X.tar
		 * X.tar.lzo -->  X.tar */
		if (_g_filename_has_extension (e_filename, ".tzo")) {
			new_name[l - 2] = 'a';
			new_name[l - 1] = 'r';
		}
		else if (_g_filename_has_extension (e_filename, ".tar.lzo"))
			new_name[l - 4] = 0;
	}
	else if (_g_mime_type_matches (archive->mime_type, "application/x-7z-compressed-tar")) {
		/* X.tar.7z -->  X.tar */
		if (_g_filename_has_extension (e_filename, ".tar.7z"))
			new_name[l - 3] = 0;
	}

	return new_name;
}