Hal-Cdroms
view release on metacpan or search on metacpan
lib/Hal/Cdroms.pm view on Meta::CPAN
print "$udisks_path is now mounted in $m\n";
=head1 DESCRIPTION
Access removable media containing CD filesystems (iso9660 and udf) through
UDisks2 and D-Bus. This includes CD-ROMS, DVD-ROMS, and USB flash drives.
=cut
# internal constant
my $dn = 'org.freedesktop.UDisks2';
=head2 Hal::Cdroms->new
Creates the object
=cut
sub new {
my ($class) = @_;
lib/Hal/Cdroms.pm view on Meta::CPAN
=head2 $cdroms->list
Return the list of C<udisks_path> of the removable media (mounted or not).
=cut
sub list {
my ($o) = @_;
my $manager = $o->{service}->get_object('/org/freedesktop/UDisks2/Manager');
grep { _is_cdrom($o, $_) } @{$manager->GetBlockDevices(undef)};
}
=head2 $cdroms->get_mount_point($udisks_path)
Return the mount point associated to the C<udisks_path>, or undef it is not mounted.
=cut
t/20-mount-unmount.t view on Meta::CPAN
use Test::More;
plan skip_all => "You need to be root to run this test" if $> != 0;
plan skip_all => "The scsi_debug kernel module is needed to run this test" if !can_create_fake_media();
use_ok('Hal::Cdroms');
my $fake_device = create_fake_media();
my $cdroms = Hal::Cdroms->new;
my @udisks_paths = grep { $_ eq "/org/freedesktop/UDisks2/block_devices/$fake_device" } $cdroms->list;
ok(@udisks_paths == 1, 'device is listed');
# If a volume manager is running, the device may get auto-mounted.
# Wait to see if this happens, and if so, unmount it.
sleep(2);
my $mount_point = find_mount_point($fake_device);
if ($mount_point) {
ok($cdroms->get_mount_point($udisks_paths[0]) eq $mount_point, 'get_mount_point returns correct path');
ok($cdroms->unmount($udisks_paths[0]), 'unmount returns success');
$mount_point = find_mount_point($fake_device);
t/21-ensure-mounted.t view on Meta::CPAN
use Test::More;
plan skip_all => "You need to be root to run this test" if $> != 0;
plan skip_all => "The scsi_debug kernel module is needed to run this test" if !can_create_fake_media();
use_ok('Hal::Cdroms');
my $fake_device = create_fake_media();
my $cdroms = Hal::Cdroms->new;
my @udisks_paths = grep { $_ eq "/org/freedesktop/UDisks2/block_devices/$fake_device" } $cdroms->list;
ok(@udisks_paths == 1, 'device is listed');
# If a volume manager is running, the device may get auto-mounted.
# Wait to see if this happens, and if so, unmount it.
sleep(2);
my $mount_point = find_mount_point($fake_device);
if ($mount_point) {
ok($cdroms->unmount($udisks_paths[0]), 'unmount returns success');
$mount_point = find_mount_point($fake_device);
}
t/22-eject.t view on Meta::CPAN
use Test::More;
plan skip_all => "You need to be root to run this test" if $> != 0;
plan skip_all => "The scsi_debug kernel module is needed to run this test" if !can_create_fake_media();
use_ok('Hal::Cdroms');
my $fake_device = create_fake_media();
my $cdroms = Hal::Cdroms->new;
my @udisks_paths = grep { $_ eq "/org/freedesktop/UDisks2/block_devices/$fake_device" } $cdroms->list;
ok(@udisks_paths == 1, 'device is listed');
# If a volume manager is running, the device may get auto-mounted.
# Allow this to settle before proceeding.
sleep(2);
# Ensure the device is mounted.
ok($cdroms->ensure_mounted($udisks_paths[0]), 'ensure_mounted returns success');
my $mount_point = find_mount_point($fake_device);
ok($mount_point, 'device is mounted');
t/23-wait-for-insert.t view on Meta::CPAN
plan skip_all => "The scsi_debug kernel module is needed to run this test" if !can_create_fake_media();
plan 'no_plan';
use_ok('Hal::Cdroms');
my $fake_device = create_fake_media(3);
my $cdroms = Hal::Cdroms->new;
my $udisks_path = $cdroms->wait_for_insert(10000);
ok($udisks_path eq "/org/freedesktop/UDisks2/block_devices/$fake_device", 'wait_for_insert returns correct path');
done_testing();
END {
system("umount /dev/$fake_device") if find_mount_point($fake_device);
remove_fake_media() if $> == 0;
}
t/24-wait-for-mounted.t view on Meta::CPAN
my $fake_device = create_fake_media(3);
if (!$auto_mounted) {
my $tmp_dir = tempdir(CLEANUP => 1);
system("(sleep 4; mount /dev/$fake_device $tmp_dir)&");
}
my $cdroms = Hal::Cdroms->new;
my $udisks_path = $cdroms->wait_for_mounted();
ok($udisks_path eq "/org/freedesktop/UDisks2/block_devices/$fake_device", 'wait_for_mounted returns correct path');
my $mount_point = find_mount_point($fake_device);
ok($mount_point, 'device is mounted');
ok($cdroms->get_mount_point($udisks_path) eq $mount_point, 'get_mount_point returns correct path');
done_testing();
END {
system("umount /dev/$fake_device") if find_mount_point($fake_device);
remove_fake_media() if $> == 0;
}
( run in 0.382 second using v1.01-cache-2.11-cpan-299005ec8e3 )