write tool fixes
This commit is contained in:
@@ -229,6 +229,8 @@ static int AL(Cfg &cfg, Messages &msgs, Usage &out, volatile int *interrupted, s
|
||||
else if (!has_line && !has_byte && !has_del_lines && !has_del_bytes) {
|
||||
/* No offset/deletion parameters: overwrite the whole file. */
|
||||
std::string c = filter_text(cv);
|
||||
/* Ensure the written file ends with a single trailing newline. */
|
||||
if (!c.empty() && c.back() != '\n') c.push_back('\n');
|
||||
auto sl = fp.find_last_of('/');
|
||||
if (sl != std::string::npos) mkdir_p(std::string_view(fp).substr(0, sl));
|
||||
else mkdir_p(".");
|
||||
@@ -236,6 +238,10 @@ static int AL(Cfg &cfg, Messages &msgs, Usage &out, volatile int *interrupted, s
|
||||
else { res = sfmt("Successfully wrote %zu bytes to %s", c.size(), fp.c_str()); }
|
||||
} else {
|
||||
int werr = 0; std::string c = filter_text(cv);
|
||||
/* Line-based edits keep the text-file trailing-newline convention;
|
||||
* byte-based edits are exact byte operations and must not have a
|
||||
* newline injected. */
|
||||
if (!(has_byte || has_del_bytes) && !c.empty() && c.back() != '\n') c.push_back('\n');
|
||||
res = write_file(fp, line_off, byte_off, del_lines, del_bytes, c, &werr);
|
||||
if (werr) sty = 31;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user