comparison src/bufwrite.c @ 26863:6ee19c6ae8a2 v8.2.3960

patch 8.2.3960: error messages are spread out Commit: https://github.com/vim/vim/commit/f1474d801bbdb73406dd3d1f931f515f99e86dfa Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 31 19:59:55 2021 +0000 patch 8.2.3960: error messages are spread out Problem: Error messages are spread out. Solution: Move more errors to errors.h.
author Bram Moolenaar <Bram@vim.org>
date Fri, 31 Dec 2021 21:15:02 +0100
parents df2de1e63de0
children bce848ec8b1b
comparison
equal deleted inserted replaced
26862:e91b94a101d1 26863:6ee19c6ae8a2
665 int device = FALSE; // writing to a device 665 int device = FALSE; // writing to a device
666 stat_T st_old; 666 stat_T st_old;
667 int prev_got_int = got_int; 667 int prev_got_int = got_int;
668 int checking_conversion; 668 int checking_conversion;
669 int file_readonly = FALSE; // overwritten file is read-only 669 int file_readonly = FALSE; // overwritten file is read-only
670 static char *err_readonly = "is read-only (cannot override: \"W\" in 'cpoptions')";
671 #if defined(UNIX) // XXX fix me sometime? 670 #if defined(UNIX) // XXX fix me sometime?
672 int made_writable = FALSE; // 'w' bit has been set 671 int made_writable = FALSE; // 'w' bit has been set
673 #endif 672 #endif
674 // writing everything 673 // writing everything
675 int whole = (start == 1 && end == buf->b_ml.ml_line_count); 674 int whole = (start == 1 && end == buf->b_ml.ml_line_count);
895 } 894 }
896 895
897 --no_wait_return; 896 --no_wait_return;
898 msg_scroll = msg_save; 897 msg_scroll = msg_save;
899 if (nofile_err) 898 if (nofile_err)
900 emsg(_("E676: No matching autocommands for acwrite buffer")); 899 emsg(_(e_no_matching_autocommands_for_acwrite_buffer));
901 900
902 if (nofile_err 901 if (nofile_err
903 #ifdef FEAT_EVAL 902 #ifdef FEAT_EVAL
904 || aborting() 903 || aborting()
905 #endif 904 #endif
993 return retval; 992 return retval;
994 } 993 }
995 else 994 else
996 { 995 {
997 errnum = (char_u *)"E656: "; 996 errnum = (char_u *)"E656: ";
998 errmsg = (char_u *)_("NetBeans disallows writes of unmodified buffers"); 997 errmsg = (char_u *)_(e_netbeans_disallows_writes_of_unmodified_buffers);
999 buffer = NULL; 998 buffer = NULL;
1000 goto fail; 999 goto fail;
1001 } 1000 }
1002 } 1001 }
1003 else 1002 else
1004 { 1003 {
1005 errnum = (char_u *)"E657: "; 1004 errnum = (char_u *)"E657: ";
1006 errmsg = (char_u *)_("Partial writes disallowed for NetBeans buffers"); 1005 errmsg = (char_u *)_(e_partial_writes_disallowed_for_netbeans_buffers);
1007 buffer = NULL; 1006 buffer = NULL;
1008 goto fail; 1007 goto fail;
1009 } 1008 }
1010 } 1009 }
1011 #endif 1010 #endif
1048 if (!S_ISREG(st_old.st_mode)) // not a file 1047 if (!S_ISREG(st_old.st_mode)) // not a file
1049 { 1048 {
1050 if (S_ISDIR(st_old.st_mode)) 1049 if (S_ISDIR(st_old.st_mode))
1051 { 1050 {
1052 errnum = (char_u *)"E502: "; 1051 errnum = (char_u *)"E502: ";
1053 errmsg = (char_u *)_("is a directory"); 1052 errmsg = (char_u *)_(e_is_a_directory);
1054 goto fail; 1053 goto fail;
1055 } 1054 }
1056 if (mch_nodetype(fname) != NODE_WRITABLE) 1055 if (mch_nodetype(fname) != NODE_WRITABLE)
1057 { 1056 {
1058 errnum = (char_u *)"E503: "; 1057 errnum = (char_u *)"E503: ";
1059 errmsg = (char_u *)_("is not a file or writable device"); 1058 errmsg = (char_u *)_(e_is_not_file_or_writable_device);
1060 goto fail; 1059 goto fail;
1061 } 1060 }
1062 // It's a device of some kind (or a fifo) which we can write to 1061 // It's a device of some kind (or a fifo) which we can write to
1063 // but for which we can't make a backup. 1062 // but for which we can't make a backup.
1064 device = TRUE; 1063 device = TRUE;
1070 // Check for a writable device name. 1069 // Check for a writable device name.
1071 c = mch_nodetype(fname); 1070 c = mch_nodetype(fname);
1072 if (c == NODE_OTHER) 1071 if (c == NODE_OTHER)
1073 { 1072 {
1074 errnum = (char_u *)"E503: "; 1073 errnum = (char_u *)"E503: ";
1075 errmsg = (char_u *)_("is not a file or writable device"); 1074 errmsg = (char_u *)_(e_is_not_file_or_writable_device);
1076 goto fail; 1075 goto fail;
1077 } 1076 }
1078 if (c == NODE_WRITABLE) 1077 if (c == NODE_WRITABLE)
1079 { 1078 {
1080 # if defined(MSWIN) 1079 # if defined(MSWIN)
1081 // MS-Windows allows opening a device, but we will probably get stuck 1080 // MS-Windows allows opening a device, but we will probably get stuck
1082 // trying to write to it. 1081 // trying to write to it.
1083 if (!p_odev) 1082 if (!p_odev)
1084 { 1083 {
1085 errnum = (char_u *)"E796: "; 1084 errnum = (char_u *)"E796: ";
1086 errmsg = (char_u *)_("writing to device disabled with 'opendevice' option"); 1085 errmsg = (char_u *)_(e_writing_to_device_disabled_with_opendevice_option);
1087 goto fail; 1086 goto fail;
1088 } 1087 }
1089 # endif 1088 # endif
1090 device = TRUE; 1089 device = TRUE;
1091 newfile = TRUE; 1090 newfile = TRUE;
1097 if (perm < 0) 1096 if (perm < 0)
1098 newfile = TRUE; 1097 newfile = TRUE;
1099 else if (mch_isdir(fname)) 1098 else if (mch_isdir(fname))
1100 { 1099 {
1101 errnum = (char_u *)"E502: "; 1100 errnum = (char_u *)"E502: ";
1102 errmsg = (char_u *)_("is a directory"); 1101 errmsg = (char_u *)_(e_is_a_directory);
1103 goto fail; 1102 goto fail;
1104 } 1103 }
1105 if (overwriting) 1104 if (overwriting)
1106 (void)mch_stat((char *)fname, &st_old); 1105 (void)mch_stat((char *)fname, &st_old);
1107 } 1106 }
1116 if (!forceit && file_readonly) 1115 if (!forceit && file_readonly)
1117 { 1116 {
1118 if (vim_strchr(p_cpo, CPO_FWRITE) != NULL) 1117 if (vim_strchr(p_cpo, CPO_FWRITE) != NULL)
1119 { 1118 {
1120 errnum = (char_u *)"E504: "; 1119 errnum = (char_u *)"E504: ";
1121 errmsg = (char_u *)_(err_readonly); 1120 errmsg = (char_u *)_(e_is_read_only_cannot_override_W_in_cpoptions);
1122 } 1121 }
1123 else 1122 else
1124 { 1123 {
1125 errnum = (char_u *)"E505: "; 1124 errnum = (char_u *)"E505: ";
1126 errmsg = (char_u *)_("is read-only (add ! to override)"); 1125 errmsg = (char_u *)_(e_is_read_only_add_bang_to_override);
1127 } 1126 }
1128 goto fail; 1127 goto fail;
1129 } 1128 }
1130 1129
1131 // Check if the timestamp hasn't changed since reading the file. 1130 // Check if the timestamp hasn't changed since reading the file.
1475 while ((write_info.bw_len = read_eintr(fd, copybuf, 1474 while ((write_info.bw_len = read_eintr(fd, copybuf,
1476 WRITEBUFSIZE)) > 0) 1475 WRITEBUFSIZE)) > 0)
1477 { 1476 {
1478 if (buf_write_bytes(&write_info) == FAIL) 1477 if (buf_write_bytes(&write_info) == FAIL)
1479 { 1478 {
1480 errmsg = (char_u *)_("E506: Can't write to backup file (add ! to override)"); 1479 errmsg = (char_u *)_(e_canot_write_to_backup_file_add_bang_to_override);
1481 break; 1480 break;
1482 } 1481 }
1483 ui_breakcheck(); 1482 ui_breakcheck();
1484 if (got_int) 1483 if (got_int)
1485 { 1484 {
1487 break; 1486 break;
1488 } 1487 }
1489 } 1488 }
1490 1489
1491 if (close(bfd) < 0 && errmsg == NULL) 1490 if (close(bfd) < 0 && errmsg == NULL)
1492 errmsg = (char_u *)_("E507: Close error for backup file (add ! to override)"); 1491 errmsg = (char_u *)_(e_close_error_for_backup_file_add_bang_to_write_anyway);
1493 if (write_info.bw_len < 0) 1492 if (write_info.bw_len < 0)
1494 errmsg = (char_u *)_("E508: Can't read file for backup (add ! to override)"); 1493 errmsg = (char_u *)_(e_cant_read_file_for_backup_add_bang_to_write_anyway);
1495 #ifdef UNIX 1494 #ifdef UNIX
1496 set_file_time(backup, st_old.st_atime, st_old.st_mtime); 1495 set_file_time(backup, st_old.st_atime, st_old.st_mtime);
1497 #endif 1496 #endif
1498 #ifdef HAVE_ACL 1497 #ifdef HAVE_ACL
1499 mch_set_acl(backup, acl); 1498 mch_set_acl(backup, acl);
1511 nobackup: 1510 nobackup:
1512 close(fd); // ignore errors for closing read file 1511 close(fd); // ignore errors for closing read file
1513 vim_free(copybuf); 1512 vim_free(copybuf);
1514 1513
1515 if (backup == NULL && errmsg == NULL) 1514 if (backup == NULL && errmsg == NULL)
1516 errmsg = (char_u *)_("E509: Cannot create backup file (add ! to override)"); 1515 errmsg = (char_u *)_(e_cannot_create_backup_file_add_bang_to_write_anyway);
1517 // ignore errors when forceit is TRUE 1516 // ignore errors when forceit is TRUE
1518 if ((some_error || errmsg != NULL) && !forceit) 1517 if ((some_error || errmsg != NULL) && !forceit)
1519 { 1518 {
1520 retval = FAIL; 1519 retval = FAIL;
1521 goto fail; 1520 goto fail;
1534 // overwrite a read-only file. But rename may be possible 1533 // overwrite a read-only file. But rename may be possible
1535 // anyway, thus we need an extra check here. 1534 // anyway, thus we need an extra check here.
1536 if (file_readonly && vim_strchr(p_cpo, CPO_FWRITE) != NULL) 1535 if (file_readonly && vim_strchr(p_cpo, CPO_FWRITE) != NULL)
1537 { 1536 {
1538 errnum = (char_u *)"E504: "; 1537 errnum = (char_u *)"E504: ";
1539 errmsg = (char_u *)_(err_readonly); 1538 errmsg = (char_u *)_(e_is_read_only_cannot_override_W_in_cpoptions);
1540 goto fail; 1539 goto fail;
1541 } 1540 }
1542 1541
1543 // Form the backup file name - change path/fo.o.h to 1542 // Form the backup file name - change path/fo.o.h to
1544 // path/fo.o.h.bak Try all directories in 'backupdir', first one 1543 // path/fo.o.h.bak Try all directories in 'backupdir', first one
1606 VIM_CLEAR(backup); // don't do the rename below 1605 VIM_CLEAR(backup); // don't do the rename below
1607 } 1606 }
1608 } 1607 }
1609 if (backup == NULL && !forceit) 1608 if (backup == NULL && !forceit)
1610 { 1609 {
1611 errmsg = (char_u *)_("E510: Can't make backup file (add ! to override)"); 1610 errmsg = (char_u *)_(e_cant_make_backup_file_add_bang_to_write_anyway);
1612 goto fail; 1611 goto fail;
1613 } 1612 }
1614 } 1613 }
1615 } 1614 }
1616 1615
1901 && perm >= 0 1900 && perm >= 0
1902 && mch_fstat(fd, &st) == 0 1901 && mch_fstat(fd, &st) == 0
1903 && st.st_ino != st_old.st_ino) 1902 && st.st_ino != st_old.st_ino)
1904 { 1903 {
1905 close(fd); 1904 close(fd);
1906 errmsg = (char_u *)_("E949: File changed while writing"); 1905 errmsg = (char_u *)_(e_file_changed_while_writing);
1907 goto fail; 1906 goto fail;
1908 } 1907 }
1909 } 1908 }
1910 #endif 1909 #endif
1911 #ifdef HAVE_FTRUNCATE 1910 #ifdef HAVE_FTRUNCATE
2227 if (perm >= 0) 2226 if (perm >= 0)
2228 (void)mch_fsetperm(fd, perm); 2227 (void)mch_fsetperm(fd, perm);
2229 #endif 2228 #endif
2230 if (close(fd) != 0) 2229 if (close(fd) != 0)
2231 { 2230 {
2232 errmsg = (char_u *)_("E512: Close failed"); 2231 errmsg = (char_u *)_(e_close_failed);
2233 end = 0; 2232 end = 0;
2234 } 2233 }
2235 2234
2236 #ifndef HAVE_FCHMOD 2235 #ifndef HAVE_FCHMOD
2237 // set permission of new file same as old file 2236 // set permission of new file same as old file
2284 if (errmsg == NULL) 2283 if (errmsg == NULL)
2285 { 2284 {
2286 if (write_info.bw_conv_error) 2285 if (write_info.bw_conv_error)
2287 { 2286 {
2288 if (write_info.bw_conv_error_lnum == 0) 2287 if (write_info.bw_conv_error_lnum == 0)
2289 errmsg = (char_u *)_("E513: write error, conversion failed (make 'fenc' empty to override)"); 2288 errmsg = (char_u *)_(e_write_error_conversion_failed_make_fenc_empty_to_override);
2290 else 2289 else
2291 { 2290 {
2292 errmsg_allocated = TRUE; 2291 errmsg_allocated = TRUE;
2293 errmsg = alloc(300); 2292 errmsg = alloc(300);
2294 vim_snprintf((char *)errmsg, 300, _("E513: write error, conversion failed in line %ld (make 'fenc' empty to override)"), 2293 vim_snprintf((char *)errmsg, 300, _(e_write_error_conversion_failed_in_line_nr_make_fenc_empty_to_override),
2295 (long)write_info.bw_conv_error_lnum); 2294 (long)write_info.bw_conv_error_lnum);
2296 } 2295 }
2297 } 2296 }
2298 else if (got_int) 2297 else if (got_int)
2299 errmsg = (char_u *)_(e_interr); 2298 errmsg = (char_u *)_(e_interr);
2300 else 2299 else
2301 errmsg = (char_u *)_("E514: write error (file system full?)"); 2300 errmsg = (char_u *)_(e_write_error_file_system_full);
2302 } 2301 }
2303 2302
2304 // If we have a backup file, try to put it in place of the new file, 2303 // If we have a backup file, try to put it in place of the new file,
2305 // because the new file is probably corrupt. This avoids losing the 2304 // because the new file is probably corrupt. This avoids losing the
2306 // original file when trying to make a backup when writing the file a 2305 // original file when trying to make a backup when writing the file a