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 doesn't complain if it tries to operate on a file that doesn't exist #2096

Closed
briandfoy opened this issue Jun 11, 2018 · 12 comments
Closed
Assignees

Comments

@briandfoy
Copy link
Contributor

briandfoy commented Jun 11, 2018

I don't know if unlink should succeed or not for a file that doesn't exist. I would expect it to fail but if it doesn't I'm not bothered. Whatever the answer it would be nice to see it noted in the docs.

Here's what I was doing on 2018.04:

my @files = <a.txt b.txt c.txt d.txt e.txt /etc/hosts>;
say 'Exists: ', @files.grep: *.IO.e;

my @unlinked-files = unlink @files;
say 'All: ', @files;
say 'Removed: ', @unlinked-files;

my @error-files = @files.Set (-) @unlinked-files.Set;

say 'Problems: ', @error-files;

And some output:

Exists: (a.txt b.txt c.txt /etc/hosts)
All: [a.txt b.txt c.txt d.txt e.txt /etc/hosts]
Removed: [a.txt b.txt c.txt d.txt e.txt]
Problems: [set(/etc/hosts)]
@rafaelschipiura
Copy link
Contributor

It copies the way Perl 5 does it and it in turns copies the way it's done in C.

Don't know if there is a motive for it being that way, but I think the documentation should certainly have a note about it.

@briandfoy
Copy link
Contributor Author

Perl 5's unlink returns a count and doesn't count the files that were missing.

@JJ JJ closed this as completed in 46e94bc Jun 12, 2018
@JJ
Copy link
Contributor

JJ commented Jun 12, 2018

Unlink behaves exactly as indicated in the documentation, which I have only clarified a little bit. It fails if you call it as a method, it returns an array as it does in your example above if called as a subroutine. If you want a count of the number of files, call .elems on the result.

@briandfoy
Copy link
Contributor Author

briandfoy commented Jun 12, 2018

None of those statements address the original issue and the documentation is still unclear and incomplete on the original issue. Why was this closed without resolution?

@JJ
Copy link
Contributor

JJ commented Jun 12, 2018

Let's see:

I don't know if unlink should succeed or not for a file that doesn't exist.

The documents don't know either. However. they say:

The subroutine form returns the names of the files that were successfully deleted. The method form returns True on success, or fails with X::IO::Unlink if the operation could not be completed.

So it clearly says:

  • It succeeds if called as a subroutine, no matter what.
  • it fails on with a particular exception if it can't delete a file, only if called as a method.

I would expect it to fail but it it doesn't matter I'm not bothered.

That's OK. It fails, or not, depending on how you call it, but since you're not bothered either way, I guess that's properly addressed.

Whatever the answer it would be nice to see it noted in the docs.

It is in the docs exactly as above, and it's been there for 3 years already. Only change has been to specify that only those files that can be deleted are actually deleted. No surprise there.

Perl 5's unlink returns a count and doesn't count the files that were missing.

Right. Perl 6 works exactly as you noted in your example, which matches exactly what has been in the documentation for 3 years.

None of those statements address the original issue and the documentation is still unclear and incomplete on the original issue. Why was this closed without resolution?

The behavior you noted is as expected, it's documented in a precise way, I revised the documentation, made a small precision, and made the call to close this issue, since it's, as explained above, well, a non-issue. We thank you for the report, that help us improve the documentation, even in little ways, and feel free to open any more issues on anything you consider necessary; just not this one. 👍

@briandfoy
Copy link
Contributor Author

I don't appreciate your attitude here. I'll refrain from further participation.

@JJ
Copy link
Contributor

JJ commented Jun 12, 2018

What do you mean exactly by "my attitude" here?

@zoffixznet zoffixznet self-assigned this Jun 12, 2018
zoffixznet added a commit that referenced this issue Jun 12, 2018
@JJ
Copy link
Contributor

JJ commented Jun 12, 2018

OK, I get it now after @zoffixznet 's patch and @rafaelschipiura explanations in the IRC channel. All the *.txt files did not exist to start with. So the documentation was actually wrong because it returned those files deleted and those that didn't exist. I don't know if that behavior is exactly as intended, and I'm sorry for, I guess my attitude. I guess the patch makes it clear now, and again my apologies.

@zoffixznet
Copy link
Contributor

since you're not bothered either way, I guess that's properly addressed

In the future, a simple "Which portion needs further clarification?" would go a longer way, IMO.

JJ added a commit that referenced this issue Jun 12, 2018
Also some possible explanation of the rationale of including
non-existing files in the output list. Refs #2096, does not close,
because it's been closed already. Thanks again @briandfoy for the
report, and sorry for not understanding the problem from the beginning.
@JJ
Copy link
Contributor

JJ commented Jun 12, 2018 via email

@rafaelschipiura
Copy link
Contributor

@briandfoy I'm not liking your attitude here. He already apologized for the misunderstanding, stop stalking him if you are not going to engage in a constructive manner.

@labster
Copy link
Contributor

labster commented Jun 12, 2018

I would expect it to fail but if it doesn't I'm not bothered.

since you're not bothered either way, I guess that's properly addressed

sigh

@Raku Raku locked as resolved and limited conversation to collaborators Jun 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants