Skip Menu |
Report information
Id: 125463
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: rob [at] hoelz.ro
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: $non-existent-file.IO.unlink returns True
Unlinking a non-existent file should fail() rather than return True.
To: "Rob Hoelz (via RT)" <perl6-bugs-followup [...] perl.org>
Subject: Re: [perl #125463] $non-existent-file.IO.unlink returns True
From: Elizabeth Mattijsen <liz [...] dijkmat.nl>
Date: Tue, 23 Jun 2015 16:17:59 +0200
Download (untitled) / with headers
text/plain 768b
Show quoted text
> On 23 Jun 2015, at 15:37, Rob Hoelz (via RT) <perl6-bugs-followup@perl.org> wrote: > > # New Ticket Created by Rob Hoelz > # Please include the string: [perl #125463] > # in the subject line of all future correspondence about this issue. > # <URL: https://rt.perl.org/Ticket/Display.html?id=125463 > > > > Unlinking a non-existent file should fail() rather than return True.
To expand on this: it appears that on MoarVM nqp::unlink returns the filename regardless of whether successful or not. On the JVM, it appears to return 0 for success, and -2 for non-existing file, and throws an exception if it could not remove the file for some reason. It also seems capable of removing empty directories on the JVM (on MoarVM it fails with an exception). Liz
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 581b
Show quoted text
> On 23 Jun 2015, at 15:37, Rob Hoelz (via RT) <perl6-bugs- > followup@perl.org> wrote: > Unlinking a non-existent file should fail() rather than return True.
The end-goal of .unlinking stuff is for the file to stop existing. IMO that goal is achieved even if the method is called for non-existent files, so there's no failure to fail with. Also, this behaviour mirrors what Perl 5 does, if I recall. I'm going to untake this ticket (as far as IO grant is concerned) and re-tag is as JVM-only issue in need to remove ability of removing directories from this method. -- IO grant
Download (untitled) / with headers
text/plain 1.6k
On 2017-05-01 01:38:14, cpan@zoffix.com wrote: Show quoted text
> > On 23 Jun 2015, at 15:37, Rob Hoelz (via RT) <perl6-bugs- > > followup@perl.org> wrote: > > Unlinking a non-existent file should fail() rather than return True.
> > The end-goal of .unlinking stuff is for the file to stop existing. > IMO that goal is achieved even if the method is called for non- > existent files, > so there's no failure to fail with.
Maybe I'm thinking too Unix-centric with this, but since unlink(2) raises ENOENT when the entry doesn't exist, I think Perl 6 implementations should reflect that behavior. A quick example for why failing on a non-existent file should be done is let's say I'm writing data to a file and I want to clean it up after I'm done working with it. If I create a bug that mistakenly alters the filename, a non-failing unlink will silently succeed, but I will *think* the file has been cleaned up. This behavior has the potential to retain sensitive data, can go undetected for a long time, and would be non-obvious to track down. Not every program needs this behavior, but Perl 6 has an "error by default" policy and facilities for suppressing these errors, so I think we should still treat unlinking a non-existent file as a failure. Show quoted text
> Also, this behaviour mirrors what > Perl 5 does, > if I recall.
Perl 5 signals failure when the file doesn't exist: $ touch one $ perl -le 'print unlink("one") ? 1 : 0' 1 $ perl -le 'print unlink("one") ? 1 : 0' 0 Show quoted text
> > I'm going to untake this ticket (as far as IO grant is concerned) and > re-tag > is as JVM-only issue in need to remove ability of removing directories > from > this method. > > -- IO grant
Subject: Re: [perl #125463] [JVM] .IO.unlink succeeds in unlinking empty directories
From: The Sidhekin <sidhekin [...] gmail.com>
To: perl6-bugs-followup [...] perl.org
Date: Mon, 1 May 2017 19:04:57 +0200
Download (untitled) / with headers
text/plain 592b
On Mon, May 1, 2017 at 6:25 PM, Rob Hoelz via RT <perl6-bugs-followup@perl.org> wrote:
Show quoted text
Perl 5 signals failure when the file doesn't exist:

  $ touch one
  $ perl -le 'print unlink("one") ? 1 : 0'
  1
  $ perl -le 'print unlink("one") ? 1 : 0'
  0

  Not exactly.  Perl5 unlink is documented to return the number of files "successfully deleted".  Which may be non-zero even if some file doesn't exist:

$ touch one; touch two
$ perl -le 'print unlink("one", "two") ? 1 : 0'
1
$ touch one;
$ perl -le 'print unlink("one", "two") ? 1 : 0'
1

  No failure signalled …


Eirik
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 364b
On Mon, 01 May 2017 10:05:41 -0700, sidhekin@gmail.com wrote: Show quoted text
> No failure signalled …
It rudimentary way it is; you can still write: `die "Some failure" unless @files == unlink @files` In Perl 6 it doesn't, and I see our &unlink even returns the full original list of files, despite some non-existing, which is certainly LTA. *clicks "Take" button again*


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org