mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 05:58:33 +00:00
fileinfo: implement os_fileinfo_hardlinks
This commit is contained in:
@@ -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");
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user