Skip to content

Commit

Permalink
Merge pull request #9959 from som-snytt/issue/4781
Browse files Browse the repository at this point in the history
Check for windows device names
  • Loading branch information
lrytz committed Apr 19, 2022
2 parents 0b1e3f5 + 69c8c81 commit 90c820f
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,18 @@ abstract class ClassfileWriters {
val noAttributes = Array.empty[FileAttribute[_]]
private val isWindows = scala.util.Properties.isWin

private def checkName(component: Path): Unit = if (isWindows) {
val specials = raw"(?i)CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9]".r
val name = component.toString
def warnSpecial(): Unit = frontendAccess.backendReporting.warning(NoPosition, s"path component is special Windows device: ${name}")
specials.findPrefixOf(name).foreach(prefix => if (prefix.length == name.length || name(prefix.length) == '.') warnSpecial())
}

def ensureDirForPath(baseDir: Path, filePath: Path): Unit = {
import java.lang.Boolean.TRUE
val parent = filePath.getParent
if (!builtPaths.containsKey(parent)) {
parent.iterator.forEachRemaining(checkName)
try Files.createDirectories(parent, noAttributes: _*)
catch {
case e: FileAlreadyExistsException =>
Expand All @@ -257,6 +265,7 @@ abstract class ClassfileWriters {
current = current.getParent
}
}
checkName(filePath.getFileName())
}

// the common case is that we are are creating a new file, and on MS Windows the create and truncate is expensive
Expand Down

0 comments on commit 90c820f

Please sign in to comment.