~ubuntu-branches/ubuntu/saucy/mime-support/saucy-proposed

« back to all changes in this revision

Viewing changes to update-mime

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2013-05-13 12:49:12 UTC
  • mfrom: (5.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130513124912-dxt3lycmzrk6j6a2
Tags: 3.54ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Add "cautious-launcher" for handling execution of files that are
    outside /usr and /opt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
$mailcap        = "/etc/mailcap";
25
25
$mailcapdef     = "/usr/lib/mime/mailcap";
26
26
$mimedir        = "/usr/lib/mime/packages";
 
27
$appsdir        = "/usr/share/applications";
27
28
$orderfile      = "/etc/mailcap.order";
28
29
$defpriority    = 5;
29
30
$localgen       = 0;
63
64
%packages;
64
65
%priorities;
65
66
@order;
66
 
 
 
67
$counter=1;
67
68
 
68
69
 
69
70
sub ReadEntries
70
71
{
71
 
        my($pkg,$priority,$counter);
72
 
 
73
 
        $counter=1;
 
72
        my($pkg,$priority);
74
73
 
75
74
#       foreach $file (glob "$mimedir/*") {
76
75
        foreach $file (map { glob $_.'/*' } split ':',$mimedir) {
110
109
        }
111
110
}
112
111
 
 
112
sub RecurseIntoDirectories
 
113
{
 
114
        my @files;
 
115
        foreach my $dir (@_) {
 
116
                next if ($dir =~ m!(^|/)(\.|\#)|(\~)$!);
 
117
                my @entries = glob "$dir/*";
 
118
                push @files, RecurseIntoDirectories(grep { -d $_ } @entries);
 
119
                push @files, grep { -f $_ } @entries;
 
120
        }
 
121
        return @files;
 
122
}
 
123
 
 
124
sub ReadDesktopEntries
 
125
{
 
126
        my($pkg,$priority);
 
127
 
 
128
        foreach $file (RecurseIntoDirectories(split ':',$appsdir)) {
 
129
                next if ($file =~ m!(^|/)(\.|\#)|(\~)$!);
 
130
                next unless ($file =~ m/\.desktop$/);
 
131
                ($pkg) = ($file =~ m|/([^/]*)\.desktop$|);
 
132
                print STDERR "$pkg:\n" if $debug;
 
133
 
 
134
                next if (defined $packages{$pkg});
 
135
                $packages{$pkg} = [];
 
136
 
 
137
                if (open(FILE,"<$file")) {
 
138
                        my($terminal, $exec, @types) = ("test=test -n \"\$DISPLAY\"");
 
139
                        while (<FILE>) {
 
140
                                chomp;
 
141
                                next if (m/^\s*$|^\s*\#/);
 
142
                                if (m/^Terminal=(\w+)/i) {
 
143
                                        $terminal = "needsterminal" if ($1 eq "true");
 
144
                                }
 
145
                                elsif (m/Exec=(.*)$/i) {
 
146
                                        $exec = $1;
 
147
                                        $exec =~ s/%[fFuU]/%s/g;
 
148
                                        $exec .= " %s" if ($exec !~ m/%s/);
 
149
                                }
 
150
                                elsif (m/MimeType=(.*)/i) {
 
151
                                        push @types, split(/;/, $1);
 
152
                                }
 
153
                        }
 
154
                        if (!defined($exec) || !scalar(@types)) {
 
155
                                close(FILE);
 
156
                                next;
 
157
                        }
 
158
                        foreach $type (@types) {
 
159
                                my $entry = "$type; $exec; $terminal";
 
160
                                $priority=$defpriority;
 
161
                                $entries{$counter} = $entry;
 
162
                                push @{$packages{$pkg}},$counter;
 
163
                                push @{$priorities{$priority}},$counter;
 
164
                                print STDERR "$counter: $entry\n" if $debug;
 
165
                                $counter++;
 
166
                        }
 
167
                        close(FILE);
 
168
                } else {
 
169
                        print STDERR "Warning: could not open file '$file' -- $!\n";
 
170
                }
 
171
        }
 
172
}
113
173
 
114
174
 
115
175
sub ReadOrder
270
330
 
271
331
 
272
332
ReadEntries();
 
333
ReadDesktopEntries();
273
334
ReadOrder();
274
335
@list = OrderEntries();
275
336
UpdateMailcap(@list);