Skip to content

Commit a1c260a

Browse files
committed
Check for long paths on Windows
1 parent 21f771d commit a1c260a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/project-util.kt

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ fun Project.setupServerProject(
5050
packagesToFix: Provider<List<String>?>,
5151
reobfMappings: Provider<RegularFile>,
5252
): ServerTasks? {
53+
testPathLength(layout)
54+
5355
if (!projectDir.exists()) {
5456
return null
5557
}

paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt

+29
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,35 @@ fun FileCollection.toJarClassProviderRoots(): List<ClassProviderRoot> = files.as
348348
.map { p -> ClassProviderRoot.fromJar(p) }
349349
.toList()
350350

351+
// Longest path as of 1.20.4
352+
private const val longestPath: String =
353+
"paperweight/mc-dev-sources/data/minecraft/datapacks/update_1_21/data/minecraft/advancements/" +
354+
"recipes/building_blocks/waxed_weathered_chiseled_copper_from_waxed_weathered_cut_copper_stonecutting.json"
355+
356+
fun testPathLength(projectLayout: ProjectLayout) {
357+
if (System.getProperty("os.name").lowercase().contains("win")) {
358+
val tmpProjDir = projectLayout.projectDirectory.path.resolveSibling(
359+
projectLayout.projectDirectory.path.name + "_"
360+
)
361+
val cache = tmpProjDir.resolve(".gradle/$CACHE_PATH")
362+
val testFile = cache.resolve(longestPath)
363+
364+
try {
365+
testFile.parent.createDirectories()
366+
testFile.writeText("test")
367+
} catch (e: Exception) {
368+
throw PaperweightException(
369+
"The directory this project is cloned in is too nested. Either enable long paths in Windows and Git, or use WSL.\n" +
370+
"Windows documentation: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry\n" +
371+
"Git command: git config --global core.longpaths true",
372+
e
373+
)
374+
} finally {
375+
tmpProjDir.deleteRecursive()
376+
}
377+
}
378+
}
379+
351380
private fun javaVersion(): Int {
352381
val version = System.getProperty("java.specification.version")
353382
val parts = version.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()

0 commit comments

Comments
 (0)