| 136 | } |
| 137 | |
| 138 | int strbuf_edit_interactively(struct repository *r, |
| 139 | struct strbuf *buffer, const char *path, |
| 140 | const char *const *env) |
| 141 | { |
| 142 | struct strbuf sb = STRBUF_INIT; |
| 143 | int fd, res = 0; |
| 144 | |
| 145 | if (!is_absolute_path(path)) |
| 146 | path = repo_git_path_append(r, &sb, "%s", path); |
| 147 | |
| 148 | fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
| 149 | if (fd < 0) |
| 150 | res = error_errno(_("could not open '%s' for writing"), path); |
| 151 | else if (write_in_full(fd, buffer->buf, buffer->len) < 0) { |
| 152 | res = error_errno(_("could not write to '%s'"), path); |
| 153 | close(fd); |
| 154 | } else if (close(fd) < 0) |
| 155 | res = error_errno(_("could not close '%s'"), path); |
| 156 | else { |
| 157 | strbuf_reset(buffer); |
| 158 | if (launch_editor(path, buffer, env) < 0) |
| 159 | res = error_errno(_("could not edit '%s'"), path); |
| 160 | unlink(path); |
| 161 | } |
| 162 | |
| 163 | strbuf_release(&sb); |
| 164 | return res; |
| 165 | } |
no test coverage detected