Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.fabricmc.loom.task.LoomTasks;
import net.fabricmc.loom.task.RemapTaskConfiguration;
import net.fabricmc.loom.util.LibraryLocationLogger;
import net.fabricmc.loom.util.OneDrive;

public class LoomGradlePlugin implements Plugin<PluginAware> {
public static final String NAME = "fabric-loom";
Expand Down Expand Up @@ -81,6 +82,7 @@ private void apply(Project project) {
project.getLogger().lifecycle("Fabric Loom: " + LOOM_VERSION);

LibraryLocationLogger.logLibraryVersions();
OneDrive.verify(project);

// Apply default plugins
project.apply(Map.of("plugin", "java-library"));
Expand Down
97 changes: 97 additions & 0 deletions src/main/java/net/fabricmc/loom/util/OneDrive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2025 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package net.fabricmc.loom.util;

import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

import org.gradle.api.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// OneDrive causes all kinds of issues, log a warning if the users project is stored there.
public final class OneDrive {
private static final List<String> ENV_VARS = List.of("OneDrive", "OneDriveConsumer", "OneDriveCommercial");
private static final Supplier<List<Path>> ONE_DRIVE_PATHS = Lazy.of(OneDrive::getOneDrivePaths);
private static final Logger LOGGER = LoggerFactory.getLogger(OneDrive.class);

private OneDrive() {
}

public static void verify(Project project) {
if (!Platform.CURRENT.getOperatingSystem().isWindows()) {
return;
}

Path projectDir = project.getProjectDir().toPath();

if (isInOneDrive(projectDir)) {
LOGGER.warn("Project directory '{}' is located in OneDrive. This is known to cause issues and slower performance. Consider moving the project to a different location.", projectDir);
}
}

private static boolean isInOneDrive(Path path) {
Path normalized = path.toAbsolutePath().normalize();

for (Path oneDrivePath : ONE_DRIVE_PATHS.get()) {
if (normalized.startsWith(oneDrivePath)) {
return true;
}
}

return false;
}

private static List<Path> getOneDrivePaths() {
var paths = new ArrayList<Path>();

for (String envVar : ENV_VARS) {
String value = System.getenv(envVar);

if (value == null || value.isEmpty()) {
continue;
}

try {
Path path = Path.of(value);

if (Files.notExists(path)) {
continue;
}

paths.add(path.toAbsolutePath().normalize());
} catch (InvalidPathException ignored) {
// Don't care
}
}

return Collections.unmodifiableList(paths);
}
}
Loading