develooper Front page | perl.perl6.users | Postings from November 2022

How in Raku can a symlink be edited to a new target, if the targetis a directory.

Thread Next
From:
Richard Hainsworth
Date:
November 7, 2022 09:55
Subject:
How in Raku can a symlink be edited to a new target, if the targetis a directory.
Message ID:
736992f4-a21a-2b74-d850-f57e5999d7ce@gmail.com
I want - in a Raku program - update a symlink from 'plug-v1' to 
'plug-v2', where both plug-v1 and plug-v2 are sub-directories of 'src'. 
The symlink is 'plug'.

I am using Ubuntu.

First time I create symlink with

'src/plug-v1'.IO.symlink( 'plug' );

If now I want to change the link, then the following

'src/plug-v2'.IO.symlink( 'plug' );

causes the error:

Failed to symlink file: file already exists

This is understandable.

So then I tried

'plug'.IO.unlink if 'plug'.IO ~~ :e;

'src/plug-v2'.IO.symlink( 'plug' );

This seems to work in a test file in which I create the directories then 
symlink and unlink.

However, when I try this sequence in a Raku script on a symlink that 
exists before the program runs, I get the error

Failed to delete file: illegal operation on a directory in block <unit> 
at test.raku line 18

where line 18 corresponds to the " 'plug'.IO.unlink " statement.

Looking at the documentation for "*nix", I see that in some flavours of 
Unix, 'unlink' deletes a directory, rather than removing a symlink. I 
can see therefore that since 'plug' is a symlink to a directory, Raku is 
forbidding the operation.

There are some options to unlink that seem to get round this problem, 
but those options do not seem to exist (or are not documented) in Raku.

How do I achieve programatically in Raku an edit of a symlink to a new 
target, if the target is a directory.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About