Beispiel #1
0
static void
add_compress_arg (FRCommand *comm)
{
   FRCommandTar *comm_tar = FR_COMMAND_TAR (comm);

   switch (comm_tar->compress_prog) {
   case FR_COMPRESS_PROGRAM_NONE:
      break;

   case FR_COMPRESS_PROGRAM_GZIP:
      fr_process_add_arg (comm->process, "-z");
      break;

   case FR_COMPRESS_PROGRAM_BZIP:
      fr_process_add_arg (comm->process, 
                          "--use-compress-program bzip");
      break;

   case FR_COMPRESS_PROGRAM_BZIP2:
      fr_process_add_arg (comm->process, "--bzip");
      break;

   case FR_COMPRESS_PROGRAM_COMPRESS:
      fr_process_add_arg (comm->process, "-Z");
      break;
   case FR_COMPRESS_PROGRAM_LZO:
      fr_process_add_arg (comm->process, 
                          "--use-compress-program lzop");
      break;
   }
}
static void
fr_command_tar_delete (FrCommand  *comm,
		       const char *from_file,
		       GList      *file_list)
{
	FrCommandTar *c_tar = FR_COMMAND_TAR (comm);
	GList        *scan;

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

	begin_tar_command (comm);
	fr_process_set_begin_func (comm->process, begin_func__delete, comm);
	fr_process_add_arg (comm->process, "--force-local");
	fr_process_add_arg (comm->process, "--no-wildcards");
	fr_process_add_arg (comm->process, "-v");
	fr_process_add_arg (comm->process, "--delete");
	fr_process_add_arg (comm->process, "-f");
	fr_process_add_arg (comm->process, c_tar->uncomp_filename);

	if (from_file != NULL) {
		fr_process_add_arg (comm->process, "-T");
		fr_process_add_arg (comm->process, from_file);
	}

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

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

	fr_process_end_command (comm->process);
}
static void
fr_command_tar_add (FrCommand  *comm,
		    const char *from_file,
		    GList      *file_list,
		    const char *base_dir,
		    gboolean    update,
		    gboolean    follow_links)
{
	FrCommandTar *c_tar = FR_COMMAND_TAR (comm);
	GList        *scan;

	fr_process_set_out_line_func (FR_COMMAND (comm)->process,
				      process_line__add,
				      comm);

	begin_tar_command (comm);
	fr_process_add_arg (comm->process, "--force-local");
	fr_process_add_arg (comm->process, "--no-recursion");
	fr_process_add_arg (comm->process, "--no-wildcards");
	fr_process_add_arg (comm->process, "-v");
	fr_process_add_arg (comm->process, "-p");
	if (follow_links)
		fr_process_add_arg (comm->process, "-h");

	if (base_dir != NULL) {
		fr_process_add_arg (comm->process, "-C");
		fr_process_add_arg (comm->process, base_dir);
	}

	if (can_create_a_compressed_archive (comm)) {
		fr_process_add_arg (comm->process, "-cf");
		fr_process_add_arg (comm->process, comm->filename);
		add_compress_arg (comm);
	}
	else {
		if (comm->creating_archive)
			fr_process_add_arg (comm->process, "-cf");
		else
			fr_process_add_arg (comm->process, "-rf");
		fr_process_add_arg (comm->process, c_tar->uncomp_filename);
	}

	if (from_file != NULL) {
		fr_process_add_arg (comm->process, "-T");
		fr_process_add_arg (comm->process, from_file);
	}

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

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

	fr_process_end_command (comm->process);
}
Beispiel #4
0
static char *
recompress (FRCommand *comm, char *uncompressed_name)
{
   gchar *new_name = NULL;
   FRCommandTar *comm_tar = FR_COMMAND_TAR (comm);

   switch (comm_tar->compress_prog) {
   case FR_COMPRESS_PROGRAM_NONE:
      break;

   case FR_COMPRESS_PROGRAM_GZIP:
      fr_process_begin_command (comm->process, "gzip");
      fr_process_add_arg (comm->process, uncompressed_name);
      fr_process_end_command (comm->process);

      new_name = g_strconcat (uncompressed_name, ".gz", NULL);
      break;

   case FR_COMPRESS_PROGRAM_BZIP:
      fr_process_begin_command (comm->process, "bzip");
      fr_process_add_arg (comm->process, uncompressed_name);
      fr_process_end_command (comm->process);

      new_name = g_strconcat (uncompressed_name, ".bz", NULL);
      break;

   case FR_COMPRESS_PROGRAM_BZIP2:
      fr_process_begin_command (comm->process, "bzip2");
      fr_process_add_arg (comm->process, uncompressed_name);
      fr_process_end_command (comm->process);

      new_name = g_strconcat (uncompressed_name, ".bz2", NULL);
      break;

   case FR_COMPRESS_PROGRAM_COMPRESS: 
      fr_process_begin_command (comm->process, "compress");
      fr_process_add_arg (comm->process, "-f");
      fr_process_add_arg (comm->process, uncompressed_name);
      fr_process_end_command (comm->process);

      new_name = g_strconcat (uncompressed_name, ".Z", NULL);
      break;

   case FR_COMPRESS_PROGRAM_LZO:
      fr_process_begin_command (comm->process, "lzop");
      fr_process_add_arg (comm->process, uncompressed_name);
      fr_process_end_command (comm->process);

      new_name = g_strconcat (uncompressed_name, ".lzo", NULL);
      break;
   }

   return new_name;
}
Beispiel #5
0
static gchar*
uncompress (FRCommand *comm, gboolean *name_modified)
{
   gchar *new_name;
   gint l;
   FRCommandTar *comm_tar = FR_COMMAND_TAR (comm);

   *name_modified = FALSE;
   new_name = g_strdup (comm->filename);
   l = strlen (new_name);

   switch (comm_tar->compress_prog) {
   case FR_COMPRESS_PROGRAM_NONE:
      break;

   case FR_COMPRESS_PROGRAM_GZIP:
      if (isfile (comm->filename)) {
         fr_process_begin_command (comm->process, "gzip");
         fr_process_add_arg (comm->process, "-d");
         fr_process_add_arg (comm->process, comm->filename);
         fr_process_end_command (comm->process);
      }

      /* X.tgz     -->  X.tar 
       * X.tar.gz  -->  X.tar */
      if (fileutil_extension_is (comm->filename, ".tgz")) {
         *name_modified = TRUE;
         new_name[l - 2] = 'a';
         new_name[l - 1] = 'r';
      } else if (fileutil_extension_is (comm->filename, ".tar.gz")) 
         new_name[l - 3] = 0;
      break;

   case FR_COMPRESS_PROGRAM_BZIP:
      if (isfile (comm->filename)) {
         fr_process_begin_command (comm->process, "bzip");
         fr_process_add_arg (comm->process, "-d");
         fr_process_add_arg (comm->process, comm->filename);
         fr_process_end_command (comm->process);
      }

      /* Remove the .bz extension. */
      new_name[l - 3] = 0;
      break;

   case FR_COMPRESS_PROGRAM_BZIP2:
      if (isfile (comm->filename)) {
         fr_process_begin_command (comm->process, "bzip2");
         fr_process_add_arg (comm->process, "-d");
         fr_process_add_arg (comm->process, comm->filename);
         fr_process_end_command (comm->process);
      }

      /* Remove the .bz2 extension. */
      new_name[l - 4] = 0;
      break;

   case FR_COMPRESS_PROGRAM_COMPRESS: 
      if (isfile (comm->filename)) {
         fr_process_begin_command (comm->process, "uncompress");
         fr_process_add_arg (comm->process, "-f");
         fr_process_add_arg (comm->process, comm->filename);
         fr_process_end_command (comm->process);
      }

      /* X.taz   -->  X.tar 
       * X.tar.Z -->  X.tar */
      if (fileutil_extension_is (comm->filename, ".taz")) {
         *name_modified = TRUE;
         new_name[l - 1] = 'r';
      } else if (fileutil_extension_is (comm->filename, ".tar.Z")) 
         new_name[l - 2] = 0;
      break;

   case FR_COMPRESS_PROGRAM_LZO:
      if (isfile (comm->filename)) {
         fr_process_begin_command (comm->process, "lzop");
         fr_process_add_arg (comm->process, "-d");
         fr_process_add_arg (comm->process, comm->filename);
         fr_process_end_command (comm->process);
      }

      /* X.tzo     -->  X.tar 
       * X.tar.lzo -->  X.tar */
      if (fileutil_extension_is (comm->filename, ".tzo")) {
         *name_modified = TRUE;
         new_name[l - 2] = 'a';
         new_name[l - 1] = 'r';
      } else if (fileutil_extension_is (comm->filename, ".tar.lzo")) 
         new_name[l - 4] = 0;
      break;
   }

   return new_name;
}
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;
}