mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fileinfo: implement os_fileinfo_hardlinks
This commit is contained in:
parent
aa378acdf5
commit
e85fe0957d
@ -2712,7 +2712,7 @@ buf_write (
|
|||||||
* - it's a symbolic link
|
* - it's a symbolic link
|
||||||
* - we don't have write permission in the directory
|
* - 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_get_file_info_link((char *)fname, &file_info)
|
||||||
|| !os_file_info_id_equal(&file_info, &file_info_old)) {
|
|| !os_file_info_id_equal(&file_info, &file_info_old)) {
|
||||||
backup_copy = TRUE;
|
backup_copy = TRUE;
|
||||||
@ -2770,7 +2770,7 @@ buf_write (
|
|||||||
|
|
||||||
/* Hardlinks. */
|
/* Hardlinks. */
|
||||||
if ((bkc_flags & BKC_BREAKHARDLINK)
|
if ((bkc_flags & BKC_BREAKHARDLINK)
|
||||||
&& file_info_old.stat.st_nlink > 1
|
&& os_fileinfo_hardlinks(&file_info_old) > 1
|
||||||
&& (!file_info_link_ok
|
&& (!file_info_link_ok
|
||||||
|| os_file_info_id_equal(&file_info, &file_info_old))) {
|
|| os_file_info_id_equal(&file_info, &file_info_old))) {
|
||||||
backup_copy = FALSE;
|
backup_copy = FALSE;
|
||||||
@ -3201,7 +3201,7 @@ nobackup:
|
|||||||
FileInfo file_info;
|
FileInfo file_info;
|
||||||
|
|
||||||
/* Don't delete the file when it's a hard or symbolic link. */
|
/* 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_get_file_info_link((char *)fname, &file_info)
|
||||||
&& !os_file_info_id_equal(&file_info, &file_info_old))) {
|
&& !os_file_info_id_equal(&file_info, &file_info_old))) {
|
||||||
errmsg = (char_u *)_("E166: Can't open linked file for writing");
|
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;
|
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
|
/// Get the `FileID` for a given path
|
||||||
///
|
///
|
||||||
/// @param path Path to the file.
|
/// @param path Path to the file.
|
||||||
|
@ -47,6 +47,7 @@ describe('fs function', function()
|
|||||||
os.remove('unit-test-directory/test.file')
|
os.remove('unit-test-directory/test.file')
|
||||||
os.remove('unit-test-directory/test_2.file')
|
os.remove('unit-test-directory/test_2.file')
|
||||||
os.remove('unit-test-directory/test_link.file')
|
os.remove('unit-test-directory/test_link.file')
|
||||||
|
os.remove('unit-test-directory/test_hlink.file')
|
||||||
lfs.rmdir('unit-test-directory')
|
lfs.rmdir('unit-test-directory')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -611,6 +612,19 @@ describe('fs function', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('os_fileinfo_hardlinks', function()
|
||||||
|
it('returns the correct number of hardlinks', function()
|
||||||
|
local path = 'unit-test-directory/test.file'
|
||||||
|
local path_link = 'unit-test-directory/test_hlink.file'
|
||||||
|
local file_info = file_info_new()
|
||||||
|
assert.is_true(fs.os_get_file_info(path, file_info))
|
||||||
|
eq(1, fs.os_fileinfo_hardlinks(file_info))
|
||||||
|
lfs.link(path, path_link)
|
||||||
|
assert.is_true(fs.os_get_file_info(path, file_info))
|
||||||
|
eq(2, fs.os_fileinfo_hardlinks(file_info))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe('os_get_file_id', function()
|
describe('os_get_file_id', function()
|
||||||
it('returns false if given an non-existing file', function()
|
it('returns false if given an non-existing file', function()
|
||||||
local file_id = file_id_new()
|
local file_id = file_id_new()
|
||||||
|
Loading…
Reference in New Issue
Block a user