4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: When writing a file it is not possible to specify that hard and/or
12 symlinks are to be broken instead of preserved.
13 Solution: Add the "breaksymlink" and "breakhardlink" values to 'backupcopy'.
15 Files: runtime/doc/options.txt, src/fileio.c, src/option.c, src/option.h
18 *** ../vim-6.2.480/runtime/doc/options.txt Mon Apr 5 19:51:11 2004
19 --- runtime/doc/options.txt Sun Apr 18 17:03:19 2004
22 ! *options.txt* For Vim version 6.2. Last change: 2004 Apr 05
25 VIM REFERENCE MANUAL by Bram Moolenaar
27 ! *options.txt* For Vim version 6.2. Last change: 2004 Apr 18
30 VIM REFERENCE MANUAL by Bram Moolenaar
35 When writing a file and a backup is made, this option tells how it's
37 "yes" make a copy of the file and overwrite the original one
38 "no" rename the file and write a new one
39 "auto" one of the previous, what works best
41 Making a copy and overwriting the original file:
42 - Takes extra time to copy the file.
43 + When the file has special attributes, is a (hard/symbolic) link or
47 When writing a file and a backup is made, this option tells how it's
48 ! done. This is a comma separated list of words.
50 ! The main values are:
51 "yes" make a copy of the file and overwrite the original one
52 "no" rename the file and write a new one
53 "auto" one of the previous, what works best
55 + Extra values that can be combined with the ones above are:
56 + "breaksymlink" always break symlinks when writing
57 + "breakhardlink" always break hardlinks when writing
59 Making a copy and overwriting the original file:
60 - Takes extra time to copy the file.
61 + When the file has special attributes, is a (hard/symbolic) link or
65 is possible without side effects (the attributes can be passed on and
66 and the file is not a link) that is used. When problems are expected,
69 + The "breaksymlink" and "breakhardlink" values can be used in
70 + combination with any of "yes", "no" and "auto". When included, they
71 + force Vim to always break either symbolic or hard links by doing
72 + exactly what the "no" option does, renaming the original file to
73 + become the backup and writing a new file in its place. This can be
74 + useful for example in source trees where all the files are symbolic or
75 + hard links and any changes should stay in the local source tree, not
76 + be propagated back to the original source.
78 One situation where "no" and "auto" will cause problems: A program
79 that opens a file, invokes Vim to edit that file, and then tests if
80 *** ../vim-6.2.480/src/fileio.c Fri Apr 16 19:59:33 2004
81 --- src/fileio.c Mon Apr 19 09:52:52 2004
85 if (!(append && *p_pm == NUL) && !filtering && perm >= 0 && dobackup)
87 ! if (*p_bkc == 'y' || append) /* "yes" */
89 #if defined(UNIX) || defined(WIN32)
90 ! else if (*p_bkc == 'a') /* "auto" */
98 if (!(append && *p_pm == NUL) && !filtering && perm >= 0 && dobackup)
100 ! #if defined(UNIX) || defined(WIN32)
104 ! if ((bkc_flags & BKC_YES) || append) /* "yes" */
106 #if defined(UNIX) || defined(WIN32)
107 ! else if ((bkc_flags & BKC_AUTO)) /* "auto" */
121 + * Break symlinks and/or hardlinks if we've been asked to.
123 + if ((bkc_flags & BKC_BREAKSYMLINK) || (bkc_flags & BKC_BREAKHARDLINK))
127 + lstat_res = mch_lstat((char *)fname, &st);
130 + if ((bkc_flags & BKC_BREAKSYMLINK)
132 + && st.st_ino != st_old.st_ino)
133 + backup_copy = FALSE;
136 + if ((bkc_flags & BKC_BREAKHARDLINK)
137 + && st_old.st_nlink > 1
138 + && (lstat_res != 0 || st.st_ino == st_old.st_ino))
139 + backup_copy = FALSE;
145 /* make sure we have a valid backup extension to use */
146 *** ../vim-6.2.480/src/option.c Wed Apr 14 11:08:53 2004
147 --- src/option.c Sun Apr 18 17:20:24 2004
150 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
151 (char_u *)&p_bk, PV_NONE,
152 {(char_u *)FALSE, (char_u *)0L}},
153 ! {"backupcopy", "bkc", P_STRING|P_VIM,
154 (char_u *)&p_bkc, PV_NONE,
156 {(char_u *)"yes", (char_u *)"auto"}
158 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
159 (char_u *)&p_bk, PV_NONE,
160 {(char_u *)FALSE, (char_u *)0L}},
161 ! {"backupcopy", "bkc", P_STRING|P_VIM|P_COMMA|P_NODUP,
162 (char_u *)&p_bkc, PV_NONE,
164 {(char_u *)"yes", (char_u *)"auto"}
167 static char *(p_ambw_values[]) = {"single", "double", NULL};
169 static char *(p_bg_values[]) = {"light", "dark", NULL};
170 - static char *(p_bkc_values[]) = {"yes", "auto", "no", NULL};
171 static char *(p_nf_values[]) = {"octal", "hex", "alpha", NULL};
172 static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
178 (void)init_chartab();
180 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
181 + (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
183 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
184 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
188 else if (varp == &p_bkc)
190 ! if (check_opt_strings(p_bkc, p_bkc_values, FALSE) != OK)
194 /* 'backupext' and 'patchmode' */
197 else if (varp == &p_bkc)
199 ! if (opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE) != OK)
201 + if (((bkc_flags & BKC_AUTO) != 0)
202 + + ((bkc_flags & BKC_YES) != 0)
203 + + ((bkc_flags & BKC_NO) != 0) != 1)
205 + /* Must have exactly one of "auto", "yes" and "no". */
206 + (void)opt_strings_flags(oldval, p_bkc_values, &bkc_flags, TRUE);
211 /* 'backupext' and 'patchmode' */
212 *** ../vim-6.2.480/src/option.h Fri Apr 2 21:06:43 2004
213 --- src/option.h Sun Apr 18 17:18:35 2004
217 EXTERN char_u *p_bg; /* 'background' */
218 EXTERN int p_bk; /* 'backup' */
219 EXTERN char_u *p_bkc; /* 'backupcopy' */
220 + EXTERN unsigned bkc_flags;
222 + static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
224 + # define BKC_YES 0x001
225 + # define BKC_AUTO 0x002
226 + # define BKC_NO 0x004
227 + # define BKC_BREAKSYMLINK 0x008
228 + # define BKC_BREAKHARDLINK 0x010
229 EXTERN char_u *p_bdir; /* 'backupdir' */
230 EXTERN char_u *p_bex; /* 'backupext' */
232 *** ../vim-6.2.480/src/version.c Sat Apr 17 21:14:10 2004
233 --- src/version.c Mon Apr 19 16:51:55 2004
237 { /* Add new patch number below this line */
243 A disclaimer for the disclaimer:
244 "and before I get a huge amount of complaints , I have no control over the
245 disclaimer at the end of this mail :-)" (Timothy Aldrich)
247 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
248 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
249 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
250 \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///