setGroup throws: java.io.IOException: 'owner' parameter can't be a group
fanf opened this issue · 4 comments
fanf commented
Hello, we are trying to use setOwner
on a file, but we get ava.io.IOException: 'owner' parameter can't be a group
.
It's on linux, with an existing group (else we get an other exception: java.nio.file.attribute.UserPrincipalNotFoundException
).
Example reproduced case:
object Test {
def main(args: Array[String]): Unit = {
println("start")
import better.files._
val file = File("/tmp/plop")
file.createFileIfNotExists()
file.setGroup("the current user group for example")
println("done")
}
}
fanf commented
Sorry for the mixed between setOwner
and setGroup
pathikrit commented
fanf commented
Well, I expected setGroup
method to allow to set the file group
... How I'm supposed to set it with better file?
Corresponding working Java code:
object Test2 {
def main(args: Array[String]): Unit = {
println("start")
import better.files._
val file = File("/tmp/plop")
file.createFileIfNotExists()
val group = java.nio.file.FileSystems.getDefault.getUserPrincipalLookupService.lookupPrincipalByGroupName("1000")
java.nio.file.Files.getFileAttributeView(file.path, classOf[java.nio.file.attribute.PosixFileAttributeView], java.nio.file.LinkOption.NOFOLLOW_LINKS).setGroup(group)
println("done")
}
}
pathikrit commented
@fanf : Thanks for the clarification. I see what you mean. I think there is bug on this line then since I use setOwner
: https://github.com/pathikrit/better-files/blob/master/core/src/main/scala/better/files/File.scala#L948