Mercurial > vim
comparison src/bufwrite.c @ 33408:dcfbfe57141c v9.0.1962
patch 9.0.1962: No support for writing extended attributes
Commit: https://github.com/vim/vim/commit/e085dfda5d8dde064b0332464040959479696d1c
Author: Christian Brabandt <cb@256bit.org>
Date: Sat Sep 30 12:49:18 2023 +0200
patch 9.0.1962: No support for writing extended attributes
Problem: No support for writing extended attributes
Solution: Add extended attribute support for linux
It's been a long standing issue, that if you write a file with extended
attributes and backupcopy is set to no, the file will loose the extended
attributes.
So this patch adds support for retrieving the extended attributes and
copying it to the new file. It currently only works on linux, mainly
because I don't know the different APIs for other systems (BSD, MacOSX and
Solaris). On linux, this should be supported since Kernel 2.4 or
something, so this should be pretty safe to use now.
Enable the extended attribute support with normal builds.
I also added it explicitly to the :version output as well as make it
able to check using `:echo has("xattr")`, to have users easily check
that this is available.
In contrast to the similar support for SELINUX and SMACK support (which
also internally uses extended attributes), I have made this a FEAT_XATTR
define, instead of the similar HAVE_XATTR.
Add a test and change CI to include relevant packages so that CI can
test that extended attributes are correctly written.
closes: #306
closes: #13203
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 30 Sep 2023 13:00:06 +0200 |
parents | d8e7d725a666 |
children |
comparison
equal
deleted
inserted
replaced
33407:c476e82af6a7 | 33408:dcfbfe57141c |
---|---|
1469 mch_setperm(backup, | 1469 mch_setperm(backup, |
1470 (perm & 0707) | ((perm & 07) << 3)); | 1470 (perm & 0707) | ((perm & 07) << 3)); |
1471 # if defined(HAVE_SELINUX) || defined(HAVE_SMACK) | 1471 # if defined(HAVE_SELINUX) || defined(HAVE_SMACK) |
1472 mch_copy_sec(fname, backup); | 1472 mch_copy_sec(fname, backup); |
1473 # endif | 1473 # endif |
1474 # ifdef FEAT_XATTR | |
1475 mch_copy_xattr(fname, backup); | |
1476 # endif | |
1474 #endif | 1477 #endif |
1475 | 1478 |
1476 // copy the file. | 1479 // copy the file. |
1477 write_info.bw_fd = bfd; | 1480 write_info.bw_fd = bfd; |
1478 write_info.bw_buf = copybuf; | 1481 write_info.bw_buf = copybuf; |
1503 #ifdef HAVE_ACL | 1506 #ifdef HAVE_ACL |
1504 mch_set_acl(backup, acl); | 1507 mch_set_acl(backup, acl); |
1505 #endif | 1508 #endif |
1506 #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) | 1509 #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) |
1507 mch_copy_sec(fname, backup); | 1510 mch_copy_sec(fname, backup); |
1511 #endif | |
1512 #ifdef FEAT_XATTR | |
1513 mch_copy_xattr(fname, backup); | |
1508 #endif | 1514 #endif |
1509 #ifdef MSWIN | 1515 #ifdef MSWIN |
1510 (void)mch_copy_file_attribute(fname, backup); | 1516 (void)mch_copy_file_attribute(fname, backup); |
1511 #endif | 1517 #endif |
1512 break; | 1518 break; |
2194 errmsg = (char_u *)_(e_fsync_failed); | 2200 errmsg = (char_u *)_(e_fsync_failed); |
2195 end = 0; | 2201 end = 0; |
2196 } | 2202 } |
2197 #endif | 2203 #endif |
2198 | 2204 |
2199 #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) | 2205 #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) || defined(FEAT_XATTR) |
2200 // Probably need to set the security context. | 2206 // Probably need to set the security context. |
2201 if (!backup_copy) | 2207 if (!backup_copy) |
2208 { | |
2209 #if defined(HAVE_SELINUX) || defined(HAVE_SMACK) | |
2202 mch_copy_sec(backup, wfname); | 2210 mch_copy_sec(backup, wfname); |
2211 #endif | |
2212 #ifdef FEAT_XATTR | |
2213 mch_copy_xattr(backup, wfname); | |
2214 #endif | |
2215 } | |
2203 #endif | 2216 #endif |
2204 | 2217 |
2205 #ifdef UNIX | 2218 #ifdef UNIX |
2206 // When creating a new file, set its owner/group to that of the | 2219 // When creating a new file, set its owner/group to that of the |
2207 // original file. Get the new device and inode number. | 2220 // original file. Get the new device and inode number. |