Skip to content

Commit

Permalink
Shell: Add create() factory function for PathRedirection
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Aug 12, 2020
1 parent e8d6653 commit 85b02d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Shell/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ RefPtr<Value> ReadRedirection::run(RefPtr<Shell> shell)
StringBuilder builder;
builder.join(" ", path_segments);

command.redirections.append(adopt(*new PathRedirection(builder.to_string(), m_fd, PathRedirection::Read)));
command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::Read));
return create<CommandValue>(move(command));
}

Expand All @@ -1288,7 +1288,7 @@ RefPtr<Value> ReadWriteRedirection::run(RefPtr<Shell> shell)
StringBuilder builder;
builder.join(" ", path_segments);

command.redirections.append(adopt(*new PathRedirection(builder.to_string(), m_fd, PathRedirection::ReadWrite)));
command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::ReadWrite));
return create<CommandValue>(move(command));
}

Expand Down Expand Up @@ -1781,7 +1781,7 @@ RefPtr<Value> WriteAppendRedirection::run(RefPtr<Shell> shell)
StringBuilder builder;
builder.join(" ", path_segments);

command.redirections.append(adopt(*new PathRedirection(builder.to_string(), m_fd, PathRedirection::WriteAppend)));
command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::WriteAppend));
return create<CommandValue>(move(command));
}

Expand All @@ -1808,7 +1808,7 @@ RefPtr<Value> WriteRedirection::run(RefPtr<Shell> shell)
StringBuilder builder;
builder.join(" ", path_segments);

command.redirections.append(adopt(*new PathRedirection(builder.to_string(), m_fd, PathRedirection::Write)));
command.redirections.append(PathRedirection::create(builder.to_string(), m_fd, PathRedirection::Write));
return create<CommandValue>(move(command));
}

Expand Down
8 changes: 7 additions & 1 deletion Shell/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,22 @@ struct PathRedirection : public Redirection {
ReadWrite,
} direction { Read };

static NonnullRefPtr<PathRedirection> create(String path, int fd, decltype(direction) direction)
{
return adopt(*new PathRedirection(move(path), fd, direction));
}

virtual Result<NonnullRefPtr<Rewiring>, String> apply() const override;
virtual ~PathRedirection();

private:
PathRedirection(String path, int fd, decltype(direction) direction)
: path(move(path))
, fd(fd)
, direction(direction)
{
}

private:
virtual bool is_path_redirection() const override { return true; }
};

Expand Down

0 comments on commit 85b02d8

Please sign in to comment.