~ubuntu-branches/ubuntu/karmic/xarchiver/karmic

« back to all changes in this revision

Viewing changes to src/deb.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-11-07 14:54:00 UTC
  • mfrom: (1.1.7 upstream) (2.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20081107145400-z0j3jmgads8coae2
Tags: 0.5.1-1
MergingĀ upstreamĀ versionĀ 0.5.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2006 Giuseppe Torelli - <colossus73@gmail.com>
 
2
 *  Copyright (C) 2008 Giuseppe Torelli - <colossus73@gmail.com>
3
3
 *  Copyright (C) 2006 Lukasz 'Sil2100' Zemczak - <sil2100@vexillium.org>
4
4
 *
5
5
 *  This program is free software; you can redistribute it and/or modify
19
19
 
20
20
#include "config.h"
21
21
#include "deb.h"
22
 
#include "string_utils.h"
23
 
 
24
 
void OpenDeb ( XArchive *archive )
 
22
#include <string.h>
 
23
 
 
24
extern void xa_create_liststore (XArchive *archive,gchar *columns_names[]);
 
25
 
 
26
void xa_open_deb (XArchive *archive)
25
27
{
26
28
        gchar *command = NULL;
27
 
        gchar *archive_no_path = NULL;
28
 
        gboolean result;
29
 
 
30
 
        archive_no_path = g_strrstr (archive->escaped_path,"/");
31
 
        archive_no_path++;
32
 
        archive->tmp = g_strconcat (" /tmp/",archive_no_path,NULL);
33
 
 
34
 
        /* Let's copy the .deb archive to /tmp */
35
 
        command = g_strconcat ("cp ",archive->escaped_path,archive->tmp,NULL);
36
 
        result = xa_run_command ( command , 0);
37
 
        g_free (command);
38
 
        if (result == FALSE)
39
 
                return;
40
 
 
41
 
        /* Ok, let's now extract the .deb archive with ar */
42
 
        chdir ("/tmp");
43
 
        command = g_strconcat ("ar xv" , archive->tmp, NULL);
44
 
        result = xa_run_command ( command , 0);
45
 
        g_free (command);
46
 
        g_free (archive->tmp);
47
 
        archive->tmp = g_strdup ("/tmp/data.tar.gz");
48
 
 
49
 
        unlink ("/tmp/control.tar.gz");
50
 
        unlink ("/tmp/debian-binary");
51
 
        unlink (archive_no_path);
52
 
 
53
 
        if (result == FALSE)
54
 
                return;
55
 
 
56
 
        /* Finally, let's show the content in /tmp/data.tar.gz */
57
 
        command = g_strconcat ("tar tfzv /tmp/data.tar.gz", NULL);
 
29
        unsigned short int i;
 
30
 
 
31
        command = g_strconcat ("ar tv ",archive->escaped_path,NULL);
 
32
        archive->has_properties = archive->can_extract = TRUE;
 
33
        archive->can_add = archive->has_test = archive->has_sfx = FALSE;
58
34
        archive->dummy_size = 0;
59
35
        archive->nr_of_files = 0;
60
 
        archive->nr_of_dirs = 0;
61
 
        archive->format ="DEB";
62
 
        archive->parse_output = TarOpen;
63
 
        SpawnAsyncProcess ( archive , command , 0, 0);
 
36
        archive->nc = 5;
 
37
        archive->format = "DEB";
 
38
        archive->parse_output = xa_get_ar_line_content;
 
39
        xa_spawn_async_process (archive,command);
64
40
        g_free (command);
65
41
 
66
42
        if (archive->child_pid == 0)
67
43
                return;
68
44
 
69
 
        char *names[]= {(_("Filename")),(_("Permissions")),(_("Symbolic Link")),(_("Owner/Group")),(_("Size")),(_("Date")),(_("Time"))};
70
 
        GType types[]= {G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING};
71
 
        xa_create_liststore ( 7, names , (GType *)types, archive );
 
45
        char *names[]= {(_("Permissions")),(_("Owner/Group")),(_("Size")),(_("Date modified")),NULL};
 
46
        GType types[]= {GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_POINTER};
 
47
        archive->column_types = g_malloc0(sizeof(types));
 
48
        for (i = 0; i < 7; i++)
 
49
                archive->column_types[i] = types[i];
 
50
        xa_create_liststore (archive,names);
 
51
}
 
52
 
 
53
void xa_get_ar_line_content (gchar *line, gpointer data)
 
54
{
 
55
        XArchive *archive = data;
 
56
        XEntry *entry;
 
57
        gchar *filename;
 
58
        gpointer item[4];
 
59
        gint n = 0, a = 0 ,linesize = 0;
 
60
 
 
61
        linesize = strlen(line);
 
62
 
 
63
        /* Permissions */
 
64
        line[9] = '\0';
 
65
        item[0] = line;
 
66
        
 
67
        /* Owner */
 
68
        for(n=12; n < linesize; ++n)
 
69
                if(line[n] == ' ')
 
70
                        break;
 
71
        line[n] = '\0';
 
72
        item[1] = line+10;
 
73
 
 
74
        /* Size */      
 
75
        for(++n; n < linesize; ++n)
 
76
                if(line[n] >= '0' && line[n] <= '9')
 
77
                        break;
 
78
        a = n;
 
79
 
 
80
        for(; n < linesize; ++n)
 
81
                if(line[n] == ' ')
 
82
                        break;
 
83
 
 
84
        line[n] = '\0';
 
85
        item[2] = line + a;
 
86
        archive->dummy_size += g_ascii_strtoull(item[2],NULL,0);
 
87
        a = ++n;
 
88
 
 
89
        /* Date Modified */     
 
90
        for(; n < linesize; ++n)
 
91
        {
 
92
                if(n == 38)
 
93
                        break;
 
94
        }
 
95
        if (line[n] != ' ')
 
96
        {
 
97
                for(; n < linesize; ++n)
 
98
                {
 
99
                        if(line[n] == ' ')
 
100
                        break;
 
101
                }
 
102
        }
 
103
        line[n] = '\0';
 
104
        item[3] = line + a;
 
105
 
 
106
        n++;
 
107
        line[linesize-1] = '\0';
 
108
 
 
109
        archive->nr_of_files++;
 
110
        filename = g_strdup(line + n);
 
111
        entry = xa_set_archive_entries_for_each_row (archive,filename,item);
 
112
        g_free(filename);
 
113
}
 
114
 
 
115
gboolean xa_deb_extract(XArchive *archive,GSList *files)
 
116
{
 
117
        gchar *command;
 
118
        GSList *list = NULL,*_files = NULL;
 
119
        GString *names = g_string_new("");
 
120
        gboolean result = FALSE;
 
121
 
 
122
        _files = files;
 
123
        while (_files)
 
124
        {
 
125
                g_string_prepend (names,(gchar*)_files->data);
 
126
                g_string_prepend_c (names,' ');
 
127
                _files = _files->next;
 
128
        }
 
129
        g_slist_foreach(files,(GFunc)g_free,NULL);
 
130
        g_slist_free(files);
 
131
 
 
132
        chdir (archive->extraction_path);
 
133
        command = g_strconcat ("ar x ",archive->escaped_path," ",names->str,NULL);
 
134
        if (command != NULL)
 
135
        {
 
136
                g_string_free(names,FALSE);
 
137
                list = g_slist_append(list,command);
 
138
                result = xa_run_command (archive,list);
 
139
        }
 
140
        return result;
72
141
}