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

Change directory.open_file() to use readonly open #2697

Merged
merged 3 commits into from
May 16, 2018

Conversation

sgebbie
Copy link
Contributor

@sgebbie sgebbie commented May 11, 2018

On non-Linux and non-BSD platforms the direction.open_file() logic
defaults to a named path base open, rather than using openat calls.

However, this was using the File.create(...) call which opens files
for read/write, rather than just readonly. This in turn fails since
the FileWrite capability is explicitly dropped.

This commit simply switches to using File.open(...) which opens the
file in a readonly mode.

This fixes: #2695

On non-Linux and non-BSD platforms the direction.open_file() logic
defaults to a named path base open, rather than using `openat` calls.

However, this was using the `File.create(...)` call which opens files
for read/write, rather than just readonly. This in turn fails since
the `FileWrite` capability is explicitly dropped.

This commit simply switches to using `File.open(...)` which opens the
file in a readonly mode.

This fixes: ponylang#2695
@jemc
Copy link
Member

jemc commented May 11, 2018

Is there a test that can be added to protect against regression, (a test which would fail on OSX CI without this change)?

@mfelsche mfelsche added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label May 12, 2018
@sgebbie
Copy link
Contributor Author

sgebbie commented May 12, 2018

Sure, no problem, I will add a unit test.

Note, care needs to be taken not the mask the `error` in a:

```
try
  ...
then
  ...
end
```

that does not have an `else` block.
@sgebbie
Copy link
Contributor Author

sgebbie commented May 14, 2018

I've added an extra unit test for the Directory.open_file case.

@mfelsche
Copy link
Contributor

Awesome!

FYI: I've created tests after this pattern too and just found out about: https://stdlib.ponylang.org/ponytest--index#tear-down which makes state setup and tear_down much easier and the test-code itself more clean.

created.dispose()

// open a file (ro)
let readonly:File = dir.open_file("created")?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For compliance with the standard library style guide, can you add a space here after the :?

Same comment for line 154 above.

Space between : and type.
@sgebbie
Copy link
Contributor Author

sgebbie commented May 15, 2018

@jemc I've submitted the style guide related tweak. Please let me know if this was what you meant?

Thanks,
Stewart.

@jemc
Copy link
Member

jemc commented May 15, 2018

Yeah, that's what I meant - I didn't merge yet because I wasn't sure if @mfelsche wanted to see the refactor to use tear_down instead of nested try blocks first.

@mfelsche
Copy link
Contributor

@jemc @sgebbie no, it is fine as is. I am working on some other part of the files package and might refactor the whole test suite in one go in another PR.

Lets get this rollin'!

@jemc jemc merged commit db07285 into ponylang:master May 16, 2018
ponylang-main added a commit that referenced this pull request May 16, 2018
@sgebbie sgebbie deleted the directory-open-readonly branch May 16, 2018 20:30
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
* Change directory.open_file() to use readonly open

On non-Linux and non-BSD platforms the direction.open_file() logic
defaults to a named path base open, rather than using `openat` calls.

However, this was using the `File.create(...)` call which opens files
for read/write, rather than just readonly. This in turn fails since
the `FileWrite` capability is explicitly dropped.

This commit simply switches to using `File.open(...)` which opens the
file in a readonly mode.

This fixes: ponylang#2695

* Introduce a unit test Directory.open_file

Note, care needs to be taken not the mask the `error` in a:

```
try
  ...
then
  ...
end
```

that does not have an `else` block.

* Tweak to match stdlib style guide.

Space between : and type.
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

directory.open_file fail on OS X
3 participants