diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2008-02-29 14:27:22 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2008-02-29 14:27:22 +0000 |
commit | 5e684f005b866fdd4890504b29cab22471a6ec64 (patch) | |
tree | b596bc3513b0592357344288cda684e49351cd31 /lib/Hal/Cdroms.pm | |
parent | e898892446943e1654e6774aa46ec81fb816f51d (diff) | |
download | perl-Hal-Cdroms-5e684f005b866fdd4890504b29cab22471a6ec64.tar perl-Hal-Cdroms-5e684f005b866fdd4890504b29cab22471a6ec64.tar.gz perl-Hal-Cdroms-5e684f005b866fdd4890504b29cab22471a6ec64.tar.bz2 perl-Hal-Cdroms-5e684f005b866fdd4890504b29cab22471a6ec64.tar.xz perl-Hal-Cdroms-5e684f005b866fdd4890504b29cab22471a6ec64.zip |
- save error in $hal_cdroms->{error}
- ->mount: do not set the mount point, HAL handles it
Diffstat (limited to 'lib/Hal/Cdroms.pm')
-rw-r--r-- | lib/Hal/Cdroms.pm | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/Hal/Cdroms.pm b/lib/Hal/Cdroms.pm index 77983f5..d90cbd3 100644 --- a/lib/Hal/Cdroms.pm +++ b/lib/Hal/Cdroms.pm @@ -101,10 +101,21 @@ sub get_mount_point { && $device->GetProperty('volume.mount_point') }; } +sub _try { + my ($o, $f) = @_; + + if (eval { $f->(); 1 }) { + 1; + } else { + $o->{error} = $@; + undef; + } +} + =head2 $hal_cdroms->ensure_mounted($hal_path) Mount the C<hal_path> if not already mounted. -Return the mount point associated to the C<hal_path>, or undef it cannot be mounted successfully. +Return the mount point associated to the C<hal_path>, or undef it cannot be mounted successfully (see $hal_cdroms->{error}). =cut @@ -120,7 +131,7 @@ sub ensure_mounted { =head2 $hal_cdroms->mount($hal_path) Mount the C<hal_path>. -Return the mount point associated to the C<hal_path>, or undef it cannot be mounted successfully. +Return the mount point associated to the C<hal_path>, or undef it cannot be mounted successfully (see $hal_cdroms->{error}) =cut @@ -130,18 +141,16 @@ sub mount { my $device = _get_device($o, $hal_path); my $volume = _get_volume($o, $hal_path); - my $mntpoint = $device->GetProperty('volume.label') || 'cdrom'; my $fstype = $device->GetProperty('volume.fstype'); - eval { - $volume->Mount($mntpoint, $fstype, []); - $device->GetProperty('volume.mount_point'); - }; + _try($o, sub { $volume->Mount("", $fstype, []) }) or return; + + eval { $device->GetProperty('volume.mount_point') }; } =head2 $hal_cdroms->unmount($hal_path) -Unmount the C<hal_path>. Return true on success. +Unmount the C<hal_path>. Return true on success (see $hal_cdroms->{error} on failure) =cut @@ -149,12 +158,12 @@ sub unmount { my ($o, $hal_path) = @_; my $volume = _get_volume($o, $hal_path); - eval { $volume->Unmount([]); 1 }; + _try($o, sub { $volume->Unmount([]) }); } =head2 $hal_cdroms->eject($hal_path) -Ejects the C<hal_path>. Return true on success. +Ejects the C<hal_path>. Return true on success (see $hal_cdroms->{error} on failure) =cut @@ -162,7 +171,7 @@ sub eject { my ($o, $hal_path) = @_; my $volume = _get_volume($o, $hal_path); - eval { $volume->Eject([]); 1 }; + _try($o, sub { $volume->Eject([]) }); } =head2 $hal_cdroms->wait_for_insert([$timeout]) |