diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-12 12:15:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-12 12:15:30 +0200 |
commit | 85b02d887b7b654d1977c361abb76c278c7159c2 (patch) | |
tree | 63466f943033b2cfe8f42eb30291c4f020b95298 /Shell | |
parent | e8d665337a41ba7be8be98274ff0c18063035a4f (diff) | |
download | serenity-85b02d887b7b654d1977c361abb76c278c7159c2.zip |
Shell: Add create() factory function for PathRedirection
Diffstat (limited to 'Shell')
-rw-r--r-- | Shell/AST.cpp | 8 | ||||
-rw-r--r-- | Shell/AST.h | 8 |
2 files changed, 11 insertions, 5 deletions
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<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)); } @@ -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)); } @@ -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)); } @@ -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)); } 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<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) @@ -118,7 +125,6 @@ struct PathRedirection : public Redirection { { } -private: virtual bool is_path_redirection() const override { return true; } }; |