Skip to content

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

@kiendang

Description

@kiendang
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions