~ubuntu-branches/debian/jessie/file-roller/jessie

« back to all changes in this revision

Viewing changes to src/fr-command-lrzip.c

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson
  • Date: 2013-05-25 13:13:26 UTC
  • mfrom: (1.8.1) (5.1.10 experimental)
  • Revision ID: package-import@ubuntu.com-20130525131326-bm7bv6b4yig6820h
Tags: 3.8.2-1
* New upstream release.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
#include <time.h>
12
12
#include <sys/types.h>
13
13
#include <sys/stat.h>
14
 
 
15
14
#include <glib.h>
16
 
 
17
15
#include "file-data.h"
18
16
#include "file-utils.h"
19
17
#include "glib-utils.h"
20
18
#include "fr-command.h"
21
19
#include "fr-command-lrzip.h"
22
20
 
23
 
static void fr_command_lrzip_class_init  (FrCommandLrzipClass *class);
24
 
static void fr_command_lrzip_init        (FrCommand         *afile);
25
 
static void fr_command_lrzip_finalize    (GObject           *object);
26
 
 
27
 
/* Parent Class */
28
 
 
29
 
static FrCommandClass *parent_class = NULL;
 
21
 
 
22
G_DEFINE_TYPE (FrCommandLrzip, fr_command_lrzip, FR_TYPE_COMMAND)
30
23
 
31
24
 
32
25
/* -- list -- */
48
41
                return;
49
42
 
50
43
        fdata = file_data_new ();
51
 
        fdata->size = g_ascii_strtoull (get_last_field (line, 4), NULL, 10);
 
44
        fdata->size = g_ascii_strtoull (_g_str_get_last_field (line, 4), NULL, 10);
52
45
 
53
46
        struct stat st;
54
47
        if (stat (comm->filename, &st) == 0)
58
51
 
59
52
        fdata->encrypted = FALSE;
60
53
 
61
 
        char *new_fname = g_strdup (file_name_from_path (comm->filename));
 
54
        char *new_fname = g_strdup (_g_path_get_basename (comm->filename));
62
55
        if (g_str_has_suffix (new_fname, ".lrz"))
63
56
                new_fname[strlen (new_fname) - 4] = '\0';
64
57
 
70
63
                fdata->full_path = g_strconcat ("/", new_fname, NULL);
71
64
                fdata->original_path = fdata->full_path + 1;
72
65
        }
73
 
        fdata->path = remove_level_from_path (fdata->full_path);
 
66
        fdata->path = _g_path_remove_level (fdata->full_path);
74
67
        fdata->name = new_fname;
75
68
        fdata->dir = FALSE;
76
69
        fdata->link = NULL;
78
71
        if (fdata->name == 0)
79
72
                file_data_free (fdata);
80
73
        else
81
 
                fr_command_add_file (comm, fdata);
 
74
                fr_archive_add_file (FR_ARCHIVE (comm), fdata);
82
75
}
83
76
 
84
77
 
85
 
static void
 
78
static gboolean
86
79
fr_command_lrzip_list (FrCommand  *comm)
87
80
{
88
81
        fr_process_set_err_line_func (comm->process, list__process_line, comm);
91
84
        fr_process_add_arg (comm->process, "-i");
92
85
        fr_process_add_arg (comm->process, comm->filename);
93
86
        fr_process_end_command (comm->process);
94
 
        fr_process_start (comm->process);
 
87
 
 
88
        return TRUE;
95
89
}
96
90
 
97
91
 
101
95
                      GList      *file_list,
102
96
                      const char *base_dir,
103
97
                      gboolean    update,
104
 
                      gboolean    recursive)
 
98
                      gboolean    follow_links)
