Ignore this message.
It turns out I had set up my file structure incorrectly, so the
description below is wrong and the problem is elsewhere. Raku handles a
symlink to a directory correctly.
On 07/11/2022 9:55 am, Richard Hainsworth wrote:
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.