line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Unix::AutomountFile; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: AutomountFile.pm,v 1.4 2000/05/02 15:50:36 ssnodgra Exp $ |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
619
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
67
|
|
7
|
1
|
|
|
1
|
|
5
|
use Unix::ConfigFile; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
739
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(Unix::ConfigFile Exporter); |
12
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
13
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
14
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
15
|
|
|
|
|
|
|
@EXPORT = qw( |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
$VERSION = '0.06'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Implementation Notes |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# This module adds 2 new fields to the basic ConfigFile object. The fields |
23
|
|
|
|
|
|
|
# are 'mount' and 'options'. Both of these fields are hashes. The mount |
24
|
|
|
|
|
|
|
# field is a hash of lists, where each list contains the possible server |
25
|
|
|
|
|
|
|
# mount points for the key, and the options field contains any options |
26
|
|
|
|
|
|
|
# associated with the key. The options field may not be defined if no |
27
|
|
|
|
|
|
|
# options were present. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Preloaded methods go here. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Read in the data structures from the supplied file |
32
|
|
|
|
|
|
|
sub read { |
33
|
1
|
|
|
1
|
0
|
12
|
my ($this, $fh) = @_; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
51
|
while (<$fh>) { |
36
|
6
|
|
|
|
|
13
|
chop; |
37
|
|
|
|
|
|
|
# Currently we nuke comments and blank lines. This may change. |
38
|
6
|
50
|
|
|
|
24
|
next if /^#/; |
39
|
6
|
50
|
|
|
|
22
|
next if /^$/; |
40
|
6
|
|
|
|
|
293
|
my @fields = split; |
41
|
6
|
|
|
|
|
10
|
my $key = shift @fields; |
42
|
6
|
|
|
|
|
18
|
my $options = undef; |
43
|
6
|
100
|
|
|
|
25
|
if ($fields[0] =~ /^-/) { |
44
|
3
|
|
|
|
|
7
|
$options = shift @fields; |
45
|
|
|
|
|
|
|
} |
46
|
6
|
|
|
|
|
18
|
$this->automount($key, @fields); |
47
|
6
|
|
|
|
|
28
|
$this->options($key, $options); |
48
|
|
|
|
|
|
|
} |
49
|
1
|
|
|
|
|
6
|
return 1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Add, modify, or get an automount point |
54
|
|
|
|
|
|
|
sub automount { |
55
|
20
|
|
|
20
|
1
|
109
|
my $this = shift; |
56
|
20
|
|
|
|
|
34
|
my $key = shift; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# If no more parameters, we return automount info |
59
|
20
|
100
|
|
|
|
44
|
unless (@_) { |
60
|
12
|
100
|
|
|
|
32
|
return undef unless defined $this->{mount}{$key}; |
61
|
11
|
100
|
|
|
|
24
|
return @{$this->{mount}{$key}} unless wantarray; |
|
4
|
|
|
|
|
16
|
|
62
|
7
|
|
|
|
|
11
|
return sort @{$this->{mount}{$key}}; |
|
7
|
|
|
|
|
104
|
|
63
|
|
|
|
|
|
|
} |
64
|
8
|
|
|
|
|
49
|
$this->{mount}{$key} = [ @_ ]; |
65
|
8
|
|
|
|
|
28
|
$this->{options}{$key} = undef; |
66
|
8
|
50
|
|
|
|
448
|
return @{$this->{mount}{$key}} unless wantarray; |
|
8
|
|
|
|
|
23
|
|
67
|
0
|
|
|
|
|
0
|
return sort @{$this->{mount}{$key}}; |
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Delete an automount entry |
72
|
|
|
|
|
|
|
sub delete { |
73
|
2
|
|
|
2
|
1
|
52
|
my ($this, $key) = @_; |
74
|
|
|
|
|
|
|
|
75
|
2
|
50
|
|
|
|
8
|
return 0 unless defined $this->{mount}{$key}; |
76
|
2
|
|
|
|
|
6
|
delete $this->{mount}{$key}; |
77
|
2
|
|
|
|
|
10
|
delete $this->{options}{$key}; |
78
|
2
|
|
|
|
|
5
|
return 1; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Renames an automount entry |
83
|
|
|
|
|
|
|
sub rename { |
84
|
1
|
|
|
1
|
1
|
42
|
my ($this, $oldname, $newname) = @_; |
85
|
|
|
|
|
|
|
|
86
|
1
|
50
|
|
|
|
6
|
return 0 unless exists $this->{mount}{$oldname}; |
87
|
1
|
|
|
|
|
5
|
$this->{mount}{$newname} = $this->{mount}{$oldname}; |
88
|
1
|
|
|
|
|
4
|
$this->{options}{$newname} = $this->{options}{$oldname}; |
89
|
1
|
|
|
|
|
3
|
$this->delete($oldname); |
90
|
1
|
|
|
|
|
2
|
return 1; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Add servers to an existing automount entry |
95
|
|
|
|
|
|
|
sub add_server { |
96
|
1
|
|
|
1
|
1
|
205
|
my $this = shift; |
97
|
1
|
|
|
|
|
4
|
my $key = shift; |
98
|
|
|
|
|
|
|
|
99
|
1
|
50
|
|
|
|
7
|
return 0 unless defined $this->{mount}{$key}; |
100
|
1
|
|
|
|
|
2
|
push @{$this->{mount}{$key}}, @_; |
|
1
|
|
|
|
|
4
|
|
101
|
1
|
|
|
|
|
4
|
return 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# Return the list of automount entries |
106
|
|
|
|
|
|
|
sub automounts { |
107
|
2
|
|
|
2
|
1
|
41
|
my $this = shift; |
108
|
|
|
|
|
|
|
|
109
|
2
|
100
|
|
|
|
7
|
return keys %{$this->{mount}} unless wantarray; |
|
1
|
|
|
|
|
7
|
|
110
|
1
|
|
|
|
|
2
|
return sort keys %{$this->{mount}}; |
|
1
|
|
|
|
|
20
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Output file to disk |
115
|
|
|
|
|
|
|
sub write { |
116
|
1
|
|
|
1
|
0
|
4
|
my ($this, $fh) = @_; |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
3
|
foreach my $key ($this->automounts) { |
119
|
6
|
50
|
|
|
|
37
|
print $fh "$key\t" or return 0; |
120
|
6
|
100
|
|
|
|
13
|
if (defined $this->options($key)) { |
121
|
4
|
50
|
|
|
|
11
|
print $fh $this->options($key), "\t" or return 0; |
122
|
|
|
|
|
|
|
} |
123
|
6
|
50
|
|
|
|
14
|
print $fh join(" ", $this->automount($key)), "\n" or return 0; |
124
|
|
|
|
|
|
|
} |
125
|
1
|
|
|
|
|
7
|
return 1; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Set or return mount options |
130
|
|
|
|
|
|
|
sub options { |
131
|
19
|
|
|
19
|
1
|
231
|
my $this = shift; |
132
|
19
|
|
|
|
|
30
|
my $key = shift; |
133
|
19
|
50
|
|
|
|
45
|
return undef unless defined $this->{mount}{$key}; |
134
|
19
|
100
|
|
|
|
129
|
@_ ? $this->{options}{$key} = shift : $this->{options}{$key}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
__END__ |