From b3d304df93347ef3f585ae91ae9ff6f5f28651af Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 31 Jan 2023 11:47:02 +0000 Subject: refactor(fileio.c): remove HAVE_ACL ifdefs --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 302faa8140..8915b0de3e 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -788,6 +788,7 @@ int os_setperm(const char *const name, int perm) # ifdef HAVE_SYS_ACCESS_H # include # endif +#endif // Return a pointer to the ACL of file "fname" in allocated memory. // Return NULL if the ACL is not available for whatever reason. @@ -811,7 +812,6 @@ void os_free_acl(vim_acl_T aclent) return; } } -#endif #ifdef UNIX /// Checks if the current user owns a file. -- cgit From 7224c889e0d5d70b99ae377036baa6377c33a568 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:25:24 +0100 Subject: build: enable MSVC level 3 warnings (#21934) MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3 (production quality) and 4 (informational). Enabling level 3 warnings mostly revealed conversion problems, similar to GCC/clang -Wconversion flag. --- src/nvim/os/fs.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 6157341ec9..85d95960a7 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -12,14 +12,20 @@ #include #include #include +#include #include "auto/config.h" +#include "nvim/ascii.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/macros.h" +#include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/option_defs.h" #include "nvim/os/fs_defs.h" +#include "nvim/os/os.h" +#include "nvim/path.h" #include "nvim/types.h" #include "nvim/vim.h" @@ -27,24 +33,17 @@ # include #endif -#include - -#include "nvim/ascii.h" -#include "nvim/memory.h" -#include "nvim/message.h" -#include "nvim/os/os.h" -#include "nvim/path.h" - -struct iovec; - #ifdef MSWIN -# include "nvim/mbyte.h" // for utf8_to_utf16, utf16_to_utf8 +# include "nvim/mbyte.h" +# include "nvim/option.h" #endif #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/fs.c.generated.h" #endif +struct iovec; + #define RUN_UV_FS_FUNC(ret, func, ...) \ do { \ bool did_try_to_free = false; \ -- cgit From 7190dba017e3aac0409c73ff1c954d18858cb3c9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:39:50 +0200 Subject: refactor: remove use of reserved c++ keywords libnvim couldn't be easily used in C++ due to the use of reserved keywords. Additionally, add explicit casts to *alloc function calls used in inline functions, as C++ doesn't allow implicit casts from void pointers. --- src/nvim/os/fs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 7eba5ca54c..cb51e81005 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -1014,17 +1014,17 @@ int os_file_mkdir(char *fname, int32_t mode) /// Create a unique temporary directory. /// -/// @param[in] template Template of the path to the directory with XXXXXX -/// which would be replaced by random chars. +/// @param[in] templ Template of the path to the directory with XXXXXX +/// which would be replaced by random chars. /// @param[out] path Path to created directory for success, undefined for /// failure. /// @return `0` for success, non-zero for failure. -int os_mkdtemp(const char *template, char *path) +int os_mkdtemp(const char *templ, char *path) FUNC_ATTR_NONNULL_ALL { uv_fs_t request; fs_loop_lock(); - int result = uv_fs_mkdtemp(&fs_loop, &request, template, NULL); + int result = uv_fs_mkdtemp(&fs_loop, &request, templ, NULL); fs_loop_unlock(); if (result == kLibuvSuccess) { xstrlcpy(path, request.path, TEMP_FILE_PATH_MAXLEN); -- cgit From f39b33ee491a4a8d4b08425e582dd0dd53617edf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Apr 2023 11:46:17 +0800 Subject: vim-patch:9.0.0411: only created files can be cleaned up with one call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Only created files can be cleaned up with one call. Solution: Add flags to mkdir() to delete with a deferred function. Expand the writefile() name to a full path to handle changing directory. https://github.com/vim/vim/commit/6f14da15ac900589f2f413d77898b9bff3b31ece vim-patch:8.2.3742: dec mouse test fails without gnome terminfo entry Problem: Dec mouse test fails without gnome terminfo entry. Solution: Check if there is a gnome entry. Also fix 'acd' test on MS-Windows. (Dominique Pellé, closes vim/vim#9282) https://github.com/vim/vim/commit/f589fd3e1047cdf90566b68aaf9a13389e54d26a Cherry-pick test_autochdir.vim changes from patch 9.0.0313. Cherry-pick test_autocmd.vim changes from patch 9.0.0323. Co-authored-by: Bram Moolenaar --- src/nvim/os/fs.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index cb51e81005..872d9c9314 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -937,10 +937,13 @@ int os_mkdir(const char *path, int32_t mode) /// the name of the directory which os_mkdir_recurse /// failed to create. I.e. it will contain dir or any /// of the higher level directories. +/// @param[out] created Set to the full name of the first created directory. +/// It will be NULL until that happens. /// /// @return `0` for success, libuv error code for failure. -int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_dir) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT +int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_dir, + char **const created) + FUNC_ATTR_NONNULL_ARG(1, 3) FUNC_ATTR_WARN_UNUSED_RESULT { // Get end of directory name in "dir". // We're done when it's "/" or "c:/". @@ -975,6 +978,8 @@ int os_mkdir_recurse(const char *const dir, int32_t mode, char **const failed_di if ((ret = os_mkdir(curdir, mode)) != 0) { *failed_dir = curdir; return ret; + } else if (created != NULL && *created == NULL) { + *created = FullName_save(curdir, false); } } xfree(curdir); @@ -1002,7 +1007,7 @@ int os_file_mkdir(char *fname, int32_t mode) *tail = NUL; int r; char *failed_dir; - if (((r = os_mkdir_recurse(fname, mode, &failed_dir)) < 0)) { + if (((r = os_mkdir_recurse(fname, mode, &failed_dir, NULL)) < 0)) { semsg(_(e_mkdir), failed_dir, os_strerror(r)); xfree(failed_dir); } -- cgit From 5e569a47031d2a5b94cfadd67d5e76ba4651ac4d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 25 Apr 2023 13:39:28 +0200 Subject: refactor(fs): now it is time to get rid of fs_loop and fs_loop_mutex Here's the headline: when run in sync mode (last argument cb=NULL), these functions don't actually use the uv_loop_t. An earlier version of this patch instead replaced fs_loop with using main_loop.uv on the main thread and luv_loop() on luv worker threads. However this made the code more complicated for no reason. Also arbitrarily, half of these functions would attempt to handle UV_ENOMEM by try_to_free_memory(). This would mostly happen on windows because it needs to allocate a converted WCHAR buffer. This should be a quite rare situation. Your system is pretty much hosed already if you cannot allocate like 50 WCHAR:s. Therefore, take the liberty of simply removing this fallback. In addition, we tried to "recover" from ENOMEM in read()/readv() this way which doesn't make any sense. The read buffer(s) are already allocated at this point. This would also be an issue when using these functions on a worker thread, as try_to_free_memory() is not thread-safe. Currently os_file_is_readable() and os_is_dir() is used by worker threads (as part of nvim__get_runtime(), to implement require from 'rtp' in threads). In the end, these changes makes _all_ os/fs.c functions thread-safe, and we thus don't need to document and maintain a thread-safe subset. --- src/nvim/os/fs.c | 73 +++++++------------------------------------------------- 1 file changed, 9 insertions(+), 64 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 872d9c9314..b13afba727 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -20,6 +20,7 @@ #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/macros.h" +#include "nvim/main.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_defs.h" @@ -46,44 +47,13 @@ struct iovec; #define RUN_UV_FS_FUNC(ret, func, ...) \ do { \ - bool did_try_to_free = false; \ -uv_call_start: {} \ uv_fs_t req; \ - fs_loop_lock(); \ - ret = func(&fs_loop, &req, __VA_ARGS__); \ + ret = func(NULL, &req, __VA_ARGS__); \ uv_fs_req_cleanup(&req); \ - fs_loop_unlock(); \ - if (ret == UV_ENOMEM && !did_try_to_free) { \ - try_to_free_memory(); \ - did_try_to_free = true; \ - goto uv_call_start; \ - } \ } while (0) // Many fs functions from libuv return that value on success. static const int kLibuvSuccess = 0; -static uv_loop_t fs_loop; -static uv_mutex_t fs_loop_mutex; - -// Initialize the fs module -void fs_init(void) -{ - uv_loop_init(&fs_loop); - uv_mutex_init_recursive(&fs_loop_mutex); -} - -/// TODO(bfredl): some of these operations should -/// be possible to do the private libuv loop of the -/// thread, instead of contending the global fs loop -void fs_loop_lock(void) -{ - uv_mutex_lock(&fs_loop_mutex); -} - -void fs_loop_unlock(void) -{ - uv_mutex_unlock(&fs_loop_mutex); -} /// Changes the current directory to `path`. /// @@ -122,12 +92,9 @@ bool os_isrealdir(const char *name) FUNC_ATTR_NONNULL_ALL { uv_fs_t request; - fs_loop_lock(); - if (uv_fs_lstat(&fs_loop, &request, name, NULL) != kLibuvSuccess) { - fs_loop_unlock(); + if (uv_fs_lstat(NULL, &request, name, NULL) != kLibuvSuccess) { return false; } - fs_loop_unlock(); if (S_ISLNK(request.statbuf.st_mode)) { return false; } @@ -566,7 +533,6 @@ ptrdiff_t os_read(const int fd, bool *const ret_eof, char *const ret_buf, const return 0; } size_t read_bytes = 0; - bool did_try_to_free = false; while (read_bytes != size) { assert(size >= read_bytes); const ptrdiff_t cur_read_bytes = read(fd, ret_buf + read_bytes, @@ -581,10 +547,6 @@ ptrdiff_t os_read(const int fd, bool *const ret_eof, char *const ret_buf, const break; } else if (error == UV_EINTR || error == UV_EAGAIN) { continue; - } else if (error == UV_ENOMEM && !did_try_to_free) { - try_to_free_memory(); - did_try_to_free = true; - continue; } else { return (ptrdiff_t)error; } @@ -618,7 +580,6 @@ ptrdiff_t os_readv(const int fd, bool *const ret_eof, struct iovec *iov, size_t { *ret_eof = false; size_t read_bytes = 0; - bool did_try_to_free = false; size_t toread = 0; for (size_t i = 0; i < iov_size; i++) { // Overflow, trying to read too much data @@ -650,10 +611,6 @@ ptrdiff_t os_readv(const int fd, bool *const ret_eof, struct iovec *iov, size_t break; } else if (error == UV_EINTR || error == UV_EAGAIN) { continue; - } else if (error == UV_ENOMEM && !did_try_to_free) { - try_to_free_memory(); - did_try_to_free = true; - continue; } else { return (ptrdiff_t)error; } @@ -742,9 +699,7 @@ static int os_stat(const char *name, uv_stat_t *statbuf) return UV_EINVAL; } uv_fs_t request; - fs_loop_lock(); - int result = uv_fs_stat(&fs_loop, &request, name, NULL); - fs_loop_unlock(); + int result = uv_fs_stat(NULL, &request, name, NULL); if (result == kLibuvSuccess) { *statbuf = request.statbuf; } @@ -1028,9 +983,7 @@ int os_mkdtemp(const char *templ, char *path) FUNC_ATTR_NONNULL_ALL { uv_fs_t request; - fs_loop_lock(); - int result = uv_fs_mkdtemp(&fs_loop, &request, templ, NULL); - fs_loop_unlock(); + int result = uv_fs_mkdtemp(NULL, &request, templ, NULL); if (result == kLibuvSuccess) { xstrlcpy(path, request.path, TEMP_FILE_PATH_MAXLEN); } @@ -1057,9 +1010,7 @@ int os_rmdir(const char *path) bool os_scandir(Directory *dir, const char *path) FUNC_ATTR_NONNULL_ALL { - fs_loop_lock(); - int r = uv_fs_scandir(&fs_loop, &dir->request, path, 0, NULL); - fs_loop_unlock(); + int r = uv_fs_scandir(NULL, &dir->request, path, 0, NULL); if (r < 0) { os_closedir(dir); } @@ -1120,9 +1071,7 @@ bool os_fileinfo_link(const char *path, FileInfo *file_info) return false; } uv_fs_t request; - fs_loop_lock(); - bool ok = uv_fs_lstat(&fs_loop, &request, path, NULL) == kLibuvSuccess; - fs_loop_unlock(); + bool ok = uv_fs_lstat(NULL, &request, path, NULL) == kLibuvSuccess; if (ok) { file_info->stat = request.statbuf; } @@ -1140,8 +1089,7 @@ bool os_fileinfo_fd(int file_descriptor, FileInfo *file_info) { uv_fs_t request; CLEAR_POINTER(file_info); - fs_loop_lock(); - bool ok = uv_fs_fstat(&fs_loop, + bool ok = uv_fs_fstat(NULL, &request, file_descriptor, NULL) == kLibuvSuccess; @@ -1149,7 +1097,6 @@ bool os_fileinfo_fd(int file_descriptor, FileInfo *file_info) file_info->stat = request.statbuf; } uv_fs_req_cleanup(&request); - fs_loop_unlock(); return ok; } @@ -1266,8 +1213,7 @@ char *os_realpath(const char *name, char *buf) FUNC_ATTR_NONNULL_ARG(1) { uv_fs_t request; - fs_loop_lock(); - int result = uv_fs_realpath(&fs_loop, &request, name, NULL); + int result = uv_fs_realpath(NULL, &request, name, NULL); if (result == kLibuvSuccess) { if (buf == NULL) { buf = xmallocz(MAXPATHL); @@ -1275,7 +1221,6 @@ char *os_realpath(const char *name, char *buf) xstrlcpy(buf, request.ptr, MAXPATHL + 1); } uv_fs_req_cleanup(&request); - fs_loop_unlock(); return result == kLibuvSuccess ? buf : NULL; } -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index b13afba727..d270f8767e 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -339,7 +339,7 @@ static bool is_executable_in_path(const char *name, char **abspath) // is an executable file. char *p = path; bool rv = false; - for (;;) { + while (true) { char *e = xstrchrnul(p, ENV_SEPCHAR); // Combine the $PATH segment with `name`. -- cgit From f5d12889e80d3369359b8248806694cf6d21f820 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:00:32 +0200 Subject: refactor: adjust headers according to the style guide (#23934) System headers should be included first to prevent naming conflicts. --- src/nvim/os/fs.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index d270f8767e..6c3eca8961 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -14,6 +14,19 @@ #include #include +#ifdef MSWIN +# include +#endif + +#if defined(HAVE_ACL) +# ifdef HAVE_SYS_ACL_H +# include +# endif +# ifdef HAVE_SYS_ACCESS_H +# include +# endif +#endif + #include "auto/config.h" #include "nvim/ascii.h" #include "nvim/gettext.h" @@ -731,15 +744,6 @@ int os_setperm(const char *const name, int perm) return (r == kLibuvSuccess ? OK : FAIL); } -#if defined(HAVE_ACL) -# ifdef HAVE_SYS_ACL_H -# include -# endif -# ifdef HAVE_SYS_ACCESS_H -# include -# endif -#endif - // Return a pointer to the ACL of file "fname" in allocated memory. // Return NULL if the ACL is not available for whatever reason. vim_acl_T os_get_acl(const char *fname) @@ -1225,8 +1229,6 @@ char *os_realpath(const char *name, char *buf) } #ifdef MSWIN -# include - /// When "fname" is the name of a shortcut (*.lnk) resolve the file it points /// to and return that name in allocated memory. /// Otherwise NULL is returned. -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 6c3eca8961..c95b5defaa 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -76,7 +76,7 @@ int os_chdir(const char *path) { if (p_verbose >= 5) { verbose_enter(); - smsg("chdir(%s)", path); + smsg(0, "chdir(%s)", path); verbose_leave(); } return uv_chdir(path); -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/os/fs.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index c95b5defaa..400284606f 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -33,7 +33,6 @@ #include "nvim/globals.h" #include "nvim/log.h" #include "nvim/macros.h" -#include "nvim/main.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_defs.h" -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 400284606f..77c4766419 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -35,7 +35,7 @@ #include "nvim/macros.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/fs_defs.h" #include "nvim/os/os.h" #include "nvim/path.h" -- cgit From f6e72c3dfed83b02483976eaedb27819df9a878d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 19:14:24 +0800 Subject: vim-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: vim/vim#306 closes: vim/vim#13203 https://github.com/vim/vim/commit/e085dfda5d8dde064b0332464040959479696d1c Co-authored-by: Christian Brabandt --- src/nvim/os/fs.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 77c4766419..3efb575039 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -18,6 +18,8 @@ # include #endif +#include "auto/config.h" + #if defined(HAVE_ACL) # ifdef HAVE_SYS_ACL_H # include @@ -27,7 +29,11 @@ # endif #endif -#include "auto/config.h" +#ifdef HAVE_XATTR +# include +# define XATTR_VAL_LEN 1024 +#endif + #include "nvim/ascii.h" #include "nvim/gettext.h" #include "nvim/globals.h" @@ -55,6 +61,17 @@ # include "os/fs.c.generated.h" #endif +#ifdef HAVE_XATTR +static const char e_xattr_erange[] + = N_("E1506: Buffer too small to copy xattr value or key"); +static const char e_xattr_enotsup[] + = N_("E1507: Extended attributes are not supported by the filesystem"); +static const char e_xattr_e2big[] + = N_("E1508: size of the extended attribute value is larger than the maximum size allowed"); +static const char e_xattr_other[] + = N_("E1509: error occured when reading or writing extended attribute"); +#endif + struct iovec; #define RUN_UV_FS_FUNC(ret, func, ...) \ @@ -743,6 +760,84 @@ int os_setperm(const char *const name, int perm) return (r == kLibuvSuccess ? OK : FAIL); } +#ifdef HAVE_XATTR +/// Copy extended attributes from_file to to_file +void os_copy_xattr(const char *from_file, const char *to_file) +{ + if (from_file == NULL) { + return; + } + + // get the length of the extended attributes + ssize_t size = listxattr((char *)from_file, NULL, 0); + // not supported or no attributes to copy + if (errno == ENOTSUP || size <= 0) { + return; + } + char *xattr_buf = xmalloc((size_t)size); + size = listxattr(from_file, xattr_buf, (size_t)size); + ssize_t tsize = size; + + errno = 0; + + ssize_t max_vallen = 0; + char *val = NULL; + const char *errmsg = NULL; + + for (int round = 0; round < 2; round++) { + char *key = xattr_buf; + if (round == 1) { + size = tsize; + } + + while (size > 0) { + ssize_t vallen = getxattr(from_file, key, val, round ? (size_t)max_vallen : 0); + // only set the attribute in the second round + if (vallen >= 0 && round + && setxattr(to_file, key, val, (size_t)vallen, 0) == 0) { + // + } else if (errno) { + switch (errno) { + case E2BIG: + errmsg = e_xattr_e2big; + goto error_exit; + case ENOTSUP: + errmsg = e_xattr_enotsup; + goto error_exit; + case ERANGE: + errmsg = e_xattr_erange; + goto error_exit; + default: + errmsg = e_xattr_other; + goto error_exit; + } + } + + if (round == 0 && vallen > max_vallen) { + max_vallen = vallen; + } + + // add one for terminating null + ssize_t keylen = (ssize_t)strlen(key) + 1; + size -= keylen; + key += keylen; + } + if (round) { + break; + } + + val = xmalloc((size_t)max_vallen + 1); + } +error_exit: + xfree(xattr_buf); + xfree(val); + + if (errmsg != NULL) { + emsg(errmsg); + } +} +#endif + // Return a pointer to the ACL of file "fname" in allocated memory. // Return NULL if the ACL is not available for whatever reason. vim_acl_T os_get_acl(const char *fname) -- cgit From 5c60fbe9db0005d10d87ba60a981fd41f85f8df5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 21:19:12 +0800 Subject: vim-patch:9.0.1963: Configure script may not detect xattr Problem: Configure script may not detect xattr correctly Solution: include sys/xattr instead of attr/xattr, make Test_write_with_xattr_support() test xattr feature correctly This also applies to the Smack security feature, so change the include and configure script for it as well. closes: vim/vim#13229 https://github.com/vim/vim/commit/6de4e58cf27a3bb6e81653ca63b77e29d1bb46f2 --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 3efb575039..93cc7de040 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -30,7 +30,7 @@ #endif #ifdef HAVE_XATTR -# include +# include # define XATTR_VAL_LEN 1024 #endif -- cgit From 248305cf377de6710daa89a92eb8605fa5dcbb1f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 1 Oct 2023 06:08:47 +0800 Subject: vim-patch:9.0.1964: xattr support fails to build on MacOS X (#25448) Problem: xattr support fails to build on MacOS X Solution: Disable xattr support for MacOS X MacOS X uses the same headers and functions sys/xattr.h but the function signatures for xattr support are much different, so building fails. So let's for now disable xattr support there. closes: vim/vim#13230 closes: vim/vim#13232 https://github.com/vim/vim/commit/a4dfbfed89e26a766e30cca62c18e710eec81c3f Co-authored-by: Christian Brabandt --- src/nvim/os/fs.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 93cc7de040..de7996e51b 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -31,7 +31,6 @@ #ifdef HAVE_XATTR # include -# define XATTR_VAL_LEN 1024 #endif #include "nvim/ascii.h" -- cgit From 2da66f1f710523548ca0746d5f7ef945de6d8f6a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 1 Oct 2023 16:29:55 +0800 Subject: vim-patch:9.0.1967: xattr errors not translated (#25454) Problem: xattr errors not translated Solution: mark for translation, consistently capitalize first letter. closes: vim/vim#13236 https://github.com/vim/vim/commit/7ece036d72cf639b05d3936183220bec7179bf63 --- src/nvim/os/fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index de7996e51b..476ede2046 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -66,9 +66,9 @@ static const char e_xattr_erange[] static const char e_xattr_enotsup[] = N_("E1507: Extended attributes are not supported by the filesystem"); static const char e_xattr_e2big[] - = N_("E1508: size of the extended attribute value is larger than the maximum size allowed"); + = N_("E1508: Size of the extended attribute value is larger than the maximum size allowed"); static const char e_xattr_other[] - = N_("E1509: error occured when reading or writing extended attribute"); + = N_("E1509: Error occured when reading or writing extended attribute"); #endif struct iovec; @@ -832,7 +832,7 @@ error_exit: xfree(val); if (errmsg != NULL) { - emsg(errmsg); + emsg(_(errmsg)); } } #endif -- cgit From 3c76038755b5c0c63604f2baa481491bb0efe2e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 3 Oct 2023 07:45:51 +0800 Subject: vim-patch:9.0.1975: xattr: permission-denied errors on write (#25478) Problem: xattr: permission-denied errors on write Solution: ignore those errors closes: vim/vim#13246 https://github.com/vim/vim/commit/993b17569b5acffe2d8941d1709a55da4e439755 N/A patches: vim-patch:9.0.1965: wrong auto/configure script vim-patch:9.0.1966: configure prints stray 6 when checking libruby Co-authored-by: Gene C --- src/nvim/os/fs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 476ede2046..2712b874bb 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -63,8 +63,6 @@ #ifdef HAVE_XATTR static const char e_xattr_erange[] = N_("E1506: Buffer too small to copy xattr value or key"); -static const char e_xattr_enotsup[] - = N_("E1507: Extended attributes are not supported by the filesystem"); static const char e_xattr_e2big[] = N_("E1508: Size of the extended attribute value is larger than the maximum size allowed"); static const char e_xattr_other[] @@ -800,9 +798,9 @@ void os_copy_xattr(const char *from_file, const char *to_file) case E2BIG: errmsg = e_xattr_e2big; goto error_exit; - case ENOTSUP: - errmsg = e_xattr_enotsup; - goto error_exit; + case EACCES: + case EPERM: + break; case ERANGE: errmsg = e_xattr_erange; goto error_exit; -- cgit From 3222f0ad0079ce4bd4e45886a00e4fe4685fb5dd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 16 Oct 2023 16:36:25 +0800 Subject: vim-patch:dbf749bd5aae (#25665) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit runtime: Fix more typos (vim/vim#13354) * Fix more typos * Fix typos in ignored runtime/ directory https://github.com/vim/vim/commit/dbf749bd5aaef6ea2d28bce081349785d174d96a Co-authored-by: Viktor Szépe --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 2712b874bb..9a448d69ae 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -66,7 +66,7 @@ static const char e_xattr_erange[] static const char e_xattr_e2big[] = N_("E1508: Size of the extended attribute value is larger than the maximum size allowed"); static const char e_xattr_other[] - = N_("E1509: Error occured when reading or writing extended attribute"); + = N_("E1509: Error occurred when reading or writing extended attribute"); #endif struct iovec; -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/os/fs.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 9a448d69ae..6b3f79abb2 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // fs.c -- filesystem access #include #include -- cgit From 4ce3159e24e18ccd53400f7066a54e01561cf586 Mon Sep 17 00:00:00 2001 From: Nik Klassen Date: Thu, 23 Nov 2023 16:28:52 -0500 Subject: fix: missing case in setxattr error handling (#26176) ENOTSUP case is present in vim, but doesn't appear to have included here. --- src/nvim/os/fs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 6b3f79abb2..e2a6136ab4 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -795,6 +795,7 @@ void os_copy_xattr(const char *from_file, const char *to_file) case E2BIG: errmsg = e_xattr_e2big; goto error_exit; + case ENOTSUP: case EACCES: case EPERM: break; -- cgit From a827003e3052c6d9ee7bdb71518182e9bd76317d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 25 Nov 2023 11:32:32 +0100 Subject: build: rework IWYU mapping files Create mapping to most of the C spec and some POSIX specific functions. This is more robust than relying files shipped with IWYU. --- src/nvim/os/fs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index e2a6136ab4..82916eca7b 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #ifdef MSWIN -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 82916eca7b..b9448ddf4b 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -17,6 +17,7 @@ #endif #include "auto/config.h" +#include "nvim/os/fs.h" #if defined(HAVE_ACL) # ifdef HAVE_SYS_ACL_H @@ -39,7 +40,6 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" -#include "nvim/os/fs_defs.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/types.h" -- cgit From 40139738eb479d0913ec6ce751ca5adfa50ad8c3 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 26 Nov 2023 21:36:02 +0100 Subject: build: enable IWYU on mac --- src/nvim/os/fs.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index b9448ddf4b..4721bc3f1c 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -67,8 +67,6 @@ static const char e_xattr_other[] = N_("E1509: Error occurred when reading or writing extended attribute"); #endif -struct iovec; - #define RUN_UV_FS_FUNC(ret, func, ...) \ do { \ uv_fs_t req; \ -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/os/fs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4721bc3f1c..4e320a79c4 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -17,6 +17,7 @@ #endif #include "auto/config.h" +#include "nvim/func_attr.h" #include "nvim/os/fs.h" #if defined(HAVE_ACL) -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/os/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 4e320a79c4..16151086c7 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -43,7 +43,7 @@ #include "nvim/option_vars.h" #include "nvim/os/os.h" #include "nvim/path.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/vim.h" #ifdef HAVE_SYS_UIO_H -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/os/fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 16151086c7..3fc9e0ab69 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -33,18 +33,18 @@ # include #endif -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/log.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/types_defs.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef HAVE_SYS_UIO_H # include -- cgit From 86cc791debba09c8ed1aa0d863be844108866a38 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 23:10:21 +0800 Subject: refactor: move function macros out of vim_defs.h (#26300) --- src/nvim/os/fs.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/os/fs.c') diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index 3fc9e0ab69..8f939c3b40 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -53,6 +53,7 @@ #ifdef MSWIN # include "nvim/mbyte.h" # include "nvim/option.h" +# include "nvim/strings.h" #endif #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit