Skip to content

Commit 8622810

Browse files
committed
Update comment on read-only directories
1 parent a26d796 commit 8622810

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/main/kotlin/com/coder/gateway/sdk/PathExtensions.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ import java.nio.file.Path
1010
* Unlike File.canWrite() or Files.isWritable() the directory does not need to
1111
* exist; it only needs a writable parent and the target needs to be
1212
* non-existent or a directory (not a regular file or nested under one).
13-
*
14-
* This check is deficient on Windows since directories that have write
15-
* permissions but are read-only will still return true.
1613
*/
1714
fun Path.canCreateDirectory(): Boolean {
1815
var current: Path? = this.toAbsolutePath()
1916
while (current != null && !Files.exists(current)) {
2017
current = current.parent
2118
}
2219
// On Windows File.canWrite() only checks read-only while Files.isWritable()
23-
// also checks permissions. For directories neither of them seem to care if
24-
// it is read-only.
20+
// also checks permissions so use the latter. Both only check read-only on
21+
// files, not directories; on Windows you are allowed to create files inside
22+
// read-only directories.
2523
return current != null && Files.isWritable(current) && Files.isDirectory(current)
2624
}

0 commit comments

Comments
 (0)