Skip to content

Commit

Permalink
[Truffle] Keep track of the current directory in RubyContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Oct 28, 2016
1 parent f224f23 commit 27ad02c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/RubyContext.java
Expand Up @@ -101,12 +101,15 @@ public class RubyContext extends ExecutionContext {

private final AttachmentsManager attachmentsManager;

private String currentDirectory;

public RubyContext(Ruby jrubyRuntime, TruffleLanguage.Env env) {
latestInstance = this;

this.jrubyRuntime = jrubyRuntime;
this.jrubyInterop = new JRubyInterop(this, jrubyRuntime);
this.env = env;
this.currentDirectory = System.getProperty("user.dir");

if (options.CALL_GRAPH) {
callGraph = new CallGraph();
Expand Down Expand Up @@ -372,4 +375,12 @@ public EncodingManager getEncodingManager() {
return encodingManager;
}

public String getCurrentDirectory() {
return currentDirectory;
}

public void setCurrentDirectory(String currentDirectory) {
this.currentDirectory = currentDirectory;
}

}
Expand Up @@ -401,7 +401,7 @@ public int chdir(DynamicObject path) {

if (result == 0) {
final String cwd = posix().getcwd();
getContext().getJRubyRuntime().setCurrentDirectory(cwd);
getContext().setCurrentDirectory(cwd);
}

return result;
Expand Down Expand Up @@ -596,7 +596,7 @@ public GetcwdNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public DynamicObject getcwd() {
final String cwd = posix().getcwd();
final String path = getContext().getJRubyRuntime().getCurrentDirectory();
final String path = getContext().getCurrentDirectory();
assert path.equals(cwd);

// TODO (nirvdrum 12-Sept-16) The rope table always returns UTF-8, but this call should be based on Encoding.default_external and reflect updates to that value.
Expand Down
Expand Up @@ -63,7 +63,7 @@ public boolean isVerbose() {

@Override
public File getCurrentWorkingDirectory() {
return new File(context.getJRubyRuntime().getCurrentDirectory());
return new File(context.getCurrentDirectory());
}

@Override
Expand Down

0 comments on commit 27ad02c

Please sign in to comment.