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

os.write with createFolders = true does not work if perms doesn't contain executable permission #377

Open
kiendang opened this issue Mar 13, 2025 · 1 comment

Comments

@kiendang
Copy link
Contributor

os.write(
  os.pwd / "folder/out.txt",
  "asdf",
  perms = os.PermSet.fromString("rw-r--r--"),
  createFolders = true
)

would result in

java.nio.file.AccessDeniedException: .../folder/out.txt
  sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
  sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
  sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
  sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
  java.nio.file.Files.newByteChannel(Files.java:380)
  os.write$.write(ReadWriteOps.scala:65)
  os.write$.apply(ReadWriteOps.scala:78)
  ammonite.$sess.cmd9$.<clinit>(cmd9.sc:1)

because perms is also applied to os.makeDir.all

if (createFolders) makeDir.all(target / RelPath.up, perms)

and directories require executable permission to be accessible. Thus writing to a non-executable file with createFolders = true like in the example doesn't work.

This affects write.outputStream, write.append, write.append.outputStream, write.over, write.over.outputStream as well.

perms should be omitted from os.makeDir.all.

@kiendang
Copy link
Contributor Author

happy to submit a PR for this

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

No branches or pull requests

1 participant