line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package urpm::removable; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
814
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
26
|
use urpm::msg; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use urpm::sys; |
7
|
|
|
|
|
|
|
use urpm::util 'reduce_pathname'; |
8
|
|
|
|
|
|
|
use urpm 'file_from_local_medium'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
urpm::removable - Removable media routines for urpmi |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=over |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=cut |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub file_or_synthesis_dir { |
26
|
|
|
|
|
|
|
my ($medium, $o_url) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
urpm::media::_valid_synthesis_dir($medium) && !$o_url ? |
29
|
|
|
|
|
|
|
urpm::media::_synthesis_dir($medium) : |
30
|
|
|
|
|
|
|
file_from_local_medium($medium, $o_url); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub file_or_synthesis_dir_from_blist { |
34
|
|
|
|
|
|
|
my ($blist) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
file_or_synthesis_dir($blist->{medium}, _blist_first_url($blist)); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#- side-effects: |
40
|
|
|
|
|
|
|
#- + those of try_mounting_medium_ ($medium->{mntpoint}) |
41
|
|
|
|
|
|
|
sub try_mounting_medium { |
42
|
|
|
|
|
|
|
my ($urpm, $medium, $o_blist) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $rc = try_mounting_medium_($urpm, $medium, $o_blist); |
45
|
|
|
|
|
|
|
$rc or $urpm->{error}(N("unable to access medium \"%s\".", $medium->{name})); |
46
|
|
|
|
|
|
|
$rc; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#- side-effects: |
50
|
|
|
|
|
|
|
#- + those of urpm::cdrom::try_mounting_cdrom ($urpm->{cdrom_mounted}, $medium->{mntpoint}, "hal_mount") |
51
|
|
|
|
|
|
|
#- + those of _try_mounting_local ($urpm->{removable_mounted}, "mount") |
52
|
|
|
|
|
|
|
sub try_mounting_medium_ { |
53
|
|
|
|
|
|
|
my ($urpm, $medium, $o_blist) = @_; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if (urpm::is_cdrom_url($medium->{url})) { |
56
|
|
|
|
|
|
|
require urpm::cdrom; |
57
|
|
|
|
|
|
|
urpm::cdrom::try_mounting_cdrom($urpm, [ { medium => $medium, pkgs => $o_blist && $o_blist->{pkgs} } ]); |
58
|
|
|
|
|
|
|
} else { |
59
|
|
|
|
|
|
|
_try_mounting_local($urpm, $medium, $o_blist); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#- side-effects: |
64
|
|
|
|
|
|
|
#- + those of _try_mounting_using_fstab ($urpm->{removable_mounted}, "mount") |
65
|
|
|
|
|
|
|
#- + those of _try_mounting_iso ($urpm->{removable_mounted}, "mount") |
66
|
|
|
|
|
|
|
sub _try_mounting_local { |
67
|
|
|
|
|
|
|
my ($urpm, $medium, $o_blist) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $dir = file_or_synthesis_dir($medium, $o_blist && _blist_first_url($o_blist)); |
70
|
|
|
|
|
|
|
-e $dir and return 1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$medium->{iso} ? _try_mounting_iso($urpm, $dir, $medium->{iso}) : _try_mounting_using_fstab($urpm, $dir); |
73
|
|
|
|
|
|
|
-e $dir; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#- side-effects: $urpm->{removable_mounted}, "mount" |
77
|
|
|
|
|
|
|
sub _try_mounting_iso { |
78
|
|
|
|
|
|
|
my ($urpm, $dir, $iso) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
#- note: for isos, we don't parse the fstab because it might not be declared in it. |
81
|
|
|
|
|
|
|
#- so we try to remove suffixes from the dir name until the dir exists |
82
|
|
|
|
|
|
|
my $mntpoint = urpm::sys::trim_until_d($dir); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
if ($mntpoint) { |
85
|
|
|
|
|
|
|
$urpm->{log}(N("mounting %s", $mntpoint)); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sys_log("mount iso $mntpoint on $iso"); |
88
|
|
|
|
|
|
|
system('mount', $iso, $mntpoint, qw(-t iso9660 -o loop)); |
89
|
|
|
|
|
|
|
$urpm->{removable_mounted}{$mntpoint} = undef; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#- side-effects: $urpm->{removable_mounted}, "mount" |
94
|
|
|
|
|
|
|
sub _try_mounting_using_fstab { |
95
|
|
|
|
|
|
|
my ($urpm, $dir) = @_; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $mntpoint = _non_mounted_mntpoint($dir); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
if ($mntpoint) { |
100
|
|
|
|
|
|
|
$urpm->{log}(N("mounting %s", $mntpoint)); |
101
|
|
|
|
|
|
|
sys_log("mount $mntpoint"); |
102
|
|
|
|
|
|
|
system("mount '$mntpoint' 2>/dev/null"); |
103
|
|
|
|
|
|
|
$urpm->{removable_mounted}{$mntpoint} = undef; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#- side-effects: $urpm->{removable_mounted}, "umount" |
108
|
|
|
|
|
|
|
sub try_umounting { |
109
|
|
|
|
|
|
|
my ($urpm, $dir) = @_; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
if (my $mntpoint = _mounted_mntpoint($dir)) { |
112
|
|
|
|
|
|
|
$urpm->{log}(N("unmounting %s", $mntpoint)); |
113
|
|
|
|
|
|
|
sys_log("umount $mntpoint"); |
114
|
|
|
|
|
|
|
system("umount '$mntpoint' 2>/dev/null"); |
115
|
|
|
|
|
|
|
delete $urpm->{removable_mounted}{$mntpoint}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
! -e $dir; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
#- side-effects: none |
121
|
|
|
|
|
|
|
sub _mounted_mntpoint { |
122
|
|
|
|
|
|
|
my ($dir) = @_; |
123
|
|
|
|
|
|
|
$dir = reduce_pathname($dir); |
124
|
|
|
|
|
|
|
my $entry = urpm::sys::find_a_mntpoint($dir); |
125
|
|
|
|
|
|
|
$entry->{mounted} && $entry->{mntpoint}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
#- side-effects: none |
128
|
|
|
|
|
|
|
sub _non_mounted_mntpoint { |
129
|
|
|
|
|
|
|
my ($dir) = @_; |
130
|
|
|
|
|
|
|
$dir = reduce_pathname($dir); |
131
|
|
|
|
|
|
|
my $entry = urpm::sys::find_a_mntpoint($dir); |
132
|
|
|
|
|
|
|
!$entry->{mounted} && $entry->{mntpoint}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#- side-effects: $urpm->{removable_mounted} |
136
|
|
|
|
|
|
|
#- + those of try_umounting ($urpm->{removable_mounted}, umount) |
137
|
|
|
|
|
|
|
sub try_umounting_removables { |
138
|
|
|
|
|
|
|
my ($urpm) = @_; |
139
|
|
|
|
|
|
|
foreach (keys %{$urpm->{removable_mounted}}) { |
140
|
|
|
|
|
|
|
try_umounting($urpm, $_); |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
delete $urpm->{removable_mounted}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
#- side-effects: |
146
|
|
|
|
|
|
|
#- + those of try_mounting_non_cdrom ($urpm->{removable_mounted}, "mount") |
147
|
|
|
|
|
|
|
sub try_mounting_non_cdroms { |
148
|
|
|
|
|
|
|
my ($urpm, $blists) = @_; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
foreach my $blist (grep { urpm::file_from_local_url($_->{medium}{url}) } @$blists) { |
151
|
|
|
|
|
|
|
try_mounting_medium($urpm, $blist->{medium}, $blist); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
#- side-effects: none |
156
|
|
|
|
|
|
|
sub _blist_first_url { |
157
|
|
|
|
|
|
|
my ($blist) = @_; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
my ($pkg) = values %{$blist->{pkgs}} or return; |
160
|
|
|
|
|
|
|
urpm::blist_pkg_to_url($blist, $pkg); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 COPYRIGHT |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Copyright (C) 2005 MandrakeSoft SA |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Copyright (C) 2005-2010 Mandriva SA |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Copyright (C) 2011-2017 Mageia |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |