1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /*
4 * Engrampa
5 *
6 * Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02110-1301, USA.
21 */
22
23 #include <config.h>
24
25 #include <sys/types.h>
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <time.h>
31
32 #include <glib.h>
33 #include "tr-wrapper.h"
34
35 #include "file-data.h"
36 #include "file-utils.h"
37 #include "glib-utils.h"
38 #include "fr-command.h"
39 #include "fr-command-tar.h"
40
41 #define ACTIVITY_DELAY 20
42
43 static void fr_command_tar_class_init (FrCommandTarClass *class);
44 static void fr_command_tar_init (FrCommand *afile);
45 static void fr_command_tar_finalize (GObject *object);
46
47 /* Parent Class */
48
49 static FrCommandClass *parent_class = NULL;
50
51
52 /* -- list -- */
53
54 static time_t
mktime_from_string(char * date_s,char * time_s)55 mktime_from_string (char *date_s,
56 char *time_s)
57 {
58 struct tm tm = {0, };
59 char **fields;
60
61 tm.tm_isdst = -1;
62
63 /* date */
64
65 fields = g_strsplit (date_s, "-", 3);
66 if (fields[0] != NULL) {
67 tm.tm_year = atoi (fields[0]) - 1900;
68 if (fields[1] != NULL) {
69 tm.tm_mon = atoi (fields[1]) - 1;
70 if (fields[2] != NULL)
71 tm.tm_mday = atoi (fields[2]);
72 }
73 }
74 g_strfreev (fields);
75
76 /* time */
77
78 fields = g_strsplit (time_s, ":", 3);
79 if (fields[0] != NULL) {
80 tm.tm_hour = atoi (fields[0]);
81 if (fields[1] != NULL) {
82 tm.tm_min = atoi (fields[1]);
83 if (fields[2] != NULL)
84 tm.tm_sec = atoi (fields[2]);
85 }
86 }
87 g_strfreev (fields);
88
89 return mktime (&tm);
90 }
91
92
93 static char*
tar_get_last_field(const char * line,int start_from,int field_n)94 tar_get_last_field (const char *line,
95 int start_from,
96 int field_n)
97 {
98 const char *f_start, *f_end;
99
100 line = line + start_from;
101
102 f_start = line;
103 while ((*f_start == ' ') && (*f_start != *line))
104 f_start++;
105 f_end = f_start;
106
107 while ((field_n > 0) && (*f_end != 0)) {
108 if (*f_end == ' ') {
109 field_n--;
110 if (field_n != 0) {
111 while ((*f_end == ' ') && (*f_end != *line))
112 f_end++;
113 f_start = f_end;
114 }
115 } else
116 f_end++;
117 }
118
119 return g_strdup (f_start);
120 }
121
122
123 static void
process_line(char * line,gpointer data)124 process_line (char *line,
125 gpointer data)
126 {
127 FileData *fdata;
128 FrCommand *comm = FR_COMMAND (data);
129 char **fields;
130 int date_idx;
131 char *field_date, *field_time, *field_size, *field_name;
132 char *name;
133
134 g_return_if_fail (line != NULL);
135
136 date_idx = file_list__get_index_from_pattern (line, "%n%n%n%n-%n%n-%n%n %n%n:%n%n");
137 if (date_idx < 0)
138 return;
139
140 fdata = file_data_new ();
141
142 field_size = file_list__get_prev_field (line, date_idx, 1);
143 fdata->size = g_ascii_strtoull (field_size, NULL, 10);
144 g_free (field_size);
145
146 field_date = file_list__get_next_field (line, date_idx, 1);
147 field_time = file_list__get_next_field (line, date_idx, 2);
148 fdata->modified = mktime_from_string (field_date, field_time);
149 g_free (field_date);
150 g_free (field_time);
151
152 /* Full path */
153
154 field_name = tar_get_last_field (line, date_idx, 3);
155 fields = g_strsplit (field_name, " -> ", 2);
156
157 if (fields[1] == NULL) {
158 g_strfreev (fields);
159 fields = g_strsplit (field_name, " link to ", 2);
160 }
161
162 name = g_strcompress (fields[0]);
163 if (*name == '/') {
164 fdata->full_path = g_strdup (name);
165 fdata->original_path = fdata->full_path;
166 } else {
167 fdata->full_path = g_strconcat ("/", name, NULL);
168 fdata->original_path = fdata->full_path + 1;
169 }
170 g_free (name);
171 name = g_filename_from_utf8 (fdata->original_path, -1, NULL, NULL, NULL);
172 if (name)
173 fdata->original_path = name;
174
175 if (fields[1] != NULL)
176 fdata->link = g_strdup (fields[1]);
177 g_strfreev (fields);
178 g_free (field_name);
179
180 fdata->dir = line[0] == 'd';
181 if (fdata->dir)
182 fdata->name = dir_name_from_path (fdata->full_path);
183 else
184 fdata->name = g_strdup (file_name_from_path (fdata->full_path));
185 fdata->path = remove_level_from_path (fdata->full_path);
186
187 if (*fdata->name == 0)
188 file_data_free (fdata);
189 else
190 fr_command_add_file (comm, fdata);
191 }
192
193
194 static void
add_compress_arg(FrCommand * comm)195 add_compress_arg (FrCommand *comm)
196 {
197 if (is_mime_type (comm->mime_type, "application/x-compressed-tar"))
198 fr_process_add_arg (comm->process, "-z");
199
200 else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar"))
201 if (is_program_in_path ("lbzip2"))
202 fr_process_add_arg (comm->process, "--use-compress-program=lbzip2");
203 else
204 fr_process_add_arg (comm->process, "--use-compress-program=bzip2");
205
206 else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
207 if (is_program_in_path ("gzip"))
208 fr_process_add_arg (comm->process, "-z");
209 else
210 fr_process_add_arg (comm->process, "-Z");
211 }
212 else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar"))
213 fr_process_add_arg (comm->process, "--use-compress-program=lrzip");
214
215 else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar"))
216 fr_process_add_arg (comm->process, "--use-compress-program=lzip");
217
218 else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar"))
219 fr_process_add_arg (comm->process, "--use-compress-program=lzma");
220
221 else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar"))
222 if (is_program_in_path ("pixz"))
223 fr_process_add_arg (comm->process, "--use-compress-program=pixz");
224 else
225 fr_process_add_arg (comm->process, "--use-compress-program=xz");
226
227 else if (is_mime_type (comm->mime_type, "application/x-zstd-compressed-tar"))
228 fr_process_add_arg (comm->process, "--use-compress-program=zstd");
229
230 else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar"))
231 fr_process_add_arg (comm->process, "--use-compress-program=lzop");
232
233 else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
234 FrCommandTar *comm_tar = (FrCommandTar*) comm;
235 char *option;
236
237 option = g_strdup_printf ("--use-compress-program=%s", comm_tar->compress_command);
238 fr_process_add_arg (comm->process, option);
239 g_free (option);
240 }
241 }
242
243
244 static void
begin_tar_command(FrCommand * comm)245 begin_tar_command (FrCommand *comm)
246 {
247 char *command = NULL;
248
249 /* In solaris gtar is present under /usr/sfw/bin */
250
251 command = g_find_program_in_path ("gtar");
252 #if defined (__SVR4) && defined (__sun)
253 if (g_file_test ("/usr/sfw/bin/gtar", G_FILE_TEST_IS_EXECUTABLE)) {
254 g_free (command);
255 command = g_strdup ("/usr/sfw/bin/gtar");
256 }
257 #endif
258 if (command != NULL)
259 fr_process_begin_command (comm->process, command);
260 else
261 fr_process_begin_command (comm->process, "tar");
262 g_free (command);
263 }
264
265
266 static void
fr_command_tar_list(FrCommand * comm)267 fr_command_tar_list (FrCommand *comm)
268 {
269 fr_process_set_out_line_func (comm->process, process_line, comm);
270
271 begin_tar_command (comm);
272 fr_process_add_arg (comm->process, "--force-local");
273 fr_process_add_arg (comm->process, "--no-wildcards");
274 fr_process_add_arg (comm->process, "-tvf");
275 fr_process_add_arg (comm->process, comm->filename);
276 add_compress_arg (comm);
277 fr_process_end_command (comm->process);
278 fr_process_start (comm->process);
279 }
280
281
282 static gboolean
can_create_a_compressed_archive(FrCommand * comm)283 can_create_a_compressed_archive (FrCommand *comm)
284 {
285 return comm->creating_archive && ! is_mime_type (comm->mime_type, "application/x-7z-compressed-tar");
286 }
287
288
289 static void
process_line__generic(char * line,gpointer data,char * action_msg)290 process_line__generic (char *line,
291 gpointer data,
292 char *action_msg)
293 {
294 FrCommand *comm = FR_COMMAND (data);
295
296 if (line == NULL)
297 return;
298
299 if (line[strlen (line) - 1] == '/') /* ignore directories */
300 return;
301
302 if (comm->n_files != 0) {
303 double fraction = (double) ++comm->n_file / (comm->n_files + 1);
304 fr_command_progress (comm, fraction);
305 }
306 else {
307 char *msg = g_strconcat (action_msg, file_name_from_path (line), NULL);
308 fr_command_message (comm, msg);
309 g_free (msg);
310 }
311 }
312
313
314 static void
process_line__add(char * line,gpointer data)315 process_line__add (char *line,
316 gpointer data)
317 {
318 /* Translators: after the colon there is a filename. */
319 process_line__generic (line, data, _("Adding file: "));
320 }
321
322
323 static void
fr_command_tar_add(FrCommand * comm,const char * from_file,GList * file_list,const char * base_dir,gboolean update,gboolean recursive)324 fr_command_tar_add (FrCommand *comm,
325 const char *from_file,
326 GList *file_list,
327 const char *base_dir,
328 gboolean update,
329 gboolean recursive)
330 {
331 FrCommandTar *c_tar = FR_COMMAND_TAR (comm);
332 GList *scan;
333
334 fr_process_set_out_line_func (FR_COMMAND (comm)->process,
335 process_line__add,
336 comm);
337
338 begin_tar_command (comm);
339 fr_process_add_arg (comm->process, "--force-local");
340 if (! recursive)
341 fr_process_add_arg (comm->process, "--no-recursion");
342 fr_process_add_arg (comm->process, "--no-wildcards");
343 fr_process_add_arg (comm->process, "--no-unquote");
344 fr_process_add_arg (comm->process, "-v");
345 fr_process_add_arg (comm->process, "-p");
346
347 if (base_dir != NULL) {
348 fr_process_add_arg (comm->process, "-C");
349 fr_process_add_arg (comm->process, base_dir);
350 }
351
352 if (can_create_a_compressed_archive (comm)) {
353 fr_process_add_arg (comm->process, "-cf");
354 fr_process_add_arg (comm->process, comm->filename);
355 add_compress_arg (comm);
356 }
357 else {
358 if (comm->creating_archive)
359 fr_process_add_arg (comm->process, "-cf");
360 else
361 fr_process_add_arg (comm->process, "-rf");
362 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
363 }
364
365 if (from_file != NULL) {
366 fr_process_add_arg (comm->process, "-T");
367 fr_process_add_arg (comm->process, from_file);
368 }
369
370 fr_process_add_arg (comm->process, "--");
371
372 if (from_file == NULL)
373 for (scan = file_list; scan; scan = scan->next)
374 fr_process_add_arg (comm->process, scan->data);
375
376 fr_process_end_command (comm->process);
377 }
378
379
380 static void
process_line__delete(char * line,gpointer data)381 process_line__delete (char *line,
382 gpointer data)
383 {
384 /* Translators: after the colon there is a filename. */
385 process_line__generic (line, data, _("Removing file: "));
386 }
387
388
389 static void
begin_func__delete(gpointer data)390 begin_func__delete (gpointer data)
391 {
392 FrCommand *comm = data;
393 fr_command_progress (comm, -1.0);
394 fr_command_message (comm, _("Deleting files from archive"));
395 }
396
397
398 static void
fr_command_tar_delete(FrCommand * comm,const char * from_file,GList * file_list)399 fr_command_tar_delete (FrCommand *comm,
400 const char *from_file,
401 GList *file_list)
402 {
403 FrCommandTar *c_tar = FR_COMMAND_TAR (comm);
404 GList *scan;
405
406 fr_process_set_out_line_func (comm->process,
407 process_line__delete,
408 comm);
409
410 begin_tar_command (comm);
411 fr_process_set_begin_func (comm->process, begin_func__delete, comm);
412 fr_process_add_arg (comm->process, "--force-local");
413 fr_process_add_arg (comm->process, "--no-wildcards");
414 fr_process_add_arg (comm->process, "--no-unquote");
415 fr_process_add_arg (comm->process, "-v");
416 fr_process_add_arg (comm->process, "--delete");
417 fr_process_add_arg (comm->process, "-f");
418 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
419
420 if (from_file != NULL) {
421 fr_process_add_arg (comm->process, "-T");
422 fr_process_add_arg (comm->process, from_file);
423 }
424
425 fr_process_add_arg (comm->process, "--");
426
427 if (from_file == NULL)
428 for (scan = file_list; scan; scan = scan->next)
429 fr_process_add_arg (comm->process, scan->data);
430
431 fr_process_end_command (comm->process);
432 }
433
434
435 static void
process_line__extract(char * line,gpointer data)436 process_line__extract (char *line,
437 gpointer data)
438 {
439 /* Translators: after the colon there is a filename. */
440 process_line__generic (line, data, _("Extracting file: "));
441 }
442
443
444 static void
fr_command_tar_extract(FrCommand * comm,const char * from_file,GList * file_list,const char * dest_dir,gboolean overwrite,gboolean skip_older,gboolean junk_paths)445 fr_command_tar_extract (FrCommand *comm,
446 const char *from_file,
447 GList *file_list,
448 const char *dest_dir,
449 gboolean overwrite,
450 gboolean skip_older,
451 gboolean junk_paths)
452 {
453 GList *scan;
454
455 fr_process_set_out_line_func (comm->process,
456 process_line__extract,
457 comm);
458
459 begin_tar_command (comm);
460 fr_process_add_arg (comm->process, "--force-local");
461 fr_process_add_arg (comm->process, "--no-wildcards");
462 fr_process_add_arg (comm->process, "--no-unquote");
463 fr_process_add_arg (comm->process, "-v");
464 fr_process_add_arg (comm->process, "-p");
465
466 if (! overwrite)
467 fr_process_add_arg (comm->process, "-k");
468 if (skip_older)
469 fr_process_add_arg (comm->process, "--keep-newer-files");
470
471 fr_process_add_arg (comm->process, "-xf");
472 fr_process_add_arg (comm->process, comm->filename);
473 add_compress_arg (comm);
474
475 if (dest_dir != NULL) {
476 fr_process_add_arg (comm->process, "-C");
477 fr_process_add_arg (comm->process, dest_dir);
478 }
479
480 if (from_file != NULL) {
481 fr_process_add_arg (comm->process, "-T");
482 fr_process_add_arg (comm->process, from_file);
483 }
484
485 fr_process_add_arg (comm->process, "--");
486
487 if (from_file == NULL)
488 for (scan = file_list; scan; scan = scan->next)
489 fr_process_add_arg (comm->process, scan->data);
490
491 fr_process_end_command (comm->process);
492 }
493
494
495 static void
begin_func__recompress(gpointer data)496 begin_func__recompress (gpointer data)
497 {
498 FrCommand *comm = data;
499 fr_command_progress (comm, -1.0);
500 fr_command_message (comm, _("Recompressing archive"));
501 }
502
503
504 static gboolean
gzip_continue_func(gpointer user_data)505 gzip_continue_func (gpointer user_data)
506 {
507 FrCommand *comm = user_data;
508
509 /* ignore gzip warnings */
510
511 if (comm->process->error.status == 2) {
512 comm->process->error.type = FR_PROC_ERROR_NONE;
513 comm->process->error.status = 0;
514 g_clear_error (&comm->process->error.gerror);
515 }
516
517 return comm->process->error.status == 0;
518 }
519
520
521 static void
fr_command_tar_recompress(FrCommand * comm)522 fr_command_tar_recompress (FrCommand *comm)
523 {
524 FrCommandTar *c_tar = FR_COMMAND_TAR (comm);
525 char *new_name = NULL;
526
527 if (can_create_a_compressed_archive (comm))
528 return;
529
530 if (is_mime_type (comm->mime_type, "application/x-compressed-tar")) {
531 fr_process_begin_command (comm->process, "gzip");
532 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
533 fr_process_set_continue_func (comm->process, gzip_continue_func, comm);
534 switch (comm->compression) {
535 case FR_COMPRESSION_VERY_FAST:
536 fr_process_add_arg (comm->process, "-1"); break;
537 case FR_COMPRESSION_FAST:
538 fr_process_add_arg (comm->process, "-3"); break;
539 case FR_COMPRESSION_NORMAL:
540 fr_process_add_arg (comm->process, "-6"); break;
541 case FR_COMPRESSION_MAXIMUM:
542 fr_process_add_arg (comm->process, "-9"); break;
543 }
544 fr_process_add_arg (comm->process, "-f");
545 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
546 fr_process_end_command (comm->process);
547
548 new_name = g_strconcat (c_tar->uncomp_filename, ".gz", NULL);
549 }
550 else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar")) {
551 fr_process_begin_command (comm->process, "bzip2");
552 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
553 switch (comm->compression) {
554 case FR_COMPRESSION_VERY_FAST:
555 fr_process_add_arg (comm->process, "-1"); break;
556 case FR_COMPRESSION_FAST:
557 fr_process_add_arg (comm->process, "-3"); break;
558 case FR_COMPRESSION_NORMAL:
559 fr_process_add_arg (comm->process, "-6"); break;
560 case FR_COMPRESSION_MAXIMUM:
561 fr_process_add_arg (comm->process, "-9"); break;
562 }
563 fr_process_add_arg (comm->process, "-f");
564 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
565 fr_process_end_command (comm->process);
566
567 new_name = g_strconcat (c_tar->uncomp_filename, ".bz2", NULL);
568 }
569 else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
570 fr_process_begin_command (comm->process, "compress");
571 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
572 fr_process_add_arg (comm->process, "-f");
573 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
574 fr_process_end_command (comm->process);
575
576 new_name = g_strconcat (c_tar->uncomp_filename, ".Z", NULL);
577 }
578 else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar")) {
579 fr_process_begin_command (comm->process, "lrzip");
580 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
581 switch (comm->compression) {
582 case FR_COMPRESSION_VERY_FAST:
583 fr_process_add_arg (comm->process, "-l"); break;
584 case FR_COMPRESSION_FAST:
585 fr_process_add_arg (comm->process, "-g"); break;
586 case FR_COMPRESSION_NORMAL:
587 fr_process_add_arg (comm->process, "-b"); break;
588 case FR_COMPRESSION_MAXIMUM:
589 fr_process_add_arg (comm->process, "-z"); break;
590 }
591 fr_process_add_arg (comm->process, "-o");
592 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
593 fr_process_end_command (comm->process);
594
595 new_name = g_strconcat (c_tar->uncomp_filename, ".lrz", NULL);
596 }
597 else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar")) {
598 fr_process_begin_command (comm->process, "lzip");
599 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
600 switch (comm->compression) {
601 case FR_COMPRESSION_VERY_FAST:
602 fr_process_add_arg (comm->process, "-1"); break;
603 case FR_COMPRESSION_FAST:
604 fr_process_add_arg (comm->process, "-3"); break;
605 case FR_COMPRESSION_NORMAL:
606 fr_process_add_arg (comm->process, "-6"); break;
607 case FR_COMPRESSION_MAXIMUM:
608 fr_process_add_arg (comm->process, "-9"); break;
609 }
610 fr_process_add_arg (comm->process, "-f");
611 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
612 fr_process_end_command (comm->process);
613
614 new_name = g_strconcat (c_tar->uncomp_filename, ".lz", NULL);
615 }
616 else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar")) {
617 fr_process_begin_command (comm->process, "lzma");
618 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
619 switch (comm->compression) {
620 case FR_COMPRESSION_VERY_FAST:
621 fr_process_add_arg (comm->process, "-1"); break;
622 case FR_COMPRESSION_FAST:
623 fr_process_add_arg (comm->process, "-3"); break;
624 case FR_COMPRESSION_NORMAL:
625 fr_process_add_arg (comm->process, "-6"); break;
626 case FR_COMPRESSION_MAXIMUM:
627 fr_process_add_arg (comm->process, "-9"); break;
628 }
629 fr_process_add_arg (comm->process, "-f");
630 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
631 fr_process_end_command (comm->process);
632
633 new_name = g_strconcat (c_tar->uncomp_filename, ".lzma", NULL);
634 }
635 else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar")) {
636 fr_process_begin_command (comm->process, "xz");
637 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
638 switch (comm->compression) {
639 case FR_COMPRESSION_VERY_FAST:
640 fr_process_add_arg (comm->process, "-1"); break;
641 case FR_COMPRESSION_FAST:
642 fr_process_add_arg (comm->process, "-3"); break;
643 case FR_COMPRESSION_NORMAL:
644 fr_process_add_arg (comm->process, "-6"); break;
645 case FR_COMPRESSION_MAXIMUM:
646 fr_process_add_arg (comm->process, "-9"); break;
647 }
648 fr_process_add_arg (comm->process, "-f");
649 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
650 fr_process_end_command (comm->process);
651
652 new_name = g_strconcat (c_tar->uncomp_filename, ".xz", NULL);
653 }
654 else if (is_mime_type (comm->mime_type, "application/x-zstd-compressed-tar")) {
655 fr_process_begin_command (comm->process, "zstd");
656 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
657 switch (comm->compression) {
658 case FR_COMPRESSION_VERY_FAST:
659 fr_process_add_arg (comm->process, "-1"); break;
660 case FR_COMPRESSION_FAST:
661 fr_process_add_arg (comm->process, "-2"); break;
662 case FR_COMPRESSION_NORMAL:
663 fr_process_add_arg (comm->process, "-3"); break;
664 case FR_COMPRESSION_MAXIMUM:
665 fr_process_add_arg (comm->process, "--ultra");
666 fr_process_add_arg (comm->process, "-22");
667 break;
668 }
669 fr_process_add_arg (comm->process, "-f");
670 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
671 fr_process_end_command (comm->process);
672
673 new_name = g_strconcat (c_tar->uncomp_filename, ".zst", NULL);
674 }
675 else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar")) {
676 fr_process_begin_command (comm->process, "lzop");
677 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
678 switch (comm->compression) {
679 case FR_COMPRESSION_VERY_FAST:
680 fr_process_add_arg (comm->process, "-1"); break;
681 case FR_COMPRESSION_FAST:
682 fr_process_add_arg (comm->process, "-3"); break;
683 case FR_COMPRESSION_NORMAL:
684 fr_process_add_arg (comm->process, "-6"); break;
685 case FR_COMPRESSION_MAXIMUM:
686 fr_process_add_arg (comm->process, "-9"); break;
687 }
688 fr_process_add_arg (comm->process, "-fU");
689 fr_process_add_arg (comm->process, "--no-stdin");
690 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
691 fr_process_end_command (comm->process);
692
693 new_name = g_strconcat (c_tar->uncomp_filename, ".lzo", NULL);
694 }
695 else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
696 FrCommandTar *comm_tar = (FrCommandTar*) comm;
697
698 fr_process_begin_command (comm->process, comm_tar->compress_command);
699 fr_process_set_begin_func (comm->process, begin_func__recompress, comm);
700 switch (comm->compression) {
701 case FR_COMPRESSION_VERY_FAST:
702 fr_process_add_arg (comm->process, "-mx=1"); break;
703 case FR_COMPRESSION_FAST:
704 fr_process_add_arg (comm->process, "-mx=5"); break;
705 case FR_COMPRESSION_NORMAL:
706 fr_process_add_arg (comm->process, "-mx=5"); break;
707 case FR_COMPRESSION_MAXIMUM:
708 fr_process_add_arg (comm->process, "-mx=7"); break;
709 }
710 fr_process_add_arg (comm->process, "a");
711 fr_process_add_arg (comm->process, "-bd");
712 fr_process_add_arg (comm->process, "-y");
713 fr_process_add_arg (comm->process, "-l");
714
715 new_name = g_strconcat (c_tar->uncomp_filename, ".7z", NULL);
716 fr_process_add_arg_concat (comm->process, new_name, NULL);
717
718 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
719 fr_process_end_command (comm->process);
720
721 /* remove the uncompressed tar */
722
723 fr_process_begin_command (comm->process, "rm");
724 fr_process_add_arg (comm->process, "-f");
725 fr_process_add_arg (comm->process, c_tar->uncomp_filename);
726 fr_process_end_command (comm->process);
727 }
728
729 if (c_tar->name_modified) {
730 char *tmp_dir;
731
732 /* Restore original name. */
733
734 fr_process_begin_command (comm->process, "mv");
735 fr_process_add_arg (comm->process, "-f");
736 fr_process_add_arg (comm->process, new_name);
737 fr_process_add_arg (comm->process, comm->filename);
738 fr_process_end_command (comm->process);
739
740 tmp_dir = remove_level_from_path (new_name);
741
742 fr_process_begin_command (comm->process, "rm");
743 fr_process_set_sticky (comm->process, TRUE);
744 fr_process_add_arg (comm->process, "-fr");
745 fr_process_add_arg (comm->process, tmp_dir);
746 fr_process_end_command (comm->process);
747
748 g_free (tmp_dir);
749 }
750
751 g_free (new_name);
752 g_free (c_tar->uncomp_filename);
753 c_tar->uncomp_filename = NULL;
754 }
755
756
757 static void
begin_func__uncompress(gpointer data)758 begin_func__uncompress (gpointer data)
759 {
760 FrCommand *comm = data;
761 fr_command_progress (comm, -1.0);
762 fr_command_message (comm, _("Decompressing archive"));
763 }
764
765
766 static char *
get_uncompressed_name(FrCommandTar * c_tar,const char * e_filename)767 get_uncompressed_name (FrCommandTar *c_tar,
768 const char *e_filename)
769 {
770 FrCommand *comm = FR_COMMAND (c_tar);
771 char *new_name = g_strdup (e_filename);
772 int l = strlen (new_name);
773
774 if (is_mime_type (comm->mime_type, "application/x-compressed-tar")) {
775 /* X.tgz --> X.tar
776 * X.tar.gz --> X.tar */
777 if (file_extension_is (e_filename, ".tgz")) {
778 new_name[l - 2] = 'a';
779 new_name[l - 1] = 'r';
780 }
781 else if (file_extension_is (e_filename, ".tar.gz"))
782 new_name[l - 3] = 0;
783 }
784 else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar")) {
785 /* X.tbz2 --> X.tar
786 * X.tar.bz2 --> X.tar */
787 if (file_extension_is (e_filename, ".tbz2")) {
788 new_name[l - 3] = 'a';
789 new_name[l - 2] = 'r';
790 new_name[l - 1] = 0;
791 }
792 else if (file_extension_is (e_filename, ".tar.bz2"))
793 new_name[l - 4] = 0;
794 }
795 else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
796 /* X.taz --> X.tar
797 * X.tar.Z --> X.tar */
798 if (file_extension_is (e_filename, ".taz"))
799 new_name[l - 1] = 'r';
800 else if (file_extension_is (e_filename, ".tar.Z"))
801 new_name[l - 2] = 0;
802 }
803 else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar")) {
804 /* X.tlrz --> X.tar
805 * X.tar.lrz --> X.tar */
806 if (file_extension_is (e_filename, ".tlrz")) {
807 new_name[l - 3] = 'a';
808 new_name[l - 2] = 'r';
809 new_name[l - 1] = 0;
810 }
811 else if (file_extension_is (e_filename, ".tar.lrz"))
812 new_name[l - 4] = 0;
813 }
814 else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar")) {
815 /* X.tlz --> X.tar
816 * X.tar.lz --> X.tar */
817 if (file_extension_is (e_filename, ".tlz")) {
818 new_name[l - 2] = 'a';
819 new_name[l - 1] = 'r';
820 }
821 else if (file_extension_is (e_filename, ".tar.lz"))
822 new_name[l - 3] = 0;
823 }
824 else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar")) {
825 /* X.tar.lzma --> X.tar
826 * (There doesn't seem to be a shorthand suffix) */
827 if (file_extension_is (e_filename, ".tar.lzma"))
828 new_name[l - 5] = 0;
829 }
830 else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar")) {
831 /* X.txz --> X.tar
832 * X.tar.xz --> X.tar */
833 if (file_extension_is (e_filename, ".txz")) {
834 new_name[l - 2] = 'a';
835 new_name[l - 1] = 'r';
836 }
837 else if (file_extension_is (e_filename, ".tar.xz"))
838 new_name[l - 3] = 0;
839 }
840 else if (is_mime_type (comm->mime_type, "application/x-zstd-compressed-tar")) {
841 /* X.tzst --> X.tar
842 * X.tar.zst --> X.tar */
843 if (file_extension_is (e_filename, ".tzst")) {
844 new_name[l - 3] = 'a';
845 new_name[l - 2] = 'r';
846 new_name[l - 1] = 0;
847 }
848 else if (file_extension_is (e_filename, ".tar.zst"))
849 new_name[l - 4] = 0;
850 }
851 else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar")) {
852 /* X.tzo --> X.tar
853 * X.tar.lzo --> X.tar */
854 if (file_extension_is (e_filename, ".tzo")) {
855 new_name[l - 2] = 'a';
856 new_name[l - 1] = 'r';
857 }
858 else if (file_extension_is (e_filename, ".tar.lzo"))
859 new_name[l - 4] = 0;
860 }
861 else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
862 /* X.tar.7z --> X.tar */
863 if (file_extension_is (e_filename, ".tar.7z"))
864 new_name[l - 3] = 0;
865 }
866
867 return new_name;
868 }
869
870
871 #define MAX_TRIES 50
872
873
874 static char *
get_temp_name(FrCommandTar * c_tar,const char * filepath)875 get_temp_name (FrCommandTar *c_tar,
876 const char *filepath)
877 {
878 char *dirname = remove_level_from_path (filepath);
879 char *template;
880 char *result = NULL;
881 char *temp_name = NULL;
882
883 template = g_strconcat (dirname, "/.fr-XXXXXX", NULL);
884 result = mkdtemp (template);
885 temp_name = g_build_filename (result, file_name_from_path (filepath), NULL);
886 g_free (template);
887
888 return temp_name;
889 }
890
891
892 static void
fr_command_tar_uncompress(FrCommand * comm)893 fr_command_tar_uncompress (FrCommand *comm)
894 {
895 FrCommandTar *c_tar = FR_COMMAND_TAR (comm);
896 char *tmp_name;
897 gboolean archive_exists;
898
899 if (can_create_a_compressed_archive (comm))
900 return;
901
902 if (c_tar->uncomp_filename != NULL) {
903 g_free (c_tar->uncomp_filename);
904 c_tar->uncomp_filename = NULL;
905 }
906
907 archive_exists = ! comm->creating_archive;
908
909 c_tar->name_modified = ! is_mime_type (comm->mime_type, "application/x-tar");
910 if (c_tar->name_modified) {
911 tmp_name = get_temp_name (c_tar, comm->filename);
912 if (archive_exists) {
913 fr_process_begin_command (comm->process, "mv");
914 fr_process_add_arg (comm->process, "-f");
915 fr_process_add_arg (comm->process, comm->filename);
916 fr_process_add_arg (comm->process, tmp_name);
917 fr_process_end_command (comm->process);
918 }
919 }
920 else
921 tmp_name = g_strdup (comm->filename);
922
923 if (archive_exists) {
924 if (is_mime_type (comm->mime_type, "application/x-compressed-tar")) {
925 fr_process_begin_command (comm->process, "gzip");
926 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
927 fr_process_set_continue_func (comm->process, gzip_continue_func, comm);
928 fr_process_add_arg (comm->process, "-f");
929 fr_process_add_arg (comm->process, "-d");
930 fr_process_add_arg (comm->process, tmp_name);
931 fr_process_end_command (comm->process);
932 }
933 else if (is_mime_type (comm->mime_type, "application/x-bzip-compressed-tar")) {
934 fr_process_begin_command (comm->process, "bzip2");
935 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
936 fr_process_add_arg (comm->process, "-f");
937 fr_process_add_arg (comm->process, "-d");
938 fr_process_add_arg (comm->process, tmp_name);
939 fr_process_end_command (comm->process);
940 }
941 else if (is_mime_type (comm->mime_type, "application/x-tarz")) {
942 if (is_program_in_path ("gzip")) {
943 fr_process_begin_command (comm->process, "gzip");
944 fr_process_set_continue_func (comm->process, gzip_continue_func, comm);
945 }
946 else
947 fr_process_begin_command (comm->process, "uncompress");
948 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
949 fr_process_add_arg (comm->process, "-f");
950 fr_process_add_arg (comm->process, tmp_name);
951 fr_process_end_command (comm->process);
952 }
953 else if (is_mime_type (comm->mime_type, "application/x-lrzip-compressed-tar")) {
954 fr_process_begin_command (comm->process, "lrzip");
955 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
956 fr_process_add_arg (comm->process, "-f");
957 fr_process_add_arg (comm->process, "-d");
958 fr_process_add_arg (comm->process, tmp_name);
959 fr_process_end_command (comm->process);
960 }
961 else if (is_mime_type (comm->mime_type, "application/x-lzip-compressed-tar")) {
962 fr_process_begin_command (comm->process, "lzip");
963 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
964 fr_process_add_arg (comm->process, "-f");
965 fr_process_add_arg (comm->process, "-d");
966 fr_process_add_arg (comm->process, tmp_name);
967 fr_process_end_command (comm->process);
968 }
969 else if (is_mime_type (comm->mime_type, "application/x-lzma-compressed-tar")) {
970 fr_process_begin_command (comm->process, "lzma");
971 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
972 fr_process_add_arg (comm->process, "-f");
973 fr_process_add_arg (comm->process, "-d");
974 fr_process_add_arg (comm->process, tmp_name);
975 fr_process_end_command (comm->process);
976 }
977 else if (is_mime_type (comm->mime_type, "application/x-xz-compressed-tar")) {
978 fr_process_begin_command (comm->process, "xz");
979 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
980 fr_process_add_arg (comm->process, "-f");
981 fr_process_add_arg (comm->process, "-d");
982 fr_process_add_arg (comm->process, tmp_name);
983 fr_process_end_command (comm->process);
984 }
985 else if (is_mime_type (comm->mime_type, "application/x-zstd-compressed-tar")) {
986 fr_process_begin_command (comm->process, "zstd");
987 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
988 fr_process_add_arg (comm->process, "-f");
989 fr_process_add_arg (comm->process, "-d");
990 fr_process_add_arg (comm->process, tmp_name);
991 fr_process_end_command (comm->process);
992 }
993 else if (is_mime_type (comm->mime_type, "application/x-lzop-compressed-tar")) {
994 fr_process_begin_command (comm->process, "lzop");
995 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
996 fr_process_add_arg (comm->process, "-dfU");
997 fr_process_add_arg (comm->process, "--no-stdin");
998 fr_process_add_arg (comm->process, tmp_name);
999 fr_process_end_command (comm->process);
1000 }
1001 else if (is_mime_type (comm->mime_type, "application/x-7z-compressed-tar")) {
1002 FrCommandTar *comm_tar = (FrCommandTar*) comm;
1003
1004 fr_process_begin_command (comm->process, comm_tar->compress_command);
1005 fr_process_set_begin_func (comm->process, begin_func__uncompress, comm);
1006 fr_process_add_arg (comm->process, "e");
1007 fr_process_add_arg (comm->process, "-bd");
1008 fr_process_add_arg (comm->process, "-y");
1009 fr_process_add_arg (comm->process, tmp_name);
1010 fr_process_end_command (comm->process);
1011
1012 /* remove the compressed tar */
1013
1014 fr_process_begin_command (comm->process, "rm");
1015 fr_process_add_arg (comm->process, "-f");
1016 fr_process_add_arg (comm->process, tmp_name);
1017 fr_process_end_command (comm->process);
1018 }
1019 }
1020
1021 c_tar->uncomp_filename = get_uncompressed_name (c_tar, tmp_name);
1022 g_free (tmp_name);
1023 }
1024
1025
1026 static void
fr_command_tar_handle_error(FrCommand * comm,FrProcError * error)1027 fr_command_tar_handle_error (FrCommand *comm,
1028 FrProcError *error)
1029 {
1030 if (error->type != FR_PROC_ERROR_NONE) {
1031 if (error->status <= 1)
1032 error->type = FR_PROC_ERROR_NONE;
1033 }
1034 }
1035
1036
1037 const char *tar_mime_types[] = { "application/x-compressed-tar",
1038 "application/x-bzip-compressed-tar",
1039 "application/x-tar",
1040 "application/x-7z-compressed-tar",
1041 "application/x-lrzip-compressed-tar",
1042 "application/x-lzip-compressed-tar",
1043 "application/x-lzma-compressed-tar",
1044 "application/x-lzop-compressed-tar",
1045 "application/x-tarz",
1046 "application/x-xz-compressed-tar",
1047 "application/x-zstd-compressed-tar",
1048 NULL };
1049
1050
1051 static const char **
fr_command_tar_get_mime_types(FrCommand * comm)1052 fr_command_tar_get_mime_types (FrCommand *comm)
1053 {
1054 return tar_mime_types;
1055 }
1056
1057
1058 static FrCommandCap
fr_command_tar_get_capabilities(FrCommand * comm,const char * mime_type,gboolean check_command)1059 fr_command_tar_get_capabilities (FrCommand *comm,
1060 const char *mime_type,
1061 gboolean check_command)
1062 {
1063 FrCommandCap capabilities;
1064
1065 capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
1066
1067 /* In solaris gtar is present under /usr/sfw/bin */
1068 if (! is_program_available ("tar", check_command) && ! is_program_available ("/usr/sfw/bin/gtar", check_command))
1069 return capabilities;
1070
1071 if (is_mime_type (mime_type, "application/x-tar")) {
1072 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1073 }
1074 else if (is_mime_type (mime_type, "application/x-compressed-tar")) {
1075 if (is_program_available ("gzip", check_command))
1076 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1077 }
1078 else if (is_mime_type (mime_type, "application/x-bzip-compressed-tar")) {
1079 if (is_program_available ("bzip2", check_command))
1080 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1081 }
1082 else if (is_mime_type (mime_type, "application/x-tarz")) {
1083 if (is_program_available ("compress", check_command) && is_program_available ("uncompress", check_command))
1084 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1085 else if (is_program_available ("gzip", check_command))
1086 capabilities |= FR_COMMAND_CAN_READ;
1087 }
1088 else if (is_mime_type (mime_type, "application/x-lrzip-compressed-tar")) {
1089 if (is_program_available ("lrzip", check_command))
1090 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1091 }
1092 else if (is_mime_type (mime_type, "application/x-lzip-compressed-tar")) {
1093 if (is_program_available ("lzip", check_command))
1094 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1095 }
1096 else if (is_mime_type (mime_type, "application/x-lzma-compressed-tar")) {
1097 if (is_program_available ("lzma", check_command))
1098 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1099 }
1100 else if (is_mime_type (mime_type, "application/x-xz-compressed-tar")) {
1101 if (is_program_available ("xz", check_command))
1102 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1103 }
1104 else if (is_mime_type (mime_type, "application/x-zstd-compressed-tar")) {
1105 if (is_program_available ("zstd", check_command))
1106 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1107 }
1108 else if (is_mime_type (mime_type, "application/x-lzop-compressed-tar")) {
1109 if (is_program_available ("lzop", check_command))
1110 capabilities |= FR_COMMAND_CAN_READ_WRITE;
1111 }
1112 else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
1113 char *try_command[3] = { "7za", "7zr", "7z" };
1114 size_t i;
1115
1116 for (i = 0; i < G_N_ELEMENTS (try_command); i++) {
1117 if (is_program_available (try_command[i], check_command)) {
1118 capabilities |= FR_COMMAND_CAN_WRITE;
1119 break;
1120 }
1121 }
1122 }
1123
1124 return capabilities;
1125 }
1126
1127
1128 static void
fr_command_tar_set_mime_type(FrCommand * comm,const char * mime_type)1129 fr_command_tar_set_mime_type (FrCommand *comm,
1130 const char *mime_type)
1131 {
1132 FrCommandTar *comm_tar = FR_COMMAND_TAR (comm);
1133
1134 FR_COMMAND_CLASS (parent_class)->set_mime_type (comm, mime_type);
1135
1136 if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
1137 char *try_command[3] = { "7za", "7zr", "7z" };
1138 size_t i;
1139
1140 for (i = 0; i < G_N_ELEMENTS (try_command); i++) {
1141 if (is_program_in_path (try_command[i])) {
1142 comm_tar->compress_command = g_strdup (try_command[i]);
1143 break;
1144 }
1145 }
1146 }
1147 }
1148
1149
1150 static const char *
fr_command_tar_get_packages(FrCommand * comm,const char * mime_type)1151 fr_command_tar_get_packages (FrCommand *comm,
1152 const char *mime_type)
1153 {
1154 if (is_mime_type (mime_type, "application/x-tar"))
1155 return PACKAGES ("tar");
1156 else if (is_mime_type (mime_type, "application/x-compressed-tar"))
1157 return PACKAGES ("tar,gzip");
1158 else if (is_mime_type (mime_type, "application/x-bzip-compressed-tar"))
1159 return PACKAGES ("tar,bzip2");
1160 else if (is_mime_type (mime_type, "application/x-tarz"))
1161 return PACKAGES ("tar,gzip,ncompress");
1162 else if (is_mime_type (mime_type, "application/x-lrzip-compressed-tar"))
1163 return PACKAGES ("tar,lrzip");
1164 else if (is_mime_type (mime_type, "application/x-lzip-compressed-tar"))
1165 return PACKAGES ("tar,lzip");
1166 else if (is_mime_type (mime_type, "application/x-lzma-compressed-tar"))
1167 return PACKAGES ("tar,lzma");
1168 else if (is_mime_type (mime_type, "application/x-xz-compressed-tar"))
1169 return PACKAGES ("tar,xz");
1170 else if (is_mime_type (mime_type, "application/x-zstd-compressed-tar"))
1171 return PACKAGES ("tar,zstd");
1172 else if (is_mime_type (mime_type, "application/x-lzop-compressed-tar"))
1173 return PACKAGES ("tar,lzop");
1174 else if (is_mime_type (mime_type, "application/x-7z-compressed-tar"))
1175 return PACKAGES ("tar,p7zip");
1176
1177 return NULL;
1178 }
1179
1180
1181 static void
fr_command_tar_class_init(FrCommandTarClass * class)1182 fr_command_tar_class_init (FrCommandTarClass *class)
1183 {
1184 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
1185 FrCommandClass *afc;
1186
1187 parent_class = g_type_class_peek_parent (class);
1188 afc = (FrCommandClass*) class;
1189
1190 gobject_class->finalize = fr_command_tar_finalize;
1191
1192 afc->list = fr_command_tar_list;
1193 afc->add = fr_command_tar_add;
1194 afc->delete_ = fr_command_tar_delete;
1195 afc->extract = fr_command_tar_extract;
1196 afc->handle_error = fr_command_tar_handle_error;
1197 afc->get_mime_types = fr_command_tar_get_mime_types;
1198 afc->get_capabilities = fr_command_tar_get_capabilities;
1199 afc->set_mime_type = fr_command_tar_set_mime_type;
1200 afc->recompress = fr_command_tar_recompress;
1201 afc->uncompress = fr_command_tar_uncompress;
1202 afc->get_packages = fr_command_tar_get_packages;
1203 }
1204
1205
1206 static void
fr_command_tar_init(FrCommand * comm)1207 fr_command_tar_init (FrCommand *comm)
1208 {
1209 FrCommandTar *comm_tar = (FrCommandTar*) comm;
1210
1211 comm->propAddCanUpdate = FALSE;
1212 comm->propAddCanReplace = FALSE;
1213 comm->propAddCanStoreFolders = TRUE;
1214 comm->propExtractCanAvoidOverwrite = FALSE;
1215 comm->propExtractCanSkipOlder = TRUE;
1216 comm->propExtractCanJunkPaths = FALSE;
1217 comm->propPassword = FALSE;
1218 comm->propTest = FALSE;
1219 comm->propCanDeleteNonEmptyFolders = FALSE;
1220 comm->propCanExtractNonEmptyFolders = FALSE;
1221 comm->propListFromFile = TRUE;
1222
1223 comm_tar->msg = NULL;
1224 comm_tar->uncomp_filename = NULL;
1225 }
1226
1227
1228 static void
fr_command_tar_finalize(GObject * object)1229 fr_command_tar_finalize (GObject *object)
1230 {
1231 FrCommandTar *comm_tar;
1232
1233 g_return_if_fail (object != NULL);
1234 g_return_if_fail (FR_IS_COMMAND_TAR (object));
1235
1236 comm_tar = FR_COMMAND_TAR (object);
1237
1238 if (comm_tar->uncomp_filename != NULL) {
1239 g_free (comm_tar->uncomp_filename);
1240 comm_tar->uncomp_filename = NULL;
1241 }
1242
1243 if (comm_tar->msg != NULL) {
1244 g_free (comm_tar->msg);
1245 comm_tar->msg = NULL;
1246 }
1247
1248 if (comm_tar->compress_command != NULL) {
1249 g_free (comm_tar->compress_command);
1250 comm_tar->compress_command = NULL;
1251 }
1252
1253 /* Chain up */
1254 if (G_OBJECT_CLASS (parent_class)->finalize)
1255 G_OBJECT_CLASS (parent_class)->finalize (object);
1256 }
1257
1258
1259 GType
fr_command_tar_get_type()1260 fr_command_tar_get_type ()
1261 {
1262 static GType type = 0;
1263
1264 if (! type) {
1265 GTypeInfo type_info = {
1266 sizeof (FrCommandTarClass),
1267 NULL,
1268 NULL,
1269 (GClassInitFunc) fr_command_tar_class_init,
1270 NULL,
1271 NULL,
1272 sizeof (FrCommandTar),
1273 0,
1274 (GInstanceInitFunc) fr_command_tar_init
1275 };
1276
1277 type = g_type_register_static (FR_TYPE_COMMAND,
1278 "FRCommandTar",
1279 &type_info,
1280 0);
1281 }
1282
1283 return type;
1284 }
1285