mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
Shell: Add create() factory function for PathRedirection
This commit is contained in:
parent
e8d665337a
commit
85b02d887b
2 changed files with 11 additions and 5 deletions
|
@ -1261,7 +1261,7 @@ RefPtr<Value> ReadRedirection::run(RefPtr<Shell> shell)
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.join(" ", path_segments);
|
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));
|
return create<CommandValue>(move(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1288,7 +1288,7 @@ RefPtr<Value> ReadWriteRedirection::run(RefPtr<Shell> shell)
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.join(" ", path_segments);
|
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));
|
return create<CommandValue>(move(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1781,7 +1781,7 @@ RefPtr<Value> WriteAppendRedirection::run(RefPtr<Shell> shell)
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.join(" ", path_segments);
|
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));
|
return create<CommandValue>(move(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1808,7 +1808,7 @@ RefPtr<Value> WriteRedirection::run(RefPtr<Shell> shell)
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.join(" ", path_segments);
|
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));
|
return create<CommandValue>(move(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,8 +109,15 @@ struct PathRedirection : public Redirection {
|
||||||
ReadWrite,
|
ReadWrite,
|
||||||
} direction { Read };
|
} 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 Result<NonnullRefPtr<Rewiring>, String> apply() const override;
|
||||||
virtual ~PathRedirection();
|
virtual ~PathRedirection();
|
||||||
|
|
||||||
|
private:
|
||||||
PathRedirection(String path, int fd, decltype(direction) direction)
|
PathRedirection(String path, int fd, decltype(direction) direction)
|
||||||
: path(move(path))
|
: path(move(path))
|
||||||
, fd(fd)
|
, fd(fd)
|
||||||
|
@ -118,7 +125,6 @@ struct PathRedirection : public Redirection {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
virtual bool is_path_redirection() const override { return true; }
|
virtual bool is_path_redirection() const override { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue