Skip to content

Commit

Permalink
Compute File.writeable based on FileWrite instead of FileRead. (ponyl…
Browse files Browse the repository at this point in the history
…ang#2698)

* Compute File.writeable based on FileWrite

`File._descriptor(...)` was computing the `writeable` flag by checking
if the `FileRead` capability was set, rather than the `FileWrite`
capability.

* Catch "inner" errors in the writeable test.

`try ... then ... end` can mask errors and give a false positive to
tests.

* Tidy code style to comply with stdlib guidelines.

Space after : before type.
  • Loading branch information
sgebbie authored and dipinhora committed Jun 5, 2018
1 parent 4e123fe commit 25332e8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions packages/files/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ actor Main is TestList
test(_TestFileCreateExistsNotWriteable)
ifdef not windows then
test(_TestFileCreateDirNotWriteable)
test(_TestFileOpenInDirNotWriteable)
test(_TestFileOpenPermissionDenied)
end
test(_TestFileCreateMissingCaps)
Expand Down Expand Up @@ -433,6 +434,39 @@ class iso _TestFileCreateDirNotWriteable is _NonRootTest
end
end

class iso _TestFileOpenInDirNotWriteable is UnitTest
fun name(): String => "files/File.open-dir-not-writeable"
fun apply(h: TestHelper) =>
ifdef not windows then
try
// make a temporary directory
let dir_path = FilePath.mkdtemp(
h.env.root as AmbientAuth,
"tmp.open-dir-not-writeable")?
try
let dir = Directory(dir_path)?

// create a file (rw)
let created: File = dir.create_file("created")?
h.assert_true(created.valid())
h.assert_true(created.writeable)
created.dispose()

// open a file (ro)
let readonly: File = dir.open_file("created")?
h.assert_true(readonly.valid())
h.assert_false(readonly.writeable)
readonly.dispose()
else
h.fail("Unhandled inner error!")
then
dir_path.remove()
end
else
h.fail("Unhandled error!")
end
end

class iso _TestFileCreateMissingCaps is UnitTest
fun name(): String => "files/File.create-missing-caps"
fun apply(h: TestHelper) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/files/file.pony
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class File
end

path = from
writeable = from.caps(FileRead)
writeable = from.caps(FileWrite)
_fd = fd

_FileDes.set_rights(_fd, path, writeable)?
Expand Down

0 comments on commit 25332e8

Please sign in to comment.