mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
fileinfo: implement os_fileinfo_blocksize
This commit is contained in:
@@ -123,10 +123,11 @@ memfile_T *mf_open(char_u *fname, int flags)
|
|||||||
*/
|
*/
|
||||||
FileInfo file_info;
|
FileInfo file_info;
|
||||||
if (mfp->mf_fd >= 0
|
if (mfp->mf_fd >= 0
|
||||||
&& os_get_file_info_fd(mfp->mf_fd, &file_info)
|
&& os_get_file_info_fd(mfp->mf_fd, &file_info)) {
|
||||||
&& file_info.stat.st_blksize >= MIN_SWAP_PAGE_SIZE
|
uint64_t blocksize = os_fileinfo_blocksize(&file_info);
|
||||||
&& file_info.stat.st_blksize <= MAX_SWAP_PAGE_SIZE) {
|
if (blocksize >= MIN_SWAP_PAGE_SIZE && blocksize <= MAX_SWAP_PAGE_SIZE) {
|
||||||
mfp->mf_page_size = file_info.stat.st_blksize;
|
mfp->mf_page_size = blocksize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mfp->mf_fd < 0 || (flags & (O_TRUNC|O_EXCL))
|
if (mfp->mf_fd < 0 || (flags & (O_TRUNC|O_EXCL))
|
||||||
|
@@ -412,6 +412,15 @@ uint64_t os_fileinfo_hardlinks(const FileInfo *file_info)
|
|||||||
return file_info->stat.st_nlink;
|
return file_info->stat.st_nlink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the blocksize from a `FileInfo`.
|
||||||
|
///
|
||||||
|
/// @return blocksize in bytes.
|
||||||
|
uint64_t os_fileinfo_blocksize(const FileInfo *file_info)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
return file_info->stat.st_blksize;
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@@ -625,6 +625,27 @@ describe('fs function', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('os_fileinfo_blocksize', function()
|
||||||
|
it('returns the correct blocksize of a file', function()
|
||||||
|
local path = 'unit-test-directory/test.file'
|
||||||
|
-- there is a bug in luafilesystem where
|
||||||
|
-- `lfs.attributes path, 'blksize'` returns the worng value:
|
||||||
|
-- https://github.com/keplerproject/luafilesystem/pull/44
|
||||||
|
-- using this workaround for now:
|
||||||
|
local blksize = lfs.attributes(path).blksize
|
||||||
|
local file_info = file_info_new()
|
||||||
|
assert.is_true(fs.os_get_file_info(path, file_info))
|
||||||
|
if blksize then
|
||||||
|
eq(blksize, fs.os_fileinfo_blocksize(file_info))
|
||||||
|
else
|
||||||
|
-- luafs dosn't support blksize on windows
|
||||||
|
-- libuv on windows returns a constant value as blocksize
|
||||||
|
-- checking for this constant value should be enough
|
||||||
|
eq(2048, fs.os_fileinfo_blocksize(file_info))
|
||||||
|
end
|
||||||
|
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()
|
||||||
|
Reference in New Issue
Block a user