Skip to content

Commit 5994428

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

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-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

+28
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,34 @@ 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/recipes/building_blocks/waxed_weathered_chiseled_copper_from_waxed_weathered_cut_copper_stonecutting.json"
354+
355+
fun testPathLength(projectLayout: ProjectLayout) {
356+
if (System.getProperty("os.name").lowercase().contains("win")) {
357+
val tmpProjDir = projectLayout.projectDirectory.path.resolveSibling(
358+
projectLayout.projectDirectory.path.name + "_"
359+
)
360+
val cache = tmpProjDir.resolve(".gradle/$CACHE_PATH")
361+
val testFile = cache.resolve(longestPath)
362+
363+
try {
364+
testFile.parent.createDirectories()
365+
testFile.writeText("test")
366+
} catch (e: Exception) {
367+
throw PaperweightException(
368+
"The directory this project is cloned in is too nested. Either enable long paths in Windows and Git, or use WSL.\n" +
369+
"Windows documentation: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry\n" +
370+
"Git command: git config --global core.longpaths true",
371+
e
372+
)
373+
} finally {
374+
tmpProjDir.deleteRecursive()
375+
}
376+
}
377+
}
378+
351379
private fun javaVersion(): Int {
352380
val version = System.getProperty("java.specification.version")
353381
val parts = version.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()

0 commit comments

Comments
 (0)