diff options
author | Ron Yorston <rmy@pobox.com> | 2021-03-28 13:18:40 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-29 12:16:21 +0200 |
commit | 5ae25f40bdc839e3fb24dcb7ddd6067698bf87b0 (patch) | |
tree | 0b6fbff2d2b8e4e0247d528368e593a0ed282941 | |
parent | 25d259264019e4171eddde570271a82b6dd0f79a (diff) | |
download | busybox-w32-5ae25f40bdc839e3fb24dcb7ddd6067698bf87b0.tar.gz busybox-w32-5ae25f40bdc839e3fb24dcb7ddd6067698bf87b0.tar.bz2 busybox-w32-5ae25f40bdc839e3fb24dcb7ddd6067698bf87b0.zip |
vi: don't overwrite existing file
If the name of the file being written doesn't match the current
filename and the output file already exists vi should issue a
warning and not overwrite the file.
Because the test only compares the file names it's somewhat over-
protective. If the current file name is 'my_text' and the user tries
to save to './my_text' they'll be prevented from doing so.
function old new delta
colon 3092 3151 +59
.rodata 105118 105146 +28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 87/0) Total: 87 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/editors/vi.c b/editors/vi.c index ccf2870ab..47b13b3ca 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -2816,6 +2816,13 @@ static void colon(char *buf) | |||
2816 | 2816 | ||
2817 | // is there a file name to write to? | 2817 | // is there a file name to write to? |
2818 | if (args[0]) { | 2818 | if (args[0]) { |
2819 | struct stat statbuf; | ||
2820 | |||
2821 | if (!useforce && (fn == NULL || strcmp(fn, args) != 0) && | ||
2822 | stat(args, &statbuf) == 0) { | ||
2823 | status_line_bold("File exists (:w! overrides)"); | ||
2824 | goto ret; | ||
2825 | } | ||
2819 | fn = args; | 2826 | fn = args; |
2820 | } | 2827 | } |
2821 | # if ENABLE_FEATURE_VI_READONLY | 2828 | # if ENABLE_FEATURE_VI_READONLY |