summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.1413
blob: 6b3de1b7de9d20e81ae056dc76990a98881b08ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
To: vim_dev@googlegroups.com
Subject: Patch 8.1.1413
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.1413
Problem:    Error when the drive of the swap file was disconnected.
Solution:   Try closing and re-opening the swap file. (closes #4378)
Files:	    src/memfile.c, src/structs.h, src/testdir/test_startup.vim


*** ../vim-8.1.1412/src/memfile.c	2019-05-24 18:48:36.766128461 +0200
--- src/memfile.c	2019-05-27 23:27:40.760156972 +0200
***************
*** 994,1000 ****
      unsigned	page_count; /* number of pages written */
      unsigned	size;	    /* number of bytes written */
  
!     if (mfp->mf_fd < 0)	    /* there is no file, can't write */
  	return FAIL;
  
      if (hp->bh_bnum < 0)	/* must assign file block number */
--- 994,1001 ----
      unsigned	page_count; /* number of pages written */
      unsigned	size;	    /* number of bytes written */
  
!     if (mfp->mf_fd < 0 && !mfp->mf_reopen)
! 	// there is no file and there was no file, can't write
  	return FAIL;
  
      if (hp->bh_bnum < 0)	/* must assign file block number */
***************
*** 1011,1016 ****
--- 1012,1019 ----
       */
      for (;;)
      {
+ 	int attempt;
+ 
  	nr = hp->bh_bnum;
  	if (nr > mfp->mf_infile_count)		/* beyond end of file */
  	{
***************
*** 1021,1049 ****
  	    hp2 = hp;
  
  	offset = (off_T)page_size * nr;
- 	if (vim_lseek(mfp->mf_fd, offset, SEEK_SET) != offset)
- 	{
- 	    PERROR(_("E296: Seek error in swap file write"));
- 	    return FAIL;
- 	}
  	if (hp2 == NULL)	    /* freed block, fill with dummy data */
  	    page_count = 1;
  	else
  	    page_count = hp2->bh_page_count;
  	size = page_size * page_count;
! 	if (mf_write_block(mfp, hp2 == NULL ? hp : hp2, offset, size) == FAIL)
  	{
! 	    /*
! 	     * Avoid repeating the error message, this mostly happens when the
! 	     * disk is full. We give the message again only after a successful
! 	     * write or when hitting a key. We keep on trying, in case some
! 	     * space becomes available.
! 	     */
! 	    if (!did_swapwrite_msg)
! 		emsg(_("E297: Write error in swap file"));
! 	    did_swapwrite_msg = TRUE;
! 	    return FAIL;
  	}
  	did_swapwrite_msg = FALSE;
  	if (hp2 != NULL)		    /* written a non-dummy block */
  	    hp2->bh_flags &= ~BH_DIRTY;
--- 1024,1072 ----
  	    hp2 = hp;
  
  	offset = (off_T)page_size * nr;
  	if (hp2 == NULL)	    /* freed block, fill with dummy data */
  	    page_count = 1;
  	else
  	    page_count = hp2->bh_page_count;
  	size = page_size * page_count;
! 
! 	for (attempt = 1; attempt <= 2; ++attempt)
  	{
! 	    if (mfp->mf_fd >= 0)
! 	    {
! 		if (vim_lseek(mfp->mf_fd, offset, SEEK_SET) != offset)
! 		{
! 		    PERROR(_("E296: Seek error in swap file write"));
! 		    return FAIL;
! 		}
! 		if (mf_write_block(mfp,
! 				   hp2 == NULL ? hp : hp2, offset, size) == OK)
! 		    break;
! 	    }
! 
! 	    if (attempt == 1)
! 	    {
! 		// If the swap file is on a network drive, and the network
! 		// gets disconnected and then re-connected, we can maybe fix it
! 		// by closing and then re-opening the file.
! 		if (mfp->mf_fd >= 0)
! 		    close(mfp->mf_fd);
! 		mfp->mf_fd = mch_open_rw((char *)mfp->mf_fname, mfp->mf_flags);
! 		mfp->mf_reopen = (mfp->mf_fd < 0);
! 	    }
! 	    if (attempt == 2 || mfp->mf_fd < 0)
! 	    {
! 		// Avoid repeating the error message, this mostly happens when
! 		// the disk is full. We give the message again only after a
! 		// successful write or when hitting a key. We keep on trying,
! 		// in case some space becomes available.
! 		if (!did_swapwrite_msg)
! 		    emsg(_("E297: Write error in swap file"));
! 		did_swapwrite_msg = TRUE;
! 		return FAIL;
! 	    }
  	}
+ 
  	did_swapwrite_msg = FALSE;
  	if (hp2 != NULL)		    /* written a non-dummy block */
  	    hp2->bh_flags &= ~BH_DIRTY;
***************
*** 1271,1276 ****
--- 1294,1300 ----
  	 * the file) */
  	flags |= O_NOINHERIT;
  #endif
+ 	mfp->mf_flags = flags;
  	mfp->mf_fd = mch_open_rw((char *)mfp->mf_fname, flags);
      }
  
*** ../vim-8.1.1412/src/structs.h	2019-05-27 21:53:53.990229301 +0200
--- src/structs.h	2019-05-27 23:22:20.062819685 +0200
***************
*** 604,631 ****
  
  struct memfile
  {
!     char_u	*mf_fname;		/* name of the file */
!     char_u	*mf_ffname;		/* idem, full path */
!     int		mf_fd;			/* file descriptor */
!     bhdr_T	*mf_free_first;		/* first block_hdr in free list */
!     bhdr_T	*mf_used_first;		/* mru block_hdr in used list */
!     bhdr_T	*mf_used_last;		/* lru block_hdr in used list */
!     unsigned	mf_used_count;		/* number of pages in used list */
!     unsigned	mf_used_count_max;	/* maximum number of pages in memory */
!     mf_hashtab_T mf_hash;		/* hash lists */
!     mf_hashtab_T mf_trans;		/* trans lists */
!     blocknr_T	mf_blocknr_max;		/* highest positive block number + 1*/
!     blocknr_T	mf_blocknr_min;		/* lowest negative block number - 1 */
!     blocknr_T	mf_neg_count;		/* number of negative blocks numbers */
!     blocknr_T	mf_infile_count;	/* number of pages in the file */
!     unsigned	mf_page_size;		/* number of bytes in a page */
!     int		mf_dirty;		/* TRUE if there are dirty blocks */
  #ifdef FEAT_CRYPT
!     buf_T	*mf_buffer;		/* buffer this memfile is for */
!     char_u	mf_seed[MF_SEED_LEN];	/* seed for encryption */
  
!     /* Values for key, method and seed used for reading data blocks when
!      * updating for a newly set key or method. Only when mf_old_key != NULL. */
      char_u	*mf_old_key;
      int		mf_old_cm;
      char_u	mf_old_seed[MF_SEED_LEN];
--- 604,633 ----
  
  struct memfile
  {
!     char_u	*mf_fname;		// name of the file
!     char_u	*mf_ffname;		// idem, full path
!     int		mf_fd;			// file descriptor
!     int		mf_flags;		// flags used when opening this memfile
!     int		mf_reopen;		// mf_fd was closed, retry opening
!     bhdr_T	*mf_free_first;		// first block_hdr in free list
!     bhdr_T	*mf_used_first;		// mru block_hdr in used list
!     bhdr_T	*mf_used_last;		// lru block_hdr in used list
!     unsigned	mf_used_count;		// number of pages in used list
!     unsigned	mf_used_count_max;	// maximum number of pages in memory
!     mf_hashtab_T mf_hash;		// hash lists
!     mf_hashtab_T mf_trans;		// trans lists
!     blocknr_T	mf_blocknr_max;		// highest positive block number + 1
!     blocknr_T	mf_blocknr_min;		// lowest negative block number - 1
!     blocknr_T	mf_neg_count;		// number of negative blocks numbers
!     blocknr_T	mf_infile_count;	// number of pages in the file
!     unsigned	mf_page_size;		// number of bytes in a page
!     int		mf_dirty;		// TRUE if there are dirty blocks
  #ifdef FEAT_CRYPT
!     buf_T	*mf_buffer;		// buffer this memfile is for
!     char_u	mf_seed[MF_SEED_LEN];	// seed for encryption
  
!     // Values for key, method and seed used for reading data blocks when
!     // updating for a newly set key or method. Only when mf_old_key != NULL.
      char_u	*mf_old_key;
      int		mf_old_cm;
      char_u	mf_old_seed[MF_SEED_LEN];
*** ../vim-8.1.1412/src/testdir/test_startup.vim	2019-05-20 22:12:30.724442773 +0200
--- src/testdir/test_startup.vim	2019-05-27 23:34:05.857353849 +0200
***************
*** 288,311 ****
  
    " Test with default argument '-q'.
    call assert_equal('errors.err', &errorfile)
!   call writefile(["../memfile.c:1482:5: error: expected ';' before '}' token"], 'errors.err')
    if RunVim([], after, '-q')
      let lines = readfile('Xtestout')
      call assert_equal(['errors.err',
! 	\              '[0, 1482, 5, 0]',
! 	\              source_file . "|1482 col 5| error: expected ';' before '}' token"],
  	\             lines)
    endif
    call delete('Xtestout')
    call delete('errors.err')
  
    " Test with explicit argument '-q Xerrors' (with space).
!   call writefile(["../memfile.c:1482:5: error: expected ';' before '}' token"], 'Xerrors')
    if RunVim([], after, '-q Xerrors')
      let lines = readfile('Xtestout')
      call assert_equal(['Xerrors',
! 	\              '[0, 1482, 5, 0]',
! 	\              source_file . "|1482 col 5| error: expected ';' before '}' token"],
  	\             lines)
    endif
    call delete('Xtestout')
--- 288,311 ----
  
    " Test with default argument '-q'.
    call assert_equal('errors.err', &errorfile)
!   call writefile(["../memfile.c:208:5: error: expected ';' before '}' token"], 'errors.err')
    if RunVim([], after, '-q')
      let lines = readfile('Xtestout')
      call assert_equal(['errors.err',
! 	\              '[0, 208, 5, 0]',
! 	\              source_file . "|208 col 5| error: expected ';' before '}' token"],
  	\             lines)
    endif
    call delete('Xtestout')
    call delete('errors.err')
  
    " Test with explicit argument '-q Xerrors' (with space).
!   call writefile(["../memfile.c:208:5: error: expected ';' before '}' token"], 'Xerrors')
    if RunVim([], after, '-q Xerrors')
      let lines = readfile('Xtestout')
      call assert_equal(['Xerrors',
! 	\              '[0, 208, 5, 0]',
! 	\              source_file . "|208 col 5| error: expected ';' before '}' token"],
  	\             lines)
    endif
    call delete('Xtestout')
***************
*** 314,321 ****
    if RunVim([], after, '-qXerrors')
      let lines = readfile('Xtestout')
      call assert_equal(['Xerrors',
! 	\              '[0, 1482, 5, 0]',
! 	\              source_file . "|1482 col 5| error: expected ';' before '}' token"],
  	\             lines)
    endif
  
--- 314,321 ----
    if RunVim([], after, '-qXerrors')
      let lines = readfile('Xtestout')
      call assert_equal(['Xerrors',
! 	\              '[0, 208, 5, 0]',
! 	\              source_file . "|208 col 5| error: expected ';' before '}' token"],
  	\             lines)
    endif
  
*** ../vim-8.1.1412/src/version.c	2019-05-27 22:21:41.309951907 +0200
--- src/version.c	2019-05-27 23:15:38.563021697 +0200
***************
*** 769,770 ****
--- 769,772 ----
  {   /* Add new patch number below this line */
+ /**/
+     1413,
  /**/

-- 
Portable Computer:  A device invented to force businessmen
to work at home, on vacation, and on business trips.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///