-
Notifications
You must be signed in to change notification settings - Fork 34
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
Dont raise NotFoundError when deleting file #849
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or can we monkey patch stdlid with a delete!
or something that delete if exists otherwise just return.
Just see some repetition here
True. It's MFiles in this case, so I can just add a method to it. |
That will actaully be much better. Rescuing like I'm doing now means that |
Also, use Crystals abstraction around LibC.unlink
Did another take. I think this is better. |
raise File::Error.from_errno("Error deleting file", file: @path) if code < 0 | ||
def delete(*, raise_on_missing = true) : self | ||
if raise_on_missing | ||
File.delete(@path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enlighten me: We go from libc.unlink
to File.delete
are they the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File.delete
(public API) is using Crystal::System::File.delete
(non-public API) which will use platform dependent calls. On unix it will be LibC.unlink
. Now MFile
doesn't work on anything else than *nix, but I think it's nice to use public APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha ok, thanks for the explanation
WHAT is this pull request doing?
I see no point in raising
FileNotFound
when trying to delete a file.One way of triggering the exception:
HOW can this pull request be tested?
See steps above.