Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help removing symbolic link

Status
Not open for further replies.

johndrake

Technical User
Jul 25, 2002
97
Hi All,

I'm trying to delete a symbolic link to a directory and to create a new one to a directory. The symbolic link is not getting deleted, although it says that it is. Each time I run this I should get the following:

link is /home/jpape/wlcbs_current_build
/home/jpape/wlcbs_current_build points at '/home/jpape/wlcbs_4'

Essentially this is what I am hoping to create each time run the code:

lrwxrwxrwx 1 jpape jpape 19 Jan 29 15:09 wlcbs_current_build -> /home/jpape/wlcbs_4

When I run the program second time, this is what I am getting:

link is /home/jpape/wlcbs_current_build
deleting /home/jpape/wlcbs_current_build
/home/jpape/wlcbs_current_build points at '/home/jpape/wlcbs_current_build'

Here is my code:

sub set_links
{

#print "$path/wlcbs_current_build\n";
$link = "$path/wlcbs_current_build";

print "link is $link\n";

# delete link
# symbolic link information
if (-e $link)
{
print "deleting $link\n";
unlink($link);
}

# create symbolic link
symlink("$path/$max_wlcbs","$path/wlcbs_current_build") ||
die "cannot symlink $path/$min_wlcbs $path/$max_wlcbs";

# symbolic link information
if (defined($x = readlink("$path/wlcbs_current_build")))
{
print "$path/wlcbs_current_build points at '$x'\n";
}
}

Thanks!

-Joe
 
try adding a die function and see what it says:

unlink($link) or die "can't delete $link: $!";
 
Hi Kevin,

It didn't help:

>r ./
./slink.pl
link is /home/jpape/wlcbs_current_build
/home/jpape/wlcbs_current_build points at '/home/jpape/wlcbs_4'

kbs80*train-/home/jpape
>r ./
./slink.pl
link is /home/jpape/wlcbs_current_build
deleting /home/jpape/wlcbs_current_build
/home/jpape/wlcbs_current_build points at '/home/jpape/wlcbs_current_build'

kbs80*train-/home/jpape

Here is the code:

# delete link
# symbolic link information
if (-e $link)
{
print "deleting $link\n";
unlink($link) or die "can't delete $link: $!";
}

Thanks!

-Joe
 
the die function doesn't return an error message? Maybe unlink can't be used for this purpose.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top