Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unlink does not signal failures / [JVM] .IO.unlink succeeds in unlinking empty directories #4340

Open
p6rt opened this issue Jun 23, 2015 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 23, 2015

Migrated from rt.perl.org#125463 (status was 'open')

Searchable as RT125463$

@p6rt
Copy link
Author

p6rt commented Jun 23, 2015

From @hoelzro

Unlinking a non-existent file should fail() rather than return True.

@p6rt
Copy link
Author

p6rt commented Jun 23, 2015

From @lizmat

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-archive.perl.org/perl6/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

@p6rt
Copy link
Author

p6rt commented Jun 23, 2015

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 1, 2017

From @zoffixznet

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

@p6rt
Copy link
Author

p6rt commented May 1, 2017

From @hoelzro

On 2017-05-01 01​:38​:14, cpan@​zoffix.com wrote​:

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.

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

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

@p6rt
Copy link
Author

p6rt commented May 1, 2017

From sidhekin@gmail.com

On Mon, May 1, 2017 at 6​:25 PM, Rob Hoelz via RT <
perl6-bugs-followup@​perl.org> wrote​:

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

@p6rt
Copy link
Author

p6rt commented May 1, 2017

From @zoffixznet

On Mon, 01 May 2017 10​:05​:41 -0700, sidhekin@​gmail.com wrote​:

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*

@p6rt p6rt added the IO label Jan 5, 2020
@usev6
Copy link

usev6 commented Apr 11, 2021

It looks like the issue on the JVM backend has been fixed a while ago (Raku/nqp@3921b1e6c7). As the commit message mentions there is a spectest for this behaviour:

$ mkdir foo; ./nqp-j -e 'my $foo := nqp::unlink("foo"); nqp::say($foo)'
Failed to delete file: is a directory
  in <mainline> (-e:1)
  in eval (gen/jvm/stage2/NQPHLL.nqp:1216)
  in <anon> (gen/jvm/stage2/NQPHLL.nqp:1328)
  in command_eval (gen/jvm/stage2/NQPHLL.nqp:1325)
  in command_line (gen/jvm/stage2/NQPHLL.nqp:1309)
  in MAIN (gen/jvm/stage2/NQP.nqp:4184)
  in <mainline> (gen/jvm/stage2/NQP.nqp:4180)
  in <anon> (gen/jvm/stage2/NQP.nqp)

So, this issue is only about whether unlinking a non-existent file should signal failure:
Current behaviour:

$ ./rakudo-m -e 'my $foo := "does-not-exist".IO.unlink; dd $foo'
Bool::True

Edited: I don't have the permissions to remove the reference to the solved JVM problem ([JVM] .IO.unlink succeeds in unlinking empty directories) from the issue title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants