[vhffs-dev] [2056] Improved Vhffs::Robots::link_to_group and Vhffs::Robots:: unlink_from_group so that it matchs what is expected by Robots:: Web and Robots::Repository recently reworked |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [2056] Improved Vhffs::Robots::link_to_group and Vhffs::Robots:: unlink_from_group so that it matchs what is expected by Robots:: Web and Robots::Repository recently reworked
- From: subversion@xxxxxxxxxxxxx
- Date: Sat, 25 Feb 2012 16:27:27 +0100
Revision: 2056
Author: gradator
Date: 2012-02-25 16:27:26 +0100 (Sat, 25 Feb 2012)
Log Message:
-----------
Improved Vhffs::Robots::link_to_group and Vhffs::Robots::unlink_from_group so that it matchs what is expected by Robots::Web and Robots::Repository recently reworked
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Robots/Repository.pm
trunk/vhffs-api/src/Vhffs/Robots/Web.pm
trunk/vhffs-api/src/Vhffs/Robots.pm
Modified: trunk/vhffs-api/src/Vhffs/Robots/Repository.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Repository.pm 2012-02-25 15:04:04 UTC (rev 2055)
+++ trunk/vhffs-api/src/Vhffs/Robots/Repository.pm 2012-02-25 15:27:26 UTC (rev 2056)
@@ -66,7 +66,7 @@
chown( $repository->get_owner_uid, $repository->get_owner_gid, $dir );
chmod( 02775, $dir );
- unless( Vhffs::Robots::link_to_group( $repository->get_group, $repository->get_name.'-repository', $dir ) ) {
+ unless( Vhffs::Robots::link_to_group( $repository, $repository->get_name.'-repository', $dir ) ) {
$repository->set_status( Vhffs::Constants::CREATION_ERROR );
$repository->commit;
return undef;
@@ -84,7 +84,7 @@
my $vhffs = $repository->get_main;
my $dir = $repository->get_dir;
- unless( Vhffs::Robots::unlink_from_group( $repository->get_group, $repository->get_name.'-repository' ) ) {
+ unless( Vhffs::Robots::unlink_from_group( $repository, $repository->get_name.'-repository' ) ) {
$repository->set_status( Vhffs::Constants::DELETION_ERROR );
$repository->commit;
return undef;
Modified: trunk/vhffs-api/src/Vhffs/Robots/Web.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Web.pm 2012-02-25 15:04:04 UTC (rev 2055)
+++ trunk/vhffs-api/src/Vhffs/Robots/Web.pm 2012-02-25 15:27:26 UTC (rev 2056)
@@ -70,7 +70,7 @@
chmod( 02775, $_ );
}
- unless( Vhffs::Robots::link_to_group( $web->get_group, $web->get_servername.'-web', $dir ) ) {
+ unless( Vhffs::Robots::link_to_group( $web, $web->get_servername.'-web', $dir ) ) {
$web->set_status( Vhffs::Constants::CREATION_ERROR );
$web->commit;
return undef;
@@ -88,7 +88,7 @@
my $vhffs = $web->get_main;
my $dir = $web->get_dir;
- unless( Vhffs::Robots::unlink_from_group( $web->get_group, $web->get_servername.'-web' ) ) {
+ unless( Vhffs::Robots::unlink_from_group( $web, $web->get_servername.'-web' ) ) {
$web->set_status( Vhffs::Constants::DELETION_ERROR );
$web->commit;
return undef;
Modified: trunk/vhffs-api/src/Vhffs/Robots.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots.pm 2012-02-25 15:04:04 UTC (rev 2055)
+++ trunk/vhffs-api/src/Vhffs/Robots.pm 2012-02-25 15:27:26 UTC (rev 2056)
@@ -62,10 +62,6 @@
Vhffs::Robots::vhffs_log( "My log message" );
- Vhffs::Robots::link_to_group( "/path/to" , Vhffs::Group , "linkname" , Vhffs::Main);
-
- Vhffs::Robots::unlink_from_group( Vhffs::Group , "linkname" , Vhffs::Main);
-
=head1 DESCRIPTION
This class contains static methods commonly used by VHFFS robots.
@@ -147,30 +143,29 @@
=head2 link_to_group
-Vhffs::Robots::link_to_group( $group, $linkname, $dir );
+Vhffs::Robots::link_to_group( $object, $linkname, $dir );
-Create a symbolic link in C<$group> home directory named $linkname which contains string $dir.
+Create a symbolic link in C<$object> group home directory named $linkname which contains string $dir.
+Returns true on success, otherwise returns undef.
+
=cut
sub link_to_group {
- my $group = shift;
+ my $object = shift;
my $linkname = shift;
my $dir = shift;
- return -1 unless defined $group;
+ return undef unless defined $object and defined $linkname and defined $dir;
- return 1 if $group->get_main->get_config->use_vhffsfs;
+ my $vhffs = $object->get_main;
+ return 1 if $vhffs->get_config->use_vhffsfs;
- return -1 unless symlink( $dir , $group->get_dir.'/'.$linkname );
+ my $linkpath = $object->get_group->get_dir.'/'.$linkname;
+ unless( symlink( $dir, $linkpath ) ) {
+ Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating symlink '.$linkpath.' -> '.$dir );
+ return undef;
+ }
-#TODO: change return values
-
-# TODO: add messages to logfile and object history
-# $web->add_history( "Can't link the webdirectory to the specified group");
-# }
-# else {
-# $web->add_history( "Ok, robots finished to create webdir. Webdir is now linked to the group directory");
-# }
-
+ Vhffs::Robots::vhffs_log( $vhffs, 'Created symlink '.$linkpath.' -> '.$dir );
return 1;
}
@@ -178,29 +173,28 @@
=head2 unlink_from_group
-Vhffs::Robots::unlink_from_group( $group, $linkname );
+Vhffs::Robots::unlink_from_group( $object, $linkname );
-Delete a symbolic link in C<$group> home directory named $linkname.
+Delete a symbolic link in C<$object> group home directory named $linkname.
+Returns true on success, otherwise returns undef.
+
=cut
sub unlink_from_group {
- my $group = shift;
+ my $object = shift;
my $linkname = shift;
- return -1 unless defined $group;
+ return undef unless defined $object and defined $linkname;
- return 1 if $group->get_main->get_config->use_vhffsfs;
+ my $vhffs = $object->get_main;
+ return 1 if $vhffs->get_config->use_vhffsfs;
- return -1 unless unlink( $group->get_dir.'/'.$linkname );
+ my $linkpath = $object->get_group->get_dir.'/'.$linkname;
+ unless( unlink( $linkpath ) ) {
+ Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while deleting symlink '.$linkpath.': '.$! );
+ return undef;
+ }
-#TODO: change return values
-
-# TODO: add messages to logfile and object history
-# $web->add_history( "Can't unlink the webdirectory from the specified group");
-# }
-# else {
-# $web->add_history( "Webdir is now unlinked from the group directory");
-# }
-
+ Vhffs::Robots::vhffs_log( $vhffs, 'Deleted symlink '.$linkpath );
return 1;
}