Skip to content

Commit 9eaa9df

Browse files
committed
[GR-49849] Remove internal resource TruffleFile workaround
PullRequest: truffleruby/4051
2 parents fe12e7f + 239acde commit 9eaa9df

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/main/java/org/truffleruby/language/loader/FileLoader.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,21 @@ public static TruffleFile getSafeTruffleFile(RubyLanguage language, RubyContext
9090
context.getCoreExceptions().loadError("Failed to canonicalize -- " + path, path, null));
9191
}
9292

93-
String homeLibDir = language.getRubyHome() + "/lib/";
94-
if (file.getPath().startsWith(homeLibDir)) {
95-
String homeRelativePath = file.getPath().substring(language.getRubyHome().length() + 1);
96-
TruffleFile internalResourceFile = language.getRubyHomeTruffleFile().resolve(homeRelativePath);
97-
if (isStdLibRubyOrCExtFile(internalResourceFile.getPath())) {
98-
return internalResourceFile;
93+
final TruffleFile home = language.getRubyHomeTruffleFile();
94+
if (file.startsWith(home.resolve("lib")) && isStdLibRubyOrCExtFile(file.getPath())) {
95+
return file;
96+
} else {
97+
try {
98+
return env.getPublicTruffleFile(path);
99+
} catch (SecurityException e) {
100+
throw new RaiseException(
101+
context,
102+
context.getCoreExceptions().loadError(
103+
"Permission denied (" + e.getMessage() + ") -- " + path,
104+
path,
105+
null));
99106
}
100107
}
101-
102-
try {
103-
return env.getPublicTruffleFile(path);
104-
} catch (SecurityException e) {
105-
throw new RaiseException(
106-
context,
107-
context.getCoreExceptions().loadError(
108-
"Permission denied (" + e.getMessage() + ") -- " + path,
109-
path,
110-
null));
111-
}
112108
}
113109

114110
private static boolean isStdLibRubyOrCExtFile(String path) {

0 commit comments

Comments
 (0)