diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2008-02-26 21:40:41 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2008-02-26 21:40:41 +0000 |
commit | 4e70971c3741b3311e27dbf009d12719e0ce09f1 (patch) | |
tree | 72c0f26e4036340b5e89dc538f6bdf999469ec1d | |
parent | 0729347e519554ad7a9d1bb24697a31e57e15b0c (diff) | |
download | urpmi-4e70971c3741b3311e27dbf009d12719e0ce09f1.tar urpmi-4e70971c3741b3311e27dbf009d12719e0ce09f1.tar.gz urpmi-4e70971c3741b3311e27dbf009d12719e0ce09f1.tar.bz2 urpmi-4e70971c3741b3311e27dbf009d12719e0ce09f1.tar.xz urpmi-4e70971c3741b3311e27dbf009d12719e0ce09f1.zip |
create _read_fstab_or_mtab() to factorise
-rw-r--r-- | urpm/sys.pm | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/urpm/sys.pm b/urpm/sys.pm index 2e71943f..aafe7b64 100644 --- a/urpm/sys.pm +++ b/urpm/sys.pm @@ -25,6 +25,20 @@ sub get_packages_list { } @l ]; } +sub _read_fstab_or_mtab { + my ($file) = @_; + + my @l; + foreach (cat_($file)) { + next if /^\s*#/; + my ($device, $mntpoint, $fstype, $_options) = m!^\s*(\S+)\s+(/\S+)\s+(\S+)\s+(\S+)! + or next; + $mntpoint =~ s,/+,/,g; $mntpoint =~ s,/$,,; + push @l, { mntpoint => $mntpoint, device => $device, fs => $fstype }; + } + @l; +} + #- find used mount point from a pathname, use a optional mode to allow #- filtering according the next operation (mount or umount). sub find_mntpoints { @@ -32,20 +46,13 @@ sub find_mntpoints { my (%fstab, @mntpoints); #- read /etc/fstab and check for existing mount point. - foreach (cat_("/etc/fstab")) { - next if /^\s*#/; - my ($device, $mntpoint, $fstype, $options) = m!^\s*(\S+)\s+(/\S+)\s+(\S+)\s+(\S+)! - or next; - $mntpoint =~ s,/+,/,g; $mntpoint =~ s,/$,,; - $fstab{$mntpoint} = 0; - $infos->{$mntpoint} = { mounted => 0, device => $device, fs => $fstype }; + foreach (_read_fstab_or_mtab("/etc/fstab")) { + $fstab{$_->{mntpoint}} = 0; + $infos->{$_->{mntpoint}} = { mounted => 0, %$_ }; } - foreach (cat_("/etc/mtab")) { - my ($device, $mntpoint, $fstype, $options) = m!^\s*(\S+)\s+(/\S+)\s+(\S+)\s+(\S+)! - or next; - $mntpoint =~ s,/+,/,g; $mntpoint =~ s,/$,,; - $fstab{$mntpoint} = 1; - $infos->{$mntpoint} = { mounted => 1, device => $device, fs => $fstype }; + foreach (_read_fstab_or_mtab("/etc/mtab")) { + $fstab{$_->{mntpoint}} = 1; + $infos->{$_->{mntpoint}} = { mounted => 1, %$_ }; } #- try to follow symlink, too complex symlink graph may not be seen. |