105
99
{
106
100
        fr_process_begin_command (comm->process, "lrzip");
107
101
 
110
104
 
111
105
        /* preserve links. */
112
106
 
113
 
        switch (comm->compression) {
 
107
        switch (FR_ARCHIVE (comm)->compression) {
114
108
        case FR_COMPRESSION_VERY_FAST:
115
109
                fr_process_add_arg (comm->process, "-l"); break;
116
110
        case FR_COMPRESSION_FAST:
167
161
const char *lrzip_mime_type[] = { "application/x-lrzip", NULL };
168
162
 
169
163
 
170
 
const char **
171
 
fr_command_lrzip_get_mime_types (FrCommand *comm)
 
164
static const char **
 
165
fr_command_lrzip_get_mime_types (FrArchive *archive)
172
166
{
173
167
        return lrzip_mime_type;
174
168
}
175
169
 
176
170
 
177
 
FrCommandCap
178
 
fr_command_lrzip_get_capabilities (FrCommand  *comm,
 
171
static FrArchiveCap
 
172
fr_command_lrzip_get_capabilities (FrArchive  *archive,
179
173
                                   const char *mime_type,
180
174
                                   gboolean    check_command)
181
175
{
182
 
        FrCommandCap capabilities = FR_COMMAND_CAN_DO_NOTHING;
 
176
        FrArchiveCap capabilities = FR_ARCHIVE_CAN_DO_NOTHING;
183
177
 
184
 
        if (is_program_available ("lrzip", check_command))
185
 
                capabilities |= FR_COMMAND_CAN_READ_WRITE;
 
178
        if (_g_program_is_available ("lrzip", check_command))
 
179
                capabilities |= FR_ARCHIVE_CAN_READ_WRITE;
186
180
 
187
181
        return capabilities;
188
182
}
189
183
 
190
184
 
191
185
static const char *
192
 
fr_command_lrzip_get_packages (FrCommand  *comm,
 
186
fr_command_lrzip_get_packages (FrArchive  *archive,
193
187
                               const char *mime_type)
194
188
{
195
189
        return PACKAGES ("lrzip");
197
191
 
198
192
 
199
193
static void
200
 
fr_command_lrzip_class_init (FrCommandLrzipClass *class)
201
 
{
202
 
        GObjectClass   *gobject_class = G_OBJECT_CLASS (class);
203
 
        FrCommandClass *afc;
204
 
 
205
 
        parent_class = g_type_class_peek_parent (class);
206
 
        afc = (FrCommandClass*) class;
207
 
 
208
 
        gobject_class->finalize = fr_command_lrzip_finalize;
209
 
 
210
 
        afc->list             = fr_command_lrzip_list;
211
 
        afc->add              = fr_command_lrzip_add;
212
 
        afc->extract          = fr_command_lrzip_extract;
213
 
        afc->get_mime_types   = fr_command_lrzip_get_mime_types;
214
 
        afc->get_capabilities = fr_command_lrzip_get_capabilities;
215
 
        afc->get_packages     = fr_command_lrzip_get_packages;
216
 
}
217
 
 
218
 
 
219
 
static void
220
 
fr_command_lrzip_init (FrCommand *comm)
221
 
{
222
 
        comm->propAddCanUpdate             = FALSE;
223
 
        comm->propAddCanReplace            = FALSE;
224
 
        comm->propAddCanStoreFolders       = FALSE;
225
 
        comm->propExtractCanAvoidOverwrite = TRUE;
226
 
        comm->propExtractCanSkipOlder      = FALSE;
227
 
        comm->propExtractCanJunkPaths      = FALSE;
228
 
        comm->propPassword                 = FALSE;
229
 
        comm->propTest                     = FALSE;
230
 
}
231
 
 
232
 
 
233
 
static void
234
194
fr_command_lrzip_finalize (GObject *object)
235
195
{
236
196
        g_return_if_fail (object != NULL);
237
197
        g_return_if_fail (FR_IS_COMMAND_LRZIP (object));
238
198
 
239
 
        /* Chain up */
240
 
        if (G_OBJECT_CLASS (parent_class)->finalize)
241
 
                G_OBJECT_CLASS (parent_class)->finalize (object);
242
 
}
243
 
 
244
 
 
245
 
GType
246
 
fr_command_lrzip_get_type ()
247
 
{
248
 
        static GType type = 0;
249
 
 
250
 
        if (! type) {
251
 
                GTypeInfo type_info = {
252
 
                        sizeof (FrCommandLrzipClass),
253
 
                        NULL,
254
 
                        NULL,
255
 
                        (GClassInitFunc) fr_command_lrzip_class_init,
256
 
                        NULL,
257
 
                        NULL,
258
 
                        sizeof (FrCommandLrzip),
259
 
                        0,
260
 
                        (GInstanceInitFunc) fr_command_lrzip_init
261
 
                };
262
 
 
263
 
                type = g_type_register_static (FR_TYPE_COMMAND,
264
 
                                               "FRCommandLrzip",
265
 
                                               &type_info,
266
 
                                               0);
267
 
        }
268
 
 
269
 
        return type;
 
199
        if (G_OBJECT_CLASS (fr_command_lrzip_parent_class)->finalize)
 
200
                G_OBJECT_CLASS (fr_command_lrzip_parent_class)->finalize (object);
 
201
}
 
202
 
 
203
 
 
204
static void
 
205
fr_command_lrzip_class_init (FrCommandLrzipClass *klass)
 
206
{
 
207
        GObjectClass   *gobject_class;
 
208
        FrArchiveClass *archive_class;
 
209
        FrCommandClass *command_class;
 
210
 
 
211
        fr_command_lrzip_parent_class = g_type_class_peek_parent (klass);
 
212
 
 
213
        gobject_class = G_OBJECT_CLASS (klass);
 
214
        gobject_class->finalize = fr_command_lrzip_finalize;
 
215
 
 
216
        archive_class = FR_ARCHIVE_CLASS (klass);
 
217
        archive_class->get_mime_types   = fr_command_lrzip_get_mime_types;
 
218
        archive_class->get_capabilities = fr_command_lrzip_get_capabilities;
 
219
        archive_class->get_packages     = fr_command_lrzip_get_packages;
 
220
 
 
221
        command_class = FR_COMMAND_CLASS (klass);
 
222
        command_class->list             = fr_command_lrzip_list;
 
223
        command_class->add              = fr_command_lrzip_add;
 
224
        command_class->extract          = fr_command_lrzip_extract;
 
225
}
 
226
 
 
227
 
 
228
static void
 
229
fr_command_lrzip_init (FrCommandLrzip *self)
 
230
{
 
231
        FrArchive *base = FR_ARCHIVE (self);
 
232
 
 
233
        base->propAddCanUpdate             = FALSE;
 
234
        base->propAddCanReplace            = FALSE;
 
235
        base->propAddCanStoreFolders       = FALSE;
 
236
        base->propAddCanStoreLinks         = FALSE;
 
237
        base->propExtractCanAvoidOverwrite = TRUE;
 
238
        base->propExtractCanSkipOlder      = FALSE;
 
239
        base->propExtractCanJunkPaths      = FALSE;
 
240
        base->propPassword                 = FALSE;
 
241
        base->propTest                     = FALSE;
270
242
}