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

Improve error on conflict with Windows device names #9959

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,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())
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is windows but could still use a test. I think the request was always to warn, but almost everything is distributed via jar or zip. Unzip at your own risk.

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 @@ -254,6 +262,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