aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/fileio.c6
-rw-r--r--src/nvim/os/fs.c9
2 files changed, 12 insertions, 3 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 245590e7ce..b2d27bd0d1 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2712,7 +2712,7 @@ buf_write (
* - it's a symbolic link
* - we don't have write permission in the directory
*/
- if (file_info_old.stat.st_nlink > 1
+ if (os_fileinfo_hardlinks(&file_info_old) > 1
|| !os_get_file_info_link((char *)fname, &file_info)
|| !os_file_info_id_equal(&file_info, &file_info_old)) {
backup_copy = TRUE;
@@ -2770,7 +2770,7 @@ buf_write (
/* Hardlinks. */
if ((bkc_flags & BKC_BREAKHARDLINK)
- && file_info_old.stat.st_nlink > 1
+ && os_fileinfo_hardlinks(&file_info_old) > 1
&& (!file_info_link_ok
|| os_file_info_id_equal(&file_info, &file_info_old))) {
backup_copy = FALSE;
@@ -3201,7 +3201,7 @@ nobackup:
FileInfo file_info;
/* Don't delete the file when it's a hard or symbolic link. */
- if ((!newfile && file_info_old.stat.st_nlink > 1)
+ if ((!newfile && os_fileinfo_hardlinks(&file_info) > 1)
|| (os_get_file_info_link((char *)fname, &file_info)
&& !os_file_info_id_equal(&file_info, &file_info_old))) {
errmsg = (char_u *)_("E166: Can't open linked file for writing");
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index 9347afb9bc..70a53edb1c 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -403,6 +403,15 @@ off_t os_fileinfo_size(const FileInfo *file_info)
return file_info->stat.st_size;
}
+/// Get the number of hardlinks from a `FileInfo`.
+///
+/// @return number of hardlinks.
+uint64_t os_fileinfo_hardlinks(const FileInfo *file_info)
+ FUNC_ATTR_NONNULL_ALL
+{
+ return file_info->stat.st_nlink;
+}
+
/// Get the `FileID` for a given path
///
/// @param path Path to the file.