From 5e684f005b866fdd4890504b29cab22471a6ec64 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 29 Feb 2008 14:27:22 +0000 Subject: - save error in $hal_cdroms->{error} - ->mount: do not set the mount point, HAL handles it --- lib/Hal/Cdroms.pm | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'lib') 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 if not already mounted. -Return the mount point associated to the C, or undef it cannot be mounted successfully. +Return the mount point associated to the C, 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. -Return the mount point associated to the C, or undef it cannot be mounted successfully. +Return the mount point associated to the C, 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. Return true on success. +Unmount the C. 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. Return true on success. +Ejects the C. 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]) -- cgit v1.2.1