Remove non-const get_io_for_fd

These could be made unused.
This commit is contained in:
ridiculousfish 2019-11-10 13:33:20 -08:00
parent 424c56006d
commit 521d0e84f5
3 changed files with 4 additions and 19 deletions

View file

@ -76,7 +76,7 @@ void exec_close(int fd) {
}
/// Returns true if the redirection is a file redirection to a file other than /dev/null.
static bool redirection_is_to_real_file(const shared_ptr<io_data_t> &io) {
static bool redirection_is_to_real_file(const shared_ptr<const io_data_t> &io) {
bool result = false;
if (io && io->io_mode == io_mode_t::file) {
// It's a file redirection. Compare the path to /dev/null.
@ -594,8 +594,8 @@ static bool handle_builtin_output(parser_t &parser, const std::shared_ptr<job_t>
// We will try to elide constructing an internal process. However if the output is going to a
// real file, we have to do it. For example in `echo -n > file.txt` we proceed to open file.txt
// even though there is no output, so that it is properly truncated.
const shared_ptr<io_data_t> stdout_io = io_chain->get_io_for_fd(STDOUT_FILENO);
const shared_ptr<io_data_t> stderr_io = io_chain->get_io_for_fd(STDERR_FILENO);
const shared_ptr<const io_data_t> stdout_io = io_chain->get_io_for_fd(STDOUT_FILENO);
const shared_ptr<const io_data_t> stderr_io = io_chain->get_io_for_fd(STDERR_FILENO);
bool must_use_process =
redirection_is_to_real_file(stdout_io) || redirection_is_to_real_file(stderr_io);
@ -610,7 +610,7 @@ static bool handle_builtin_output(parser_t &parser, const std::shared_ptr<job_t>
// need for a similar check for stderr.
bool stdout_done = false;
if (stdout_io && stdout_io->io_mode == io_mode_t::bufferfill) {
auto stdout_buffer = static_cast<io_bufferfill_t *>(stdout_io.get())->buffer();
auto stdout_buffer = static_cast<const io_bufferfill_t *>(stdout_io.get())->buffer();
stdout_buffer->append_from_stream(stdout_stream);
stdout_done = true;
}

View file

@ -337,20 +337,7 @@ shared_ptr<const io_data_t> io_chain_t::get_io_for_fd(int fd) const {
return shared_ptr<const io_data_t>();
}
shared_ptr<io_data_t> io_chain_t::get_io_for_fd(int fd) {
size_t idx = this->size();
while (idx--) {
const shared_ptr<io_data_t> &data = this->at(idx);
if (data->fd == fd) {
return data;
}
}
return shared_ptr<io_data_t>();
}
/// The old function returned the last match, so we mimic that.
shared_ptr<const io_data_t> io_chain_get(const io_chain_t &src, int fd) {
return src.get_io_for_fd(fd);
}
shared_ptr<io_data_t> io_chain_get(io_chain_t &src, int fd) { return src.get_io_for_fd(fd); }

View file

@ -336,12 +336,10 @@ class io_chain_t : public std::vector<shared_ptr<io_data_t>> {
void append(const io_chain_t &chain);
shared_ptr<const io_data_t> get_io_for_fd(int fd) const;
shared_ptr<io_data_t> get_io_for_fd(int fd);
};
/// Return the last io redirection in the chain for the specified file descriptor.
shared_ptr<const io_data_t> io_chain_get(const io_chain_t &src, int fd);
shared_ptr<io_data_t> io_chain_get(io_chain_t &src, int fd);
/// Helper type returned from making autoclose pipes.
struct autoclose_pipes_t {