diff --git a/Shell/AST.cpp b/Shell/AST.cpp index 7b9e0aaf6f..d82ca6834c 100644 --- a/Shell/AST.cpp +++ b/Shell/AST.cpp @@ -1261,7 +1261,7 @@ RefPtr ReadRedirection::run(RefPtr 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(move(command)); } @@ -1288,7 +1288,7 @@ RefPtr ReadWriteRedirection::run(RefPtr 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(move(command)); } @@ -1781,7 +1781,7 @@ RefPtr WriteAppendRedirection::run(RefPtr 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(move(command)); } @@ -1808,7 +1808,7 @@ RefPtr WriteRedirection::run(RefPtr 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(move(command)); } diff --git a/Shell/AST.h b/Shell/AST.h index 4a81fdfd19..bdddfba75d 100644 --- a/Shell/AST.h +++ b/Shell/AST.h @@ -109,8 +109,15 @@ struct PathRedirection : public Redirection { ReadWrite, } direction { Read }; + static NonnullRefPtr create(String path, int fd, decltype(direction) direction) + { + return adopt(*new PathRedirection(move(path), fd, direction)); + } + virtual Result, String> apply() const override; virtual ~PathRedirection(); + +private: PathRedirection(String path, int fd, decltype(direction) direction) : path(move(path)) , fd(fd) @@ -118,7 +125,6 @@ struct PathRedirection : public Redirection { { } -private: virtual bool is_path_redirection() const override { return true; } };