Commit 11ee1e69 authored by frankiejol's avatar frankiejol
Browse files

fix(volumes): check file exists when linked

if locally we use -e , else we follow the link

issue #1524
parent bfa9a571
......@@ -454,12 +454,21 @@ Returns true if the file exists in this virtual manager storage
=cut
sub file_exists($self, $file) {
return -e $file if $self->is_local;
return $self->_file_exists_remote($file);
}
sub _file_exists_remote($self, $file) {
$file = $self->_follow_link($file);
for my $pool ($self->vm->list_all_storage_pools ) {
$self->_wait_storage( sub { $pool->refresh() } );
my @volumes = $self->_wait_storage( sub { $pool->list_all_volumes });
for my $vol ( @volumes ) {
my $found;
eval { $found = 1 if $vol->get_path eq $file };
eval {
my $path = $self->_follow_link($vol->get_path);
$found = 1 if $path eq $file;
};
# volume was removed in the nick of time
die $@ if $@ && ( !ref($@) || $@->code != 50);
return 1 if $found;
......@@ -468,6 +477,20 @@ sub file_exists($self, $file) {
return 0;
}
sub _follow_link($self, $file) {
my ($dir, $name) = $file =~ m{(.*)/(.*)};
if (!defined $self->{_is_link}->{$dir} ) {
my ($out,$err) = $self->run_command("stat", $dir );
chomp $out;
$out =~ m{ -> (/.*)};
$self->{_is_link}->{$dir} = $1;
}
my $path = $self->{_is_link}->{$dir};
return $file if !$path;
return "$path/$name";
}
sub _wait_storage($self, $sub) {
my @ret;
for ( 1 .. 10 ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment