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

setGroup throws: java.io.IOException: 'owner' parameter can't be a group #332

Closed
fanf opened this issue Aug 13, 2019 · 4 comments
Closed
Labels

Comments

@fanf
Copy link
Contributor

fanf commented Aug 13, 2019

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 fanf changed the title setOwner throws: java.io.IOException: 'owner' parameter can't be a group setGroup throws: java.io.IOException: 'owner' parameter can't be a group Aug 13, 2019
@fanf
Copy link
Contributor Author

fanf commented Aug 13, 2019

Sorry for the mixed between setOwner and setGroup

@pathikrit
Copy link
Owner

Your exception says owner parameter can't be a group but you are setting the group in your example e.g.

image

I don't see why that would work - that exception makes sense IMO. Do you have a working example using plain Java code that works that fails in better-files?

@fanf
Copy link
Contributor Author

fanf commented Aug 22, 2019

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
Copy link
Owner

@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

@pathikrit pathikrit reopened this Aug 22, 2019
@pathikrit pathikrit added bug and removed question labels Aug 22, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants