On 10/16/23 06:54, Ralph Mellor wrote:
if not FileExists( $WanIpFileName )  {
     $WanIpFileName.IO.open(:w);
     spurt "$WanIpFileName", "New File Opened";
}

Afaik, depending on how you choose to look at things,
there's a doc error (doc for `spurt` doesn't mention that
it opens the file it's spurting to), and/or behavior due to
your Windows file system / account settings that leads
to the issue you see, and/or a bug in your code.

Let me explain. Here's what the code does:

1. Opens the file with `$WanIpFileName.IO.open(:w);`
if it doesn't already exist.

2. Opens the file with `spurt` and writes to it.

And that causes the behavior you see.

Presumably, on your system/setup, doing those two things
fails because the second open fails due to the first one.

So it succeeds the second time around because the file
already exists (though blank) and the `spurt` goes ahead.

I'd argue that the bug is ultimately in your code, perhaps
due to you not realizing that `spurt` opens the file it spurts
to, because the doc doesn't say so.

Whichever way one looks at it, there's no bug in Raku(do).

--
love, raiph


Hi Raiph,

Interesting.  Be nice if it was me.  I can fix me.
I can't fix bugs in languages.

Looking at
    https://docs.raku.org/type/IO::Path

I only find one instance of IO.open and it is an
example for "unlink"

    'foo.txt'.IO.open(:w).close;

I was using it to create a file.  I can not find
any discussion of that.

And I could find no discussion of file locks either.

    spurt "$WanIpFileName", "New File Opened";

was only added to see it I could write to the newly
created file.  Apparently, not.  And no error message
complaining about being denied access (file lock?).

Maybe I am opening a handle that is blocking
spurt from writing to the file.  It should not
matter, but apparently is does.

And if the above is the case, it is a bug in Raku.

Maybe I should have done
    $WanIpFileName.IO.open(:w).close;


What I need is what function Raku is using to support fileapi.h:
    CreateFileA function (fileapi.h)

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea

And I see that fileapi.h is also opening a handle
which probably should also be closed.

I really do not feel like writing the api call myself.

Thank you for the help,
-T

p.s.  I adore Linux's "touch" command.



Reply via email to