refactor
This commit is contained in:
@ -113,7 +113,9 @@ auto remote_server::fuse_access(const char *path, const std::int32_t &mask)
|
|||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
const auto windows_mask = utils::unix_access_mask_to_windows(mask);
|
const auto windows_mask = utils::unix_access_mask_to_windows(mask);
|
||||||
const auto res = _access(file_path.c_str(), windows_mask);
|
auto res{
|
||||||
|
_access(file_path.c_str(), windows_mask),
|
||||||
|
};
|
||||||
const auto ret = ((res < 0) ? -errno : 0);
|
const auto ret = ((res < 0) ? -errno : 0);
|
||||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
||||||
return ret;
|
return ret;
|
||||||
@ -188,7 +190,9 @@ auto remote_server::fuse_fgetattr(
|
|||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
memset(&r_stat, 0, sizeof(remote::stat));
|
memset(&r_stat, 0, sizeof(remote::stat));
|
||||||
|
|
||||||
auto res = has_compat_open_info(handle, EBADF);
|
auto res{
|
||||||
|
has_compat_open_info(handle, EBADF),
|
||||||
|
};
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
directory = utils::file::directory(file_path).exists();
|
directory = utils::file::directory(file_path).exists();
|
||||||
struct _stat64 unix_st {};
|
struct _stat64 unix_st {};
|
||||||
@ -225,7 +229,9 @@ auto remote_server::fuse_fsync(
|
|||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
|
|
||||||
auto res = has_compat_open_info(handle, EBADF);
|
auto res{
|
||||||
|
has_compat_open_info(handle, EBADF),
|
||||||
|
};
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
res = -1;
|
res = -1;
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
@ -254,7 +260,9 @@ auto remote_server::fuse_ftruncate(
|
|||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
|
|
||||||
auto res = has_compat_open_info(handle, EBADF);
|
auto res{
|
||||||
|
has_compat_open_info(handle, EBADF),
|
||||||
|
};
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
res = -1;
|
res = -1;
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
@ -289,7 +297,9 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_st,
|
|||||||
directory = utils::file::directory(file_path).exists();
|
directory = utils::file::directory(file_path).exists();
|
||||||
|
|
||||||
struct _stat64 st1 {};
|
struct _stat64 st1 {};
|
||||||
const auto res = _stat64(file_path.c_str(), &st1);
|
auto res{
|
||||||
|
_stat64(file_path.c_str(), &st1),
|
||||||
|
};
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
populate_stat(path, directory, r_st, st1);
|
populate_stat(path, directory, r_st, st1);
|
||||||
}
|
}
|
||||||
@ -349,7 +359,9 @@ auto remote_server::fuse_mkdir(const char *path,
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
const auto res = _mkdir(file_path.c_str());
|
auto res{
|
||||||
|
_mkdir(file_path.c_str()),
|
||||||
|
};
|
||||||
const auto ret = ((res < 0) ? -errno : 0);
|
const auto ret = ((res < 0) ? -errno : 0);
|
||||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
||||||
return ret;
|
return ret;
|
||||||
@ -363,7 +375,7 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
|
|||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
const auto unicode_file_path = utils::string::from_utf8(file_path);
|
const auto unicode_file_path = utils::string::from_utf8(file_path);
|
||||||
auto res = -1;
|
auto res{-1};
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
|
|
||||||
if (::PathIsDirectoryW(unicode_file_path.c_str()) != 0) {
|
if (::PathIsDirectoryW(unicode_file_path.c_str()) != 0) {
|
||||||
@ -406,8 +418,9 @@ auto remote_server::fuse_create(const char *path, const remote::file_mode &mode,
|
|||||||
ret = -EACCES;
|
ret = -EACCES;
|
||||||
} else {
|
} else {
|
||||||
int file = -1;
|
int file = -1;
|
||||||
const auto res =
|
auto res{
|
||||||
_sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, perms);
|
_sopen_s(&file, file_path.c_str(), open_flags, _SH_DENYNO, perms),
|
||||||
|
};
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
handle = static_cast<remote::file_handle>(file);
|
handle = static_cast<remote::file_handle>(file);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -429,7 +442,7 @@ auto remote_server::fuse_open(const char *path, const remote::open_flags &flags,
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
auto res = -1;
|
auto res{-1};
|
||||||
|
|
||||||
if ((flags & remote::open_flags::directory) ==
|
if ((flags & remote::open_flags::directory) ==
|
||||||
remote::open_flags::directory) {
|
remote::open_flags::directory) {
|
||||||
@ -464,13 +477,13 @@ auto remote_server::fuse_read(
|
|||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
auto &data = *reinterpret_cast<data_buffer *>(buffer);
|
auto &data = *reinterpret_cast<data_buffer *>(buffer);
|
||||||
auto res = 0;
|
auto res{0};
|
||||||
if (read_size > std::numeric_limits<std::size_t>::max()) {
|
if (read_size > std::numeric_limits<std::size_t>::max()) {
|
||||||
res = -1;
|
res = -1;
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
} else if ((res = has_compat_open_info(handle, EBADF)) == 0) {
|
} else if ((res = has_compat_open_info(handle, EBADF)) == 0) {
|
||||||
res = _lseeki64(static_cast<int>(handle), static_cast<__int64>(read_offset),
|
res = static_cast<std::decay(res)>(_lseeki64(
|
||||||
SEEK_SET);
|
static_cast<int>(handle), static_cast<__int64>(read_offset), SEEK_SET));
|
||||||
if (res != -1) {
|
if (res != -1) {
|
||||||
data.resize(read_size);
|
data.resize(read_size);
|
||||||
res = read(static_cast<int>(handle), data.data(),
|
res = read(static_cast<int>(handle), data.data(),
|
||||||
@ -498,7 +511,9 @@ auto remote_server::fuse_rename(const char *from,
|
|||||||
|
|
||||||
const auto from_path = utils::path::combine(mount_location_, {from});
|
const auto from_path = utils::path::combine(mount_location_, {from});
|
||||||
const auto to_path = utils::path::combine(mount_location_, {to});
|
const auto to_path = utils::path::combine(mount_location_, {to});
|
||||||
const auto res = rename(from_path.c_str(), to_path.c_str());
|
auto res{
|
||||||
|
rename(from_path.c_str(), to_path.c_str()),
|
||||||
|
};
|
||||||
|
|
||||||
const auto ret = ((res < 0) ? -errno : 0);
|
const auto ret = ((res < 0) ? -errno : 0);
|
||||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, from + std::string("|") + to,
|
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, from + std::string("|") + to,
|
||||||
@ -516,15 +531,16 @@ auto remote_server::fuse_write(
|
|||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
std::size_t bytes_written{};
|
std::size_t bytes_written{};
|
||||||
auto res = 0;
|
auto res{0};
|
||||||
if (write_size > std::numeric_limits<std::size_t>::max()) {
|
if (write_size > std::numeric_limits<std::size_t>::max()) {
|
||||||
res = -1;
|
res = -1;
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
} else {
|
} else {
|
||||||
res = has_compat_open_info(handle, EBADF);
|
res = has_compat_open_info(handle, EBADF);
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
res = _lseeki64(static_cast<int>(handle),
|
res = static_cast<std::decay(res)>(
|
||||||
static_cast<__int64>(write_offset), SEEK_SET);
|
_lseeki64(static_cast<int>(handle),
|
||||||
|
static_cast<__int64>(write_offset), SEEK_SET));
|
||||||
if (res != -1) {
|
if (res != -1) {
|
||||||
res = write(static_cast<int>(handle), buffer,
|
res = write(static_cast<int>(handle), buffer,
|
||||||
static_cast<unsigned int>(write_size));
|
static_cast<unsigned int>(write_size));
|
||||||
@ -560,7 +576,7 @@ auto remote_server::fuse_readdir(const char *path,
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
auto res = 0;
|
auto res{0};
|
||||||
if (offset > std::numeric_limits<std::size_t>::max()) {
|
if (offset > std::numeric_limits<std::size_t>::max()) {
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
res = -1;
|
res = -1;
|
||||||
@ -588,7 +604,9 @@ auto remote_server::fuse_release(
|
|||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
|
|
||||||
remove_compat_open_info(handle);
|
remove_compat_open_info(handle);
|
||||||
const auto res = _close(static_cast<int>(handle));
|
auto res{
|
||||||
|
_close(static_cast<int>(handle)),
|
||||||
|
};
|
||||||
|
|
||||||
const auto ret = ((res < 0) ? -errno : 0);
|
const auto ret = ((res < 0) ? -errno : 0);
|
||||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
||||||
@ -620,7 +638,9 @@ auto remote_server::fuse_rmdir(const char *path) -> packet::error_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
const auto res = _rmdir(file_path.c_str());
|
auto res{
|
||||||
|
_rmdir(file_path.c_str()),
|
||||||
|
};
|
||||||
const auto ret = ((res < 0) ? -errno : 0);
|
const auto ret = ((res < 0) ? -errno : 0);
|
||||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
||||||
return ret;
|
return ret;
|
||||||
@ -761,7 +781,7 @@ auto remote_server::fuse_truncate(
|
|||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
const auto unicode_file_path = utils::string::from_utf8(file_path);
|
const auto unicode_file_path = utils::string::from_utf8(file_path);
|
||||||
auto res = -1;
|
auto res{-1};
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
|
|
||||||
const auto flags_and_attributes =
|
const auto flags_and_attributes =
|
||||||
@ -796,7 +816,9 @@ auto remote_server::fuse_unlink(const char *path) -> packet::error_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
const auto res = _unlink(file_path.c_str());
|
auto res{
|
||||||
|
_unlink(file_path.c_str()),
|
||||||
|
};
|
||||||
const auto ret = ((res < 0) ? -errno : 0);
|
const auto ret = ((res < 0) ? -errno : 0);
|
||||||
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
RAISE_REMOTE_WINFSP_SERVER_EVENT(function_name, file_path, ret);
|
||||||
return ret;
|
return ret;
|
||||||
@ -812,7 +834,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
|
|||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
const auto unicode_file_path = utils::string::from_utf8(file_path);
|
const auto unicode_file_path = utils::string::from_utf8(file_path);
|
||||||
|
|
||||||
auto res = -1;
|
auto res{-1};
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
|
|
||||||
const auto flags_and_attributes =
|
const auto flags_and_attributes =
|
||||||
@ -874,7 +896,7 @@ auto remote_server::json_create_directory_snapshot(
|
|||||||
|
|
||||||
const auto file_path = construct_path(path);
|
const auto file_path = construct_path(path);
|
||||||
|
|
||||||
auto res = -1;
|
auto res{-1};
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
|
|
||||||
if (utils::file::directory(file_path).exists()) {
|
if (utils::file::directory(file_path).exists()) {
|
||||||
@ -1481,4 +1503,4 @@ auto remote_server::winfsp_get_dir_buffer(PVOID /*file_desc*/, PVOID *& /*ptr*/)
|
|||||||
}
|
}
|
||||||
} // namespace repertory::remote_winfsp
|
} // namespace repertory::remote_winfsp
|
||||||
|
|
||||||
#endif // _WIN32
|
#endif // defined(_WIN32)
|
||||||
|
Reference in New Issue
Block a user