Skip to content

Commit 1e2bbe6

Browse files
authored
Fix os.write.outputStream with perms for Scala 3 (com-lihaoyi#368)
On Scala 3 ```scala os.write.outputStream(os.pwd / "text", perms = os.PermSet(420)) java.lang.ClassCastException: class [Ljava.nio.file.attribute.FileAttribute; cannot be cast to class scala.collection.immutable.Seq ([Ljava.nio.file.attribute.FileAttribute; is in module java.base of loader 'bootstrap'; scala.collection.immutable.Seq is in unnamed module of loader java.net.URLClassLoader @4520ebad) os.write$.outputStream(ReadWriteOps.scala:35) ammonite.$sess.cmd0$.<clinit>(cmd0.sc:1) ```
1 parent 36e00e0 commit 1e2bbe6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

os/src/ReadWriteOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ object write {
3030
checker.value.onWrite(target)
3131
if (createFolders) makeDir.all(target / RelPath.up, perms)
3232
if (perms != null && !exists(target)) {
33-
val permArray =
34-
if (perms == null) Array[FileAttribute[PosixFilePermission]]()
33+
val permArray: Array[FileAttribute[_]] =
34+
if (perms == null) Array.empty
3535
else Array(PosixFilePermissions.asFileAttribute(perms.toSet()))
3636
java.nio.file.Files.createFile(target.toNIO, permArray: _*)
3737
}

os/test/src/ReadingWritingTests.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ object ReadingWritingTests extends TestSuite {
124124
os.read(wd / "New File.txt") ==> "Hello"
125125
}
126126
}
127+
test("outputStreamWithPerms") {
128+
test - prep { wd =>
129+
if (!scala.util.Properties.isWin) {
130+
val out = os.write.outputStream(wd / "New File.txt", perms = os.PermSet(420))
131+
out.write('H')
132+
out.write('e')
133+
out.write('l')
134+
out.write('l')
135+
out.write('o')
136+
out.close()
137+
138+
os.read(wd / "New File.txt") ==> "Hello"
139+
}
140+
}
141+
}
127142
}
128143
test("truncate") {
129144
test - prep { wd =>

0 commit comments

Comments
 (0)