]> git.ipfire.org Git - thirdparty/systemd.git/commit
systemctl: add message when edit is aborted
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Dec 2023 15:41:46 +0000 (16:41 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 5 Dec 2023 17:11:45 +0000 (18:11 +0100)
commit232f017b1a879c4d099dcbb644f60e44ae2b8dbf
treebcc6758231e1659e224c876c8c8679990443d578
parent5161836bd093c55bd92cb5314126968e6ebabd5d
systemctl: add message when edit is aborted

If the user edits result in an empty file (after stripping), we would silently
not do anything, aborting the edit. This is rather confusing, let's emit a
notice:

  $ build/systemctl --user edit asdf.service --full --stdin </dev/null
  /home/zbyszek/.config/systemd/user/asdf.service: after editing, new contents are empty, not writing file.

(This also works with an editor, instead of --stdin. The message is printed on
the console and is visible after the editor exits.)

While at it, fix the condition to skip writing file after stripping. We had
"old_contents", but we modified that string. In some code flows, we would
compare the stripped old contents (i.e. a string which by defintion doesn't
have a newline at the end) with a string to which we just appended a newline
(i.e. a string which by defintion has a newline at the end).
src/shared/edit-util.c