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

Add extension update folder #4929

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,68 @@ protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) {
Map<String, GeyserExtensionContainer> loadedExtensions = new LinkedHashMap<>();

Pattern[] extensionFilters = this.extensionFilters();
List<Path> extensionPaths = Files.walk(extensionsDirectory).toList();

Path updateDirectory = extensionsDirectory.resolve("update");
List<Path> extensionPaths;
if (Files.isDirectory(updateDirectory)) {
// Get the current extensions and store them in a map
rtm516 marked this conversation as resolved.
Show resolved Hide resolved
Map<String, Path> extensionFiles = new HashMap<>();
extensionPaths = Files.list(extensionsDirectory).toList();
extensionPaths.forEach(path -> {
if (Files.isDirectory(path)) {
return;
}

// Only look at files that meet the extension filter
for (Pattern filter : extensionFilters) {
if (!filter.matcher(path.getFileName().toString()).matches()) {
return;
}
}

try {
// Try load the description, so we know it's a valid extension
GeyserExtensionDescription description = this.extensionDescription(path);
rtm516 marked this conversation as resolved.
Show resolved Hide resolved

// Store the file name against ID for later use
rtm516 marked this conversation as resolved.
Show resolved Hide resolved
extensionFiles.put(description.id(), path);
} catch (Throwable e) {
// no-op
rtm516 marked this conversation as resolved.
Show resolved Hide resolved
}
});

// Perform the updates
rtm516 marked this conversation as resolved.
Show resolved Hide resolved
List<Path> extensionUpdatePaths = Files.list(updateDirectory).toList();
extensionUpdatePaths.forEach(path -> {
if (Files.isDirectory(path)) {
return;
}

// Only look at files that meet the extension filter
for (Pattern filter : extensionFilters) {
if (!filter.matcher(path.getFileName().toString()).matches()) {
return;
}
}

try {
// Try load the description, so we know it's a valid extension
GeyserExtensionDescription description = this.extensionDescription(path);

// Remove the old extension with the same ID if it exists
if (extensionFiles.containsKey(description.id())) {
Files.delete(extensionFiles.get(description.id()));
}
rtm516 marked this conversation as resolved.
Show resolved Hide resolved

// Overwrite the extension with the new jar
Files.move(path, extensionsDirectory.resolve(path.getFileName()), StandardCopyOption.REPLACE_EXISTING);
rtm516 marked this conversation as resolved.
Show resolved Hide resolved
} catch (Throwable e) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.update.failed", path.getFileName()), e);
}
});
}

extensionPaths = Files.list(extensionsDirectory).toList();
extensionPaths.forEach(path -> {
if (Files.isDirectory(path)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/languages