diff options
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]) |