Skip to content

Commit

Permalink
[GR-49849] Remove internal resource TruffleFile workaround
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4051
  • Loading branch information
eregon committed Nov 7, 2023
2 parents fe12e7f + 239acde commit 9eaa9df
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/main/java/org/truffleruby/language/loader/FileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,21 @@ public static TruffleFile getSafeTruffleFile(RubyLanguage language, RubyContext
context.getCoreExceptions().loadError("Failed to canonicalize -- " + path, path, null));
}

String homeLibDir = language.getRubyHome() + "/lib/";
if (file.getPath().startsWith(homeLibDir)) {
String homeRelativePath = file.getPath().substring(language.getRubyHome().length() + 1);
TruffleFile internalResourceFile = language.getRubyHomeTruffleFile().resolve(homeRelativePath);
if (isStdLibRubyOrCExtFile(internalResourceFile.getPath())) {
return internalResourceFile;
final TruffleFile home = language.getRubyHomeTruffleFile();
if (file.startsWith(home.resolve("lib")) && isStdLibRubyOrCExtFile(file.getPath())) {
return file;
} else {
try {
return env.getPublicTruffleFile(path);
} catch (SecurityException e) {
throw new RaiseException(
context,
context.getCoreExceptions().loadError(
"Permission denied (" + e.getMessage() + ") -- " + path,
path,
null));
}
}

try {
return env.getPublicTruffleFile(path);
} catch (SecurityException e) {
throw new RaiseException(
context,
context.getCoreExceptions().loadError(
"Permission denied (" + e.getMessage() + ") -- " + path,
path,
null));
}
}

private static boolean isStdLibRubyOrCExtFile(String path) {
Expand Down

0 comments on commit 9eaa9df

Please sign in to comment.