private FoundLibrary findFileResourceWithLoadPath(String searchName, String suffix, String loadPath) { String fullPath = loadPath != null ? loadPath + "/" + searchName : searchName; String pathWithSuffix = fullPath + suffix; DebugLog.Resource.logTry(pathWithSuffix); FileResource resource = JRubyFile.createResourceAsFile(runtime, pathWithSuffix); if (resource.exists()) { if (resource.absolutePath() != resource.canonicalPath()) { FileResource expandedResource = JRubyFile.createResourceAsFile(runtime, resource.canonicalPath()); if (expandedResource.exists()){ String scriptName = resolveScriptName(expandedResource, expandedResource.canonicalPath()); String loadName = resolveLoadName(expandedResource, searchName + suffix); return new FoundLibrary(ResourceLibrary.create(searchName, scriptName, resource), loadName); } } DebugLog.Resource.logFound(pathWithSuffix); String scriptName = resolveScriptName(resource, pathWithSuffix); String loadName = resolveLoadName(resource, searchName + suffix); return new FoundLibrary(ResourceLibrary.create(searchName, scriptName, resource), loadName); } return null; }
private FoundLibrary findFileResourceWithLoadPath(String searchName, String suffix, String loadPath) { String fullPath = loadPath != null ? loadPath + "/" + searchName : searchName; String pathWithSuffix = fullPath + suffix; DebugLog.Resource.logTry(pathWithSuffix); FileResource resource = JRubyFile.createResourceAsFile(runtime, pathWithSuffix); if (resource.exists()) { if (resource.absolutePath() != resource.canonicalPath()) { FileResource expandedResource = JRubyFile.createResourceAsFile(runtime, resource.canonicalPath()); if (expandedResource.exists()){ String scriptName = resolveScriptName(expandedResource, expandedResource.canonicalPath()); String loadName = resolveLoadName(expandedResource, searchName + suffix); return new FoundLibrary(ResourceLibrary.create(searchName, scriptName, resource), loadName); } } DebugLog.Resource.logFound(pathWithSuffix); String scriptName = resolveScriptName(resource, pathWithSuffix); String loadName = resolveLoadName(resource, searchName + suffix); return new FoundLibrary(ResourceLibrary.create(searchName, scriptName, resource), loadName); } return null; }
/** Changes the current directory to <code>path</code> */ @JRubyMethod(optional = 1, meta = true) public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; RubyString path = args.length == 1 ? StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])) : getHomeDirectoryPath(context); String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null); checkDirIsTwoSlashesOnWindows(runtime, adjustedPath); adjustedPath = getExistingDir(runtime, adjustedPath).canonicalPath(); IRubyObject result; if (block.isGiven()) { final String oldCwd = runtime.getCurrentDirectory(); // FIXME: Don't allow multiple threads to do this at once runtime.setCurrentDirectory(adjustedPath); try { result = block.yield(context, path); } finally { getExistingDir(runtime, oldCwd); // needed in case the block deleted the oldCwd runtime.setCurrentDirectory(oldCwd); } } else { runtime.setCurrentDirectory(adjustedPath); result = runtime.newFixnum(0); } return result; }
/** Changes the current directory to <code>path</code> */ @JRubyMethod(optional = 1, meta = true) public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) { Ruby runtime = context.runtime; RubyString path = args.length == 1 ? StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, args[0])) : getHomeDirectoryPath(context); String adjustedPath = RubyFile.adjustRootPathOnWindows(runtime, path.asJavaString(), null); checkDirIsTwoSlashesOnWindows(runtime, adjustedPath); adjustedPath = getExistingDir(runtime, adjustedPath).canonicalPath(); IRubyObject result; if (block.isGiven()) { final String oldCwd = runtime.getCurrentDirectory(); // FIXME: Don't allow multiple threads to do this at once runtime.setCurrentDirectory(adjustedPath); try { result = block.yield(context, path); } finally { getExistingDir(runtime, oldCwd); // needed in case the block deleted the oldCwd runtime.setCurrentDirectory(oldCwd); } } else { runtime.setCurrentDirectory(adjustedPath); result = runtime.newFixnum(0); } return result; }