This is a great set of patches you've shared the past few days!

Just a heads up to whoever reviews and merges this: I think this patch in particular might have a small conflict with the patch I submitted on March 3 "vi: allow writing to another file if this one is readonly" which just moves around some curly brackets to fix a bug where you can't write a file in readonly mode.

Looking forward to these improvements!

Alison

On Sun, 28 Mar 2021, Ron Yorston wrote:

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 <r...@pobox.com>
---
editors/vi.c | 7 +++++++
1 file changed, 7 insertions(+)

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)

                // is there a file name to write to?
                if (args[0]) {
+                       struct stat statbuf;
+
+                       if (!useforce && (fn == NULL || strcmp(fn, args) != 0) 
&&
+                                       stat(args, &statbuf) == 0) {
+                               status_line_bold("File exists (:w! overrides)");
+                               goto ret;
+                       }
                        fn = args;
                }
# if ENABLE_FEATURE_VI_READONLY
--
2.30.2

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to