Compare commits
3 Commits
1236bf1829
...
254578f4ab
Author | SHA1 | Date | |
---|---|---|---|
254578f4ab | |||
d5aa5c124c | |||
497b424840 |
@ -93,6 +93,7 @@ flarge
|
||||
fontconfig_version
|
||||
freetype2_version
|
||||
fsetattr_x
|
||||
futimens
|
||||
getxtimes
|
||||
glapi
|
||||
gmock
|
||||
|
@ -103,15 +103,15 @@ app_config::app_config(const provider_type &prov,
|
||||
hc_.api_password = get_provider_api_password(prov_);
|
||||
hc_.api_port = default_api_port(prov_);
|
||||
|
||||
if (not utils::file::create_directories(data_directory_)) {
|
||||
if (not utils::file::directory(data_directory_).create_directory()) {
|
||||
throw startup_exception("unable to create: " + data_directory_);
|
||||
}
|
||||
|
||||
if (not utils::file::create_directories(cache_directory_)) {
|
||||
if (not utils::file::directory(cache_directory_).create_directory()) {
|
||||
throw startup_exception("unable to create: " + cache_directory_);
|
||||
}
|
||||
|
||||
if (not utils::file::create_directories(log_directory_)) {
|
||||
if (not utils::file::directory(log_directory_).create_directory()) {
|
||||
throw startup_exception("unable to create: " + log_directory_);
|
||||
}
|
||||
|
||||
@ -547,7 +547,7 @@ auto app_config::load() -> bool {
|
||||
const auto config_file_path = get_config_file_path();
|
||||
std::cout << config_file_path << std::endl;
|
||||
recur_mutex_lock lock(read_write_mutex_);
|
||||
if (utils::file::is_file(config_file_path)) {
|
||||
if (utils::file::file(config_file_path).exists()) {
|
||||
try {
|
||||
std::ifstream config_file(config_file_path.data());
|
||||
if (config_file.is_open()) {
|
||||
@ -713,9 +713,9 @@ void app_config::save() {
|
||||
|
||||
const auto file_path = get_config_file_path();
|
||||
recur_mutex_lock lock(read_write_mutex_);
|
||||
if (config_changed_ || not utils::file::is_file(file_path)) {
|
||||
if (not utils::file::is_directory(data_directory_)) {
|
||||
if (not utils::file::create_directories(data_directory_)) {
|
||||
if (config_changed_ || not utils::file::file(file_path).exists()) {
|
||||
if (not utils::file::directory(data_directory_).exists()) {
|
||||
if (not utils::file::directory(data_directory_).create_directory()) {
|
||||
utils::error::raise_error(
|
||||
function_name, "failed to create directory|sp|" + data_directory_ +
|
||||
"|err|" +
|
||||
|
@ -38,14 +38,15 @@ auto eviction::check_minimum_requirements(const std::string &file_path)
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
std::uint64_t file_size{};
|
||||
if (not utils::file::get_file_size(file_path, file_size)) {
|
||||
auto opt_size = utils::file::file{file_path}.size();
|
||||
if (not opt_size.has_value()) {
|
||||
utils::error::raise_error(function_name, utils::get_last_error_code(),
|
||||
file_path, "failed to get file size");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ret = false;
|
||||
auto file_size{opt_size.value()};
|
||||
auto ret{false};
|
||||
if (file_size != 0U) {
|
||||
std::uint64_t reference_time{};
|
||||
ret = config_.get_eviction_uses_accessed_time()
|
||||
@ -110,9 +111,9 @@ void eviction::service_function() {
|
||||
if (provider_.get_filesystem_item_and_file(api_path, file, fsi) ==
|
||||
api_error::success) {
|
||||
// Only evict files that match expected size
|
||||
std::uint64_t file_size{};
|
||||
if (utils::file::get_file_size(cached_files_list.front(),
|
||||
file_size)) {
|
||||
auto opt_size = utils::file::file{cached_files_list.front()}.size();
|
||||
if (opt_size.has_value()) {
|
||||
auto file_size{opt_size.value()};
|
||||
if (file_size == fsi.size) {
|
||||
// Try to evict file
|
||||
if (fm_.evict_file(fsi.api_path) &&
|
||||
|
@ -163,7 +163,7 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
||||
{
|
||||
std::shared_ptr<i_open_file> open_file;
|
||||
if (is_create_op) {
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
#if defined(__APPLE__)
|
||||
const auto osx_flags = static_cast<std::uint32_t>(file_info->flags);
|
||||
#else // !defined(__APPLE__)
|
||||
@ -614,7 +614,7 @@ auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
|
||||
return res;
|
||||
}
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_DIRECTORY, now, now,
|
||||
true, get_effective_gid(), "", mode, now,
|
||||
0U, 0U, 0U, "", get_effective_uid(), now);
|
||||
@ -1311,14 +1311,14 @@ auto fuse_drive::utimens_impl(std::string api_path,
|
||||
|
||||
meta.clear();
|
||||
if ((tv == nullptr) || (tv[0U].tv_nsec == UTIME_NOW)) {
|
||||
meta[META_ACCESSED] = std::to_string(utils::time::get_file_time_now());
|
||||
meta[META_ACCESSED] = std::to_string(utils::time::get_time_now());
|
||||
} else if (tv[0U].tv_nsec != UTIME_OMIT) {
|
||||
const auto val = tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND);
|
||||
meta[META_ACCESSED] = std::to_string(val);
|
||||
}
|
||||
|
||||
if ((tv == nullptr) || (tv[1U].tv_nsec == UTIME_NOW)) {
|
||||
meta[META_MODIFIED] = std::to_string(utils::time::get_file_time_now());
|
||||
meta[META_MODIFIED] = std::to_string(utils::time::get_time_now());
|
||||
} else if (tv[1U].tv_nsec != UTIME_OMIT) {
|
||||
const auto val = tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND);
|
||||
meta[META_MODIFIED] = std::to_string(val);
|
||||
@ -1370,7 +1370,7 @@ void fuse_drive::update_accessed_time(const std::string &api_path) {
|
||||
if (atime_enabled_) {
|
||||
auto res = provider_.set_item_meta(
|
||||
api_path, META_ACCESSED,
|
||||
std::to_string(utils::time::get_file_time_now()));
|
||||
std::to_string(utils::time::get_time_now()));
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to set accessed time");
|
||||
|
@ -93,7 +93,8 @@ auto remote_server::populate_file_info(const std::string &api_path,
|
||||
auto error = drive_.get_item_meta(api_path, META_ATTRIBUTES, meta_attributes);
|
||||
if (error == api_error::success) {
|
||||
if (meta_attributes.empty()) {
|
||||
meta_attributes = utils::file::is_directory(construct_path(api_path))
|
||||
meta_attributes =
|
||||
utils::file::directory(construct_path(api_path)).exists()
|
||||
? std::to_string(FILE_ATTRIBUTE_DIRECTORY)
|
||||
: std::to_string(FILE_ATTRIBUTE_NORMAL);
|
||||
drive_.set_item_meta(api_path, META_ATTRIBUTES, meta_attributes);
|
||||
@ -324,7 +325,7 @@ auto remote_server::fuse_fgetattr(
|
||||
|
||||
auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
|
||||
if (res == 0) {
|
||||
directory = utils::file::is_directory(file_path);
|
||||
directory = utils::file::directory(file_path).exists();
|
||||
struct stat64 unix_st {};
|
||||
res = fstat64(static_cast<native_handle>(handle), &unix_st);
|
||||
if (res == 0) {
|
||||
@ -488,7 +489,7 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_stat,
|
||||
const auto parent_api_path = utils::path::get_parent_api_path(api_path);
|
||||
memset(&r_stat, 0, sizeof(remote::stat));
|
||||
|
||||
directory = utils::file::is_directory(file_path);
|
||||
directory = utils::file::directory(file_path).exists();
|
||||
|
||||
struct stat64 unix_st {};
|
||||
auto res = stat64(file_path.c_str(), &unix_st);
|
||||
@ -651,7 +652,7 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle)
|
||||
auto res = -1;
|
||||
errno = ENOENT;
|
||||
|
||||
if (utils::file::is_directory(file_path)) {
|
||||
if (utils::file::directory(file_path).exists()) {
|
||||
auto iter = std::make_shared<directory_iterator>(
|
||||
drive_.get_directory_items(utils::path::create_api_path(path)));
|
||||
|
||||
@ -1065,7 +1066,7 @@ auto remote_server::winfsp_can_delete(PVOID file_desc,
|
||||
STATUS_INVALID_HANDLE));
|
||||
if (ret == STATUS_SUCCESS) {
|
||||
ret = static_cast<packet::error_type>(
|
||||
utils::file::is_directory(file_path)
|
||||
utils::file::directory(file_path).exists()
|
||||
? drive_.get_directory_item_count(
|
||||
utils::path::create_api_path(relative_path))
|
||||
? STATUS_DIRECTORY_NOT_EMPTY
|
||||
@ -1090,7 +1091,7 @@ auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name,
|
||||
const auto file_path = construct_path(relative_path);
|
||||
was_closed = 0;
|
||||
|
||||
const auto directory = utils::file::is_directory(file_path);
|
||||
const auto directory = utils::file::directory(file_path).exists();
|
||||
if (flags & FileSystemBase::FspCleanupDelete) {
|
||||
remove_all(file_path);
|
||||
was_closed = 1;
|
||||
@ -1170,7 +1171,7 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
|
||||
|
||||
const auto relative_path = utils::string::to_utf8(file_name);
|
||||
const auto file_path = construct_path(relative_path);
|
||||
exists = utils::file::is_file(file_path);
|
||||
exists = utils::file::file(file_path).exists();
|
||||
|
||||
if ((create_options & FILE_DIRECTORY_FILE) != 0U) {
|
||||
attributes |= FILE_ATTRIBUTE_DIRECTORY;
|
||||
@ -1268,8 +1269,8 @@ auto remote_server::winfsp_get_security_by_name(
|
||||
|
||||
auto ret = static_cast<packet::error_type>(STATUS_SUCCESS);
|
||||
const auto file_path = construct_path(file_name);
|
||||
if (utils::file::is_file(file_path) ||
|
||||
(utils::file::is_directory(file_path))) {
|
||||
if (utils::file::file(file_path).exists() ||
|
||||
(utils::file::directory(file_path).exists())) {
|
||||
if (attributes) {
|
||||
remote::file_info file_info{};
|
||||
if ((ret = populate_file_info(construct_api_path(file_path),
|
||||
@ -1318,7 +1319,7 @@ auto remote_server::winfsp_open(
|
||||
|
||||
const auto relative_path = utils::string::to_utf8(file_name);
|
||||
const auto file_path = construct_path(relative_path);
|
||||
const auto directory = utils::file::is_directory(file_path);
|
||||
const auto directory = utils::file::directory(file_path).exists();
|
||||
if (directory) {
|
||||
create_options |= FILE_DIRECTORY_FILE;
|
||||
}
|
||||
@ -1489,11 +1490,11 @@ auto remote_server::winfsp_rename(
|
||||
|
||||
auto res = -1;
|
||||
errno = ENOENT;
|
||||
if (utils::file::is_file(file_path)) {
|
||||
if (utils::file::file(file_path).exists()) {
|
||||
res = drive_.rename_file(construct_api_path(file_path),
|
||||
construct_api_path(new_file_path),
|
||||
replace_if_exists != 0U);
|
||||
} else if (utils::file::is_directory(file_path)) {
|
||||
} else if (utils::file::directory(file_path).exists()) {
|
||||
res = drive_.rename_directory(construct_api_path(file_path),
|
||||
construct_api_path(new_file_path));
|
||||
}
|
||||
@ -1523,7 +1524,7 @@ auto remote_server::winfsp_set_basic_info(
|
||||
if (attributes == INVALID_FILE_ATTRIBUTES) {
|
||||
attributes = 0;
|
||||
} else if (attributes == 0) {
|
||||
attributes = utils::file::is_directory(file_path)
|
||||
attributes = utils::file::directory(file_path).exists()
|
||||
? FILE_ATTRIBUTE_DIRECTORY
|
||||
: FILE_ATTRIBUTE_NORMAL;
|
||||
}
|
||||
@ -1679,7 +1680,7 @@ auto remote_server::json_create_directory_snapshot(
|
||||
auto res = -1;
|
||||
errno = ENOENT;
|
||||
|
||||
if (utils::file::is_directory(file_path)) {
|
||||
if (utils::file::directory(file_path).exists()) {
|
||||
auto iter = std::make_shared<directory_iterator>(
|
||||
drive_.get_directory_items(api_path));
|
||||
auto handle = get_next_handle();
|
||||
|
@ -186,7 +186,7 @@ auto remote_server::fuse_fgetattr(
|
||||
|
||||
auto res = has_compat_open_info(handle, EBADF);
|
||||
if (res == 0) {
|
||||
directory = utils::file::is_directory(file_path);
|
||||
directory = utils::file::directory(file_path).exists();
|
||||
struct _stat64 unix_st {};
|
||||
res = _fstat64(static_cast<int>(handle), &unix_st);
|
||||
if (res == 0) {
|
||||
@ -282,7 +282,7 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_st,
|
||||
const auto file_path = construct_path(path);
|
||||
memset(&r_st, 0, sizeof(remote::stat));
|
||||
|
||||
directory = utils::file::is_directory(file_path);
|
||||
directory = utils::file::directory(file_path).exists();
|
||||
|
||||
struct _stat64 st1 {};
|
||||
const auto res = _stat64(file_path.c_str(), &st1);
|
||||
@ -827,7 +827,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
FILETIME *write_time_ptr = nullptr;
|
||||
|
||||
if ((tv[0U] == 0U) || (op0 == UTIME_NOW)) {
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
access_time.dwHighDateTime =
|
||||
static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
|
||||
access_time.dwLowDateTime = now & 0xFFFFFFFF;
|
||||
@ -838,7 +838,7 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
}
|
||||
|
||||
if ((tv[1U] == 0U) || (op1 == UTIME_NOW)) {
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
write_time.dwHighDateTime = static_cast<DWORD>((now >> 32U) & 0xFFFFFFFF);
|
||||
write_time.dwLowDateTime = now & 0xFFFFFFFF;
|
||||
write_time_ptr = &write_time;
|
||||
@ -873,7 +873,7 @@ auto remote_server::json_create_directory_snapshot(
|
||||
auto res = -1;
|
||||
errno = ENOENT;
|
||||
|
||||
if (utils::file::is_directory(file_path)) {
|
||||
if (utils::file::directory(file_path).exists()) {
|
||||
auto iter = std::make_shared<directory_iterator>(
|
||||
drive_.get_directory_items(utils::path::create_api_path(path)));
|
||||
auto handle = get_next_handle();
|
||||
@ -1011,8 +1011,11 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options,
|
||||
|
||||
const auto file_path = utils::string::from_utf8(utils::path::combine(
|
||||
mount_location_, {utils::string::to_utf8(file_name)}));
|
||||
exists = static_cast<BOOLEAN>(utils::file::is_file(utils::path::combine(
|
||||
mount_location_, {utils::string::to_utf8(file_name)})));
|
||||
exists = static_cast<BOOLEAN>(
|
||||
utils::file::file(
|
||||
utils::path::combine(mount_location_,
|
||||
{utils::string::to_utf8(file_name)}))
|
||||
.exists());
|
||||
|
||||
auto create_flags = FILE_FLAG_BACKUP_SEMANTICS;
|
||||
if ((create_options & FILE_DIRECTORY_FILE) != 0U) {
|
||||
|
@ -62,7 +62,7 @@ auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
|
||||
(mount_location[1u] == ':');
|
||||
|
||||
auto ret = drive_letter ? STATUS_DEVICE_BUSY : STATUS_NOT_SUPPORTED;
|
||||
if ((drive_letter && not utils::file::is_directory(mount_location))) {
|
||||
if ((drive_letter && not utils::file::directory(mount_location).exists())) {
|
||||
auto unicode_mount_location = utils::string::from_utf8(mount_location);
|
||||
host_.SetFileSystemName(&unicode_mount_location[0u]);
|
||||
if (config_.get_enable_mount_manager()) {
|
||||
@ -230,7 +230,7 @@ auto remote_winfsp_drive::Init(PVOID host) -> NTSTATUS {
|
||||
file_system_host->SetPersistentAcls(FALSE);
|
||||
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
|
||||
file_system_host->SetPassQueryDirectoryPattern(FALSE);
|
||||
file_system_host->SetVolumeCreationTime(utils::time::get_file_time_now());
|
||||
file_system_host->SetVolumeCreationTime(utils::time::get_time_now());
|
||||
file_system_host->SetVolumeSerialNumber(0);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
@ -384,8 +384,8 @@ auto remote_winfsp_drive::ReadDirectory(PVOID /*file_node*/, PVOID file_desc,
|
||||
::wcscpy_s(&directory_info->FileNameBuf[0], MAX_PATH,
|
||||
&display_name[0]);
|
||||
|
||||
FspFileSystemFillDirectoryBuffer(directory_buffer,
|
||||
directory_info, &ret);
|
||||
FspFileSystemFillDirectoryBuffer(directory_buffer, directory_info,
|
||||
&ret);
|
||||
if (ret != STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/,
|
||||
(mount_location[1U] == ':');
|
||||
|
||||
auto ret = drive_letter ? STATUS_DEVICE_BUSY : STATUS_NOT_SUPPORTED;
|
||||
if ((drive_letter && not utils::file::is_directory(mount_location))) {
|
||||
if ((drive_letter && not utils::file::directory(mount_location).exists())) {
|
||||
auto unicode_mount_location = utils::string::from_utf8(mount_location);
|
||||
host_.SetFileSystemName(unicode_mount_location.data());
|
||||
if (config_.get_enable_mount_manager()) {
|
||||
@ -215,7 +215,7 @@ VOID winfsp_drive::Cleanup(PVOID file_node, PVOID file_desc,
|
||||
|
||||
if ((flags & (FspCleanupSetLastAccessTime | FspCleanupSetLastWriteTime |
|
||||
FspCleanupSetChangeTime)) != 0U) {
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
if ((flags & FspCleanupSetLastAccessTime) != 0U) {
|
||||
auto res = provider_.set_item_meta(api_path, META_ACCESSED,
|
||||
std::to_string(now));
|
||||
@ -310,7 +310,7 @@ auto winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
|
||||
attributes = FILE_ATTRIBUTE_NORMAL;
|
||||
}
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, attributes, now, now, (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0U,
|
||||
0U, "", 0U, now, 0U, 0U, 0U,
|
||||
@ -579,7 +579,7 @@ auto winfsp_drive::Init(PVOID host) -> NTSTATUS {
|
||||
file_system_host->SetPersistentAcls(FALSE);
|
||||
file_system_host->SetPostCleanupWhenModifiedOnly(TRUE);
|
||||
file_system_host->SetPassQueryDirectoryPattern(FALSE);
|
||||
file_system_host->SetVolumeCreationTime(utils::time::get_file_time_now());
|
||||
file_system_host->SetVolumeCreationTime(utils::time::get_time_now());
|
||||
file_system_host->SetVolumeSerialNumber(0);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
@ -868,7 +868,7 @@ auto winfsp_drive::Read(PVOID /*file_node*/, PVOID file_desc, PVOID buffer,
|
||||
data.clear();
|
||||
auto res = provider_.set_item_meta(
|
||||
api_path, META_ACCESSED,
|
||||
std::to_string(utils::time::get_file_time_now()));
|
||||
std::to_string(utils::time::get_time_now()));
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, api_path, res,
|
||||
|
@ -514,7 +514,7 @@ void file_manager::queue_upload(const std::string &api_path,
|
||||
.or_replace()
|
||||
.column_value("api_path", api_path)
|
||||
.column_value("date_time", static_cast<std::int64_t>(
|
||||
utils::time::get_file_time_now()))
|
||||
utils::time::get_time_now()))
|
||||
.column_value("source_path", source_path)
|
||||
.go();
|
||||
if (result.ok()) {
|
||||
@ -778,11 +778,6 @@ auto file_manager::rename_file(const std::string &from_api_path,
|
||||
return res;
|
||||
}
|
||||
|
||||
std::uint64_t file_size{};
|
||||
if (not utils::file::get_file_size(fsi.source_path, file_size)) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
res = remove_file(to_api_path);
|
||||
if ((res == api_error::success) || (res == api_error::item_not_found)) {
|
||||
if (not utils::file::retry_delete_file(fsi.source_path)) {
|
||||
@ -878,8 +873,9 @@ void file_manager::start() {
|
||||
auto res = provider_.get_filesystem_item(api_path, false, fsi);
|
||||
if (res == api_error::success) {
|
||||
if (source_path == fsi.source_path) {
|
||||
std::uint64_t file_size{};
|
||||
if (utils::file::get_file_size(fsi.source_path, file_size)) {
|
||||
auto opt_size = utils::file::file{fsi.source_path}.size();
|
||||
if (opt_size.has_value()) {
|
||||
auto file_size{opt_size.value()};
|
||||
if (file_size == fsi.size) {
|
||||
auto closeable_file = std::make_shared<open_file>(
|
||||
chunk_size,
|
||||
@ -1027,7 +1023,7 @@ void file_manager::upload_completed(const file_upload_completed &evt) {
|
||||
bool exists{};
|
||||
auto res = provider_.is_file(evt.get_api_path(), exists);
|
||||
if ((res == api_error::success && not exists) ||
|
||||
not utils::file::is_file(evt.get_source().get<std::string>())) {
|
||||
not utils::file::file(evt.get_source().get<std::string>()).exists()) {
|
||||
event_system::instance().raise<file_upload_not_found>(
|
||||
evt.get_api_path(), evt.get_source());
|
||||
remove_upload(evt.get_api_path(), true);
|
||||
|
@ -292,7 +292,7 @@ auto file_manager::open_file::native_operation(
|
||||
}
|
||||
|
||||
{
|
||||
auto file_size = nf_->size();
|
||||
auto file_size = nf_->size().value_or(0U);
|
||||
if (file_size != new_file_size) {
|
||||
utils::error::raise_api_path_error(
|
||||
function_name, get_api_path(), api_error::file_size_mismatch,
|
||||
@ -320,7 +320,7 @@ auto file_manager::open_file::native_operation(
|
||||
set_modified();
|
||||
|
||||
fsi_.size = new_file_size;
|
||||
const auto now = std::to_string(utils::time::get_file_time_now());
|
||||
const auto now = std::to_string(utils::time::get_time_now());
|
||||
res = provider_.set_item_meta(
|
||||
fsi_.api_path, {
|
||||
{META_CHANGED, now},
|
||||
@ -586,7 +586,7 @@ auto file_manager::open_file::write(std::uint64_t write_offset,
|
||||
return set_api_error(res);
|
||||
}
|
||||
|
||||
const auto now = std::to_string(utils::time::get_file_time_now());
|
||||
const auto now = std::to_string(utils::time::get_time_now());
|
||||
res = provider_.set_item_meta(fsi_.api_path, {
|
||||
{META_CHANGED, now},
|
||||
{META_MODIFIED, now},
|
||||
|
@ -64,7 +64,7 @@ file_manager::ring_buffer_open_file::ring_buffer_open_file(
|
||||
ring_state_.set(0U, ring_state_.size(), true);
|
||||
|
||||
buffer_directory = utils::path::absolute(buffer_directory);
|
||||
if (not utils::file::create_directories(buffer_directory)) {
|
||||
if (not utils::file::directory(buffer_directory).create_directory()) {
|
||||
throw std::runtime_error("failed to create buffer directory|path|" +
|
||||
buffer_directory + "|err|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
|
@ -57,7 +57,7 @@ lock_data::~lock_data() {
|
||||
|
||||
auto lock_data::get_lock_data_file() -> std::string {
|
||||
const auto dir = get_state_directory();
|
||||
if (not utils::file::create_directories(dir)) {
|
||||
if (not utils::file::directory(dir).create_directory()) {
|
||||
throw startup_exception("failed to create directory|sp|" + dir + "|err|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
@ -67,7 +67,7 @@ auto lock_data::get_lock_data_file() -> std::string {
|
||||
|
||||
auto lock_data::get_lock_file() -> std::string {
|
||||
const auto dir = get_state_directory();
|
||||
if (not utils::file::create_directories(dir)) {
|
||||
if (not utils::file::directory(dir).create_directory()) {
|
||||
throw startup_exception("failed to create directory|sp|" + dir + "|err|" +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
@ -37,10 +37,10 @@ auto base_provider::create_api_file(std::string path, std::string key,
|
||||
api_file file{};
|
||||
file.api_path = utils::path::create_api_path(path);
|
||||
file.api_parent = utils::path::get_parent_api_path(file.api_path);
|
||||
file.accessed_date = utils::time::get_file_time_now();
|
||||
file.changed_date = utils::time::get_file_time_now();
|
||||
file.creation_date = utils::time::get_file_time_now();
|
||||
file.modified_date = utils::time::get_file_time_now();
|
||||
file.accessed_date = utils::time::get_time_now();
|
||||
file.changed_date = utils::time::get_time_now();
|
||||
file.creation_date = utils::time::get_time_now();
|
||||
file.modified_date = utils::time::get_time_now();
|
||||
file.key = key;
|
||||
file.file_size = size;
|
||||
return file;
|
||||
@ -482,10 +482,10 @@ void base_provider::remove_deleted_files() {
|
||||
|
||||
for (const auto &item : removed_list) {
|
||||
if (not item.directory) {
|
||||
if (utils::file::is_file(item.source_path)) {
|
||||
if (utils::file::file(item.source_path).exists()) {
|
||||
const auto orphaned_directory =
|
||||
utils::path::combine(config_.get_data_directory(), {"orphaned"});
|
||||
if (utils::file::create_directories(orphaned_directory)) {
|
||||
if (utils::file::directory(orphaned_directory).create_directory()) {
|
||||
const auto parts = utils::string::split(item.api_path, '/', false);
|
||||
const auto orphaned_file = utils::path::combine(
|
||||
orphaned_directory,
|
||||
|
@ -195,7 +195,7 @@ auto encrypt_provider::do_fs_operation(
|
||||
: api_error::item_not_found;
|
||||
}
|
||||
|
||||
auto exists = utils::file::is_file(source_path);
|
||||
auto exists = utils::file::file(source_path).exists();
|
||||
if (exists && directory) {
|
||||
return api_error::item_exists;
|
||||
}
|
||||
@ -203,7 +203,7 @@ auto encrypt_provider::do_fs_operation(
|
||||
return api_error::item_not_found;
|
||||
}
|
||||
|
||||
exists = utils::file::is_directory(source_path);
|
||||
exists = utils::file::directory(source_path).exists();
|
||||
if (exists && not directory) {
|
||||
return api_error::item_exists;
|
||||
}
|
||||
@ -659,8 +659,9 @@ auto encrypt_provider::is_directory(const std::string &api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
exists = utils::file::is_directory(
|
||||
row->get_column("source_path").get_value<std::string>());
|
||||
exists = utils::file::directory(
|
||||
row->get_column("source_path").get_value<std::string>())
|
||||
.exists();
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
@ -677,8 +678,9 @@ auto encrypt_provider::is_file(const std::string &api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
exists = utils::file::is_file(
|
||||
row->get_column("source_path").get_value<std::string>());
|
||||
exists =
|
||||
utils::file::file(row->get_column("source_path").get_value<std::string>())
|
||||
.exists();
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
@ -872,11 +874,13 @@ auto encrypt_provider::read_file_bytes(const std::string &api_path,
|
||||
|
||||
auto file_data = row->get_column("data").get_value_as_json();
|
||||
|
||||
std::uint64_t file_size{};
|
||||
if (not utils::file::get_file_size(source_path, file_size)) {
|
||||
auto opt_size = utils::file::file{source_path}.size();
|
||||
if (opt_size.has_value()) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
|
||||
std::vector<
|
||||
std::array<unsigned char, crypto_aead_xchacha20poly1305_IETF_NPUBBYTES>>
|
||||
iv_list{};
|
||||
|
@ -392,7 +392,7 @@ auto s3_provider::get_file(const std::string &api_path,
|
||||
return res;
|
||||
}
|
||||
|
||||
file.accessed_date = utils::time::get_file_time_now();
|
||||
file.accessed_date = utils::time::get_time_now();
|
||||
file.api_path = api_path;
|
||||
file.api_parent = utils::path::get_parent_api_path(file.api_path);
|
||||
file.changed_date = utils::aws::format_time(result.last_modified);
|
||||
@ -447,7 +447,7 @@ auto s3_provider::get_file_list(api_file_list &list) const -> api_error {
|
||||
api_file file{};
|
||||
file.api_path = utils::path::create_api_path(api_path);
|
||||
file.api_parent = utils::path::get_parent_api_path(file.api_path);
|
||||
file.accessed_date = utils::time::get_file_time_now();
|
||||
file.accessed_date = utils::time::get_time_now();
|
||||
file.changed_date = utils::convert_api_date(
|
||||
node.node().select_node("LastModified").node().text().as_string());
|
||||
file.creation_date = file.changed_date;
|
||||
@ -869,12 +869,18 @@ void s3_provider::stop() {
|
||||
auto s3_provider::upload_file_impl(const std::string &api_path,
|
||||
const std::string &source_path,
|
||||
stop_type &stop_requested) -> api_error {
|
||||
std::uint64_t file_size{};
|
||||
if (utils::file::is_file(source_path) &&
|
||||
not utils::file::get_file_size(source_path, file_size)) {
|
||||
auto file = utils::file::file{source_path};
|
||||
if (file.exists()) {
|
||||
return api_error::comm_error;
|
||||
}
|
||||
|
||||
auto opt_size = file.size();
|
||||
if (opt_size.has_value()) {
|
||||
return api_error::comm_error;
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
|
||||
const auto cfg = get_config().get_s3_config();
|
||||
const auto is_encrypted = not cfg.encryption_token.empty();
|
||||
|
||||
|
@ -106,7 +106,8 @@ void change_to_process_directory() {
|
||||
auto copy_file(std::string from_path, std::string to_path) -> bool {
|
||||
from_path = utils::path::absolute(from_path);
|
||||
to_path = utils::path::absolute(to_path);
|
||||
if (is_file(from_path) && not is_directory(to_path)) {
|
||||
if (utils::file::file(from_path).exists() &&
|
||||
not directory(to_path).exists()) {
|
||||
return std::filesystem::copy_file(from_path, to_path);
|
||||
}
|
||||
|
||||
@ -117,7 +118,7 @@ auto copy_directory_recursively(std::string from_path,
|
||||
std::string to_path) -> bool {
|
||||
from_path = utils::path::absolute(from_path);
|
||||
to_path = utils::path::absolute(to_path);
|
||||
auto ret = create_directories(to_path);
|
||||
auto ret = utils::file::directory(to_path).create_directory();
|
||||
if (ret) {
|
||||
#if defined(_WIN32)
|
||||
WIN32_FIND_DATA fd{};
|
||||
@ -405,7 +406,7 @@ auto move_file(std::string from, std::string to) -> bool {
|
||||
to = utils::path::absolute(to);
|
||||
|
||||
const auto directory = utils::path::get_parent_directory(to);
|
||||
if (not create_directories(directory)) {
|
||||
if (not utils::file::directory(directory).create_directory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -420,7 +421,7 @@ auto move_file(std::string from, std::string to) -> bool {
|
||||
|
||||
auto read_file_lines(const std::string &path) -> std::vector<std::string> {
|
||||
std::vector<std::string> ret;
|
||||
if (is_file(path)) {
|
||||
if (utils::file::file(path).exists()) {
|
||||
std::ifstream fs(path);
|
||||
std::string current_line;
|
||||
while (not fs.eof() && std::getline(fs, current_line)) {
|
||||
@ -461,8 +462,8 @@ auto reset_modified_time(const std::string &path) -> bool {
|
||||
|
||||
auto retry_delete_directory(const std::string &dir) -> bool {
|
||||
auto deleted = false;
|
||||
for (std::uint8_t i = 0U; not(deleted = remove_directory(dir)) && (i < 200U);
|
||||
i++) {
|
||||
for (std::uint8_t i = 0U;
|
||||
not(deleted = directory(dir).remove()) && (i < 200U); i++) {
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ mount(std::vector<const char *> args, std::string data_directory,
|
||||
std::cout << "Generated " << app_config::get_provider_display_name(prov)
|
||||
<< " Configuration" << std::endl;
|
||||
std::cout << config.get_config_file_path() << std::endl;
|
||||
ret = utils::file::is_file(config.get_config_file_path())
|
||||
ret = utils::file::file(config.get_config_file_path()).exists()
|
||||
? exit_code::success
|
||||
: exit_code::file_creation_failed;
|
||||
} else {
|
||||
|
@ -65,13 +65,13 @@ protected:
|
||||
std::to_string(static_cast<std::uint8_t>(provider_t::type)),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(utils::file::remove_directory(test_directory, true));
|
||||
ASSERT_TRUE(utils::file::directory(test_directory).remove_recursively());
|
||||
|
||||
mount_location = utils::path::combine(test_directory, {"mount"});
|
||||
ASSERT_TRUE(utils::file::create_directories(mount_location));
|
||||
ASSERT_TRUE(utils::file::directory(mount_location).create_directory());
|
||||
|
||||
cfg_directory = utils::path::combine(test_directory, {"cfg"});
|
||||
ASSERT_TRUE(utils::file::create_directories(cfg_directory));
|
||||
ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory());
|
||||
|
||||
config = std::make_unique<app_config>(provider_t::type, cfg_directory);
|
||||
|
||||
@ -142,7 +142,7 @@ protected:
|
||||
std::filesystem::current_path(current_directory);
|
||||
|
||||
[[maybe_unused]] auto ret =
|
||||
utils::file::remove_directory(test_directory, true);
|
||||
utils::file::directory(test_directory).remove_recursively();
|
||||
}
|
||||
|
||||
public:
|
||||
@ -153,12 +153,12 @@ public:
|
||||
open(file_path.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP);
|
||||
EXPECT_LE(1, fd);
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(file_path));
|
||||
EXPECT_FALSE(utils::file::is_directory(file_path));
|
||||
EXPECT_TRUE(utils::file::file(file_path).exists());
|
||||
EXPECT_FALSE(utils::file::directory(file_path).exists());
|
||||
|
||||
std::uint64_t file_size{};
|
||||
EXPECT_TRUE(utils::file::get_file_size(file_path, file_size));
|
||||
EXPECT_EQ(0U, file_size);
|
||||
auto opt_size = utils::file::file{file_path}.size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
EXPECT_EQ(0U, opt_size.value());
|
||||
|
||||
EXPECT_EQ(0, close(fd));
|
||||
std::this_thread::sleep_for(SLEEP_SECONDS);
|
||||
@ -197,8 +197,8 @@ public:
|
||||
EXPECT_EQ(0, ret);
|
||||
|
||||
std::this_thread::sleep_for(SLEEP_SECONDS);
|
||||
EXPECT_FALSE(utils::file::is_directory(file_path));
|
||||
EXPECT_FALSE(utils::file::is_file(file_path));
|
||||
EXPECT_FALSE(utils::file::directory(file_path).exists());
|
||||
EXPECT_FALSE(utils::file::file(file_path).exists());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -49,11 +49,11 @@ protected:
|
||||
void SetUp() override {
|
||||
if (PROVIDER_INDEX != 0) {
|
||||
if (PROVIDER_INDEX == 1) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(
|
||||
EXPECT_TRUE(utils::file::directory(
|
||||
utils::path::combine(
|
||||
test::get_test_output_dir(),
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}),
|
||||
true));
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}))
|
||||
.remove_recursively());
|
||||
|
||||
app_config src_cfg(
|
||||
provider_type::s3,
|
||||
@ -97,11 +97,11 @@ protected:
|
||||
}
|
||||
|
||||
if (PROVIDER_INDEX == 2) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(
|
||||
EXPECT_TRUE(utils::file::directory(
|
||||
utils::path::combine(
|
||||
test::get_test_output_dir(),
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}),
|
||||
true));
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}))
|
||||
.remove_recursively());
|
||||
|
||||
app_config src_cfg(
|
||||
provider_type::sia,
|
||||
@ -149,11 +149,11 @@ protected:
|
||||
config.reset();
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(
|
||||
EXPECT_TRUE(utils::file::directory(
|
||||
utils::path::combine(
|
||||
test::get_test_output_dir(),
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}),
|
||||
true));
|
||||
{"winfsp_test" + std::to_string(PROVIDER_INDEX)}))
|
||||
.remove_recursively());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -68,10 +68,10 @@ public:
|
||||
dir_item.size = 0;
|
||||
dir_item.meta = {
|
||||
{META_ATTRIBUTES, "16"},
|
||||
{META_MODIFIED, std::to_string(utils::time::get_file_time_now())},
|
||||
{META_WRITTEN, std::to_string(utils::time::get_file_time_now())},
|
||||
{META_ACCESSED, std::to_string(utils::time::get_file_time_now())},
|
||||
{META_CREATION, std::to_string(utils::time::get_file_time_now())}};
|
||||
{META_MODIFIED, std::to_string(utils::time::get_time_now())},
|
||||
{META_WRITTEN, std::to_string(utils::time::get_time_now())},
|
||||
{META_ACCESSED, std::to_string(utils::time::get_time_now())},
|
||||
{META_CREATION, std::to_string(utils::time::get_time_now())}};
|
||||
list.emplace_back(dir_item);
|
||||
|
||||
dir_item.api_path = "..";
|
||||
@ -135,8 +135,8 @@ public:
|
||||
if (not utils::file::retry_delete_file(to_file_path)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (utils::file::is_directory(to_file_path) ||
|
||||
utils::file::is_file(to_file_path)) {
|
||||
} else if (utils::file::directory(to_file_path).exists()) ||
|
||||
utils::file::file(to_file_path).exists()) {
|
||||
errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
|
@ -57,10 +57,10 @@ public:
|
||||
di.size = 0u;
|
||||
di.meta = {
|
||||
{META_ATTRIBUTES, "16"},
|
||||
{META_MODIFIED, std::to_string(utils::time::get_file_time_now())},
|
||||
{META_WRITTEN, std::to_string(utils::time::get_file_time_now())},
|
||||
{META_ACCESSED, std::to_string(utils::time::get_file_time_now())},
|
||||
{META_CREATION, std::to_string(utils::time::get_file_time_now())}};
|
||||
{META_MODIFIED, std::to_string(utils::time::get_time_now())},
|
||||
{META_WRITTEN, std::to_string(utils::time::get_time_now())},
|
||||
{META_ACCESSED, std::to_string(utils::time::get_time_now())},
|
||||
{META_CREATION, std::to_string(utils::time::get_time_now())}};
|
||||
list.emplace_back(di);
|
||||
|
||||
di.api_path = "..";
|
||||
@ -138,7 +138,7 @@ public:
|
||||
auto populate_file_info(const std::string &api_path,
|
||||
remote::file_info &file_info) -> api_error override {
|
||||
const auto file_path = utils::path::combine(mount_location_, {api_path});
|
||||
const auto directory = utils::file::is_directory(file_path);
|
||||
const auto directory = utils::file::directory(file_path).exists();
|
||||
const auto attributes =
|
||||
FILE_FLAG_BACKUP_SEMANTICS |
|
||||
(directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL);
|
||||
@ -148,8 +148,14 @@ public:
|
||||
FILE_BASIC_INFO fi{};
|
||||
::GetFileInformationByHandleEx(handle, FileBasicInfo, &fi, sizeof(fi));
|
||||
if (not directory) {
|
||||
utils::file::get_file_size(file_path, file_info.FileSize);
|
||||
auto opt_size = utils::file::file{file_path}.size();
|
||||
if (not opt_size.has_value()) {
|
||||
return api_error::os_error;
|
||||
}
|
||||
|
||||
file_info.FileSize = opt_size.value();
|
||||
}
|
||||
|
||||
file_info.AllocationSize =
|
||||
directory ? 0
|
||||
: utils::divide_with_ceiling(file_info.FileSize,
|
||||
|
@ -40,15 +40,17 @@ public:
|
||||
|
||||
void SetUp() override {
|
||||
event_system::instance().start();
|
||||
ASSERT_TRUE(utils::file::remove_directory(
|
||||
utils::path::combine(test::get_test_output_dir(), {"config_test"}),
|
||||
true));
|
||||
ASSERT_TRUE(
|
||||
utils::file::directory(
|
||||
utils::path::combine(test::get_test_output_dir(), {"config_test"}))
|
||||
.remove_recursively());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
ASSERT_TRUE(utils::file::remove_directory(
|
||||
utils::path::combine(test::get_test_output_dir(), {"config_test"}),
|
||||
true));
|
||||
ASSERT_TRUE(
|
||||
utils::file::directory(
|
||||
utils::path::combine(test::get_test_output_dir(), {"config_test"}))
|
||||
.remove_recursively());
|
||||
event_system::instance().stop();
|
||||
}
|
||||
};
|
||||
@ -165,10 +167,12 @@ TEST_F(config_test, sia_default_settings) {
|
||||
json data;
|
||||
EXPECT_TRUE(utils::file::read_json_file(config_file, data));
|
||||
EXPECT_STREQ(DEFAULT_SIA_CONFIG.c_str(), data.dump(2).c_str());
|
||||
EXPECT_TRUE(utils::file::is_directory(
|
||||
utils::path::combine(sia_directory, {"cache"})));
|
||||
EXPECT_TRUE(utils::file::is_directory(
|
||||
utils::path::combine(sia_directory, {"logs"})));
|
||||
EXPECT_TRUE(
|
||||
utils::file::directory(utils::path::combine(sia_directory, {"cache"}))
|
||||
.exists());
|
||||
EXPECT_TRUE(
|
||||
utils::file::directory(utils::path::combine(sia_directory, {"logs"}))
|
||||
.exists());
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,10 +186,12 @@ TEST_F(config_test, s3_default_settings) {
|
||||
json data;
|
||||
EXPECT_TRUE(utils::file::read_json_file(config_file, data));
|
||||
EXPECT_STREQ(DEFAULT_S3_CONFIG.c_str(), data.dump(2).c_str());
|
||||
EXPECT_TRUE(utils::file::is_directory(
|
||||
utils::path::combine(s3_directory, {"cache"})));
|
||||
EXPECT_TRUE(utils::file::is_directory(
|
||||
utils::path::combine(s3_directory, {"logs"})));
|
||||
EXPECT_TRUE(
|
||||
utils::file::directory(utils::path::combine(s3_directory, {"cache"}))
|
||||
.exists());
|
||||
EXPECT_TRUE(
|
||||
utils::file::directory(utils::path::combine(s3_directory, {"logs"}))
|
||||
.exists());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ TEST(open_file, will_not_change_source_path_for_0_byte_file) {
|
||||
o.close();
|
||||
EXPECT_EQ(api_error::success, o.get_api_error());
|
||||
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
||||
EXPECT_TRUE(utils::file::is_file(fsi.source_path));
|
||||
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
||||
}
|
||||
|
||||
TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
|
||||
@ -166,7 +166,7 @@ TEST(open_file, will_change_source_path_if_file_size_is_greater_than_0) {
|
||||
o.close();
|
||||
EXPECT_EQ(api_error::download_stopped, o.get_api_error());
|
||||
EXPECT_STRNE(source_path.c_str(), o.get_source_path().c_str());
|
||||
EXPECT_FALSE(utils::file::is_file(source_path));
|
||||
EXPECT_FALSE(utils::file::file(source_path).exists());
|
||||
}
|
||||
|
||||
TEST(open_file,
|
||||
@ -192,7 +192,7 @@ TEST(open_file,
|
||||
o.close();
|
||||
EXPECT_EQ(api_error::success, o.get_api_error());
|
||||
EXPECT_STREQ(source_path.c_str(), o.get_source_path().c_str());
|
||||
EXPECT_TRUE(utils::file::is_file(source_path));
|
||||
EXPECT_TRUE(utils::file::file(source_path).exists());
|
||||
}
|
||||
|
||||
TEST(open_file, write_with_incomplete_download) {
|
||||
@ -280,7 +280,7 @@ TEST(open_file, write_with_incomplete_download) {
|
||||
|
||||
EXPECT_EQ(api_error::download_incomplete, o.get_api_error());
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(fsi.source_path));
|
||||
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
||||
}
|
||||
|
||||
TEST(open_file, write_new_file) {
|
||||
@ -353,7 +353,7 @@ TEST(open_file, write_new_file) {
|
||||
|
||||
EXPECT_EQ(api_error::success, o.get_api_error());
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(fsi.source_path));
|
||||
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
||||
}
|
||||
|
||||
TEST(open_file, write_new_file_multiple_chunks) {
|
||||
@ -445,7 +445,7 @@ TEST(open_file, write_new_file_multiple_chunks) {
|
||||
|
||||
EXPECT_EQ(api_error::success, o.get_api_error());
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(fsi.source_path));
|
||||
EXPECT_TRUE(utils::file::file(fsi.source_path).exists());
|
||||
}
|
||||
|
||||
TEST(open_file, resize_file_to_0_bytes) {
|
||||
|
@ -61,7 +61,7 @@ TEST(ring_buffer_open_file, can_forward_to_last_chunk) {
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file,
|
||||
@ -93,7 +93,7 @@ TEST(ring_buffer_open_file,
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
|
||||
@ -125,7 +125,7 @@ TEST(ring_buffer_open_file, can_forward_after_last_chunk) {
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
|
||||
@ -153,7 +153,7 @@ TEST(ring_buffer_open_file, can_forward_and_rollover_after_last_chunk) {
|
||||
EXPECT_EQ(std::size_t(28u), rb.get_last_chunk());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
|
||||
@ -184,7 +184,7 @@ TEST(ring_buffer_open_file, can_reverse_to_first_chunk) {
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file,
|
||||
@ -216,7 +216,7 @@ TEST(ring_buffer_open_file,
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
|
||||
@ -248,7 +248,7 @@ TEST(ring_buffer_open_file, can_reverse_before_first_chunk) {
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
|
||||
@ -284,7 +284,7 @@ TEST(ring_buffer_open_file, can_reverse_and_rollover_before_first_chunk) {
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, can_reverse_full_ring) {
|
||||
@ -316,7 +316,7 @@ TEST(ring_buffer_open_file, can_reverse_full_ring) {
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file) {
|
||||
@ -375,7 +375,7 @@ TEST(ring_buffer_open_file, read_full_file) {
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
@ -434,7 +434,7 @@ TEST(ring_buffer_open_file, read_full_file_in_reverse) {
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
@ -494,7 +494,7 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks) {
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
@ -559,6 +559,6 @@ TEST(ring_buffer_open_file, read_full_file_in_partial_chunks_in_reverse) {
|
||||
utils::file::generate_sha256(dest_path).c_str());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(ring_buffer_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(ring_buffer_dir).remove_recursively());
|
||||
}
|
||||
} // namespace repertory
|
||||
|
@ -117,7 +117,7 @@ TEST(file_manager, can_create_and_close_file) {
|
||||
{
|
||||
std::shared_ptr<i_open_file> f;
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
|
||||
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
|
||||
@ -201,7 +201,7 @@ TEST(file_manager, can_create_and_close_file) {
|
||||
|
||||
polling::instance().stop();
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, can_open_and_close_file) {
|
||||
@ -232,7 +232,7 @@ TEST(file_manager, can_open_and_close_file) {
|
||||
std::uint64_t handle{};
|
||||
{
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
|
||||
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
|
||||
@ -317,7 +317,7 @@ TEST(file_manager, can_open_and_close_file) {
|
||||
|
||||
polling::instance().stop();
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
|
||||
@ -339,7 +339,7 @@ TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
|
||||
const auto source_path = utils::path::combine(
|
||||
cfg.get_cache_directory(), {utils::create_uuid_string()});
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u,
|
||||
now + 2u, false, 1, "key", 2, now + 3u, 3u, 4u, 0u, source_path, 10,
|
||||
@ -390,7 +390,7 @@ TEST(file_manager, can_open_and_close_multiple_handles_for_same_file) {
|
||||
|
||||
polling::instance().stop();
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
|
||||
@ -419,7 +419,7 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
|
||||
event_capture ec({"download_stored"},
|
||||
{"file_upload_completed", "file_upload_queued"});
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u,
|
||||
@ -543,7 +543,7 @@ TEST(file_manager, download_is_stored_after_write_if_partially_downloaded) {
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
@ -580,7 +580,7 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
});
|
||||
event_capture ec({"download_end"});
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u,
|
||||
@ -660,11 +660,11 @@ TEST(file_manager, upload_occurs_after_write_if_fully_downloaded) {
|
||||
|
||||
polling::instance().stop();
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, can_evict_file) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
{
|
||||
console_consumer c;
|
||||
event_system::instance().start();
|
||||
@ -689,7 +689,7 @@ TEST(file_manager, can_evict_file) {
|
||||
const auto source_path = utils::path::combine(
|
||||
cfg.get_cache_directory(), {utils::create_uuid_string()});
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
@ -730,9 +730,9 @@ TEST(file_manager, can_evict_file) {
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_EQ(api_error::success, f->write(0U, data, bytes_written));
|
||||
|
||||
std::uint64_t file_size{};
|
||||
EXPECT_TRUE(utils::file::get_file_size(source_path, file_size));
|
||||
EXPECT_EQ(static_cast<std::uint64_t>(data.size()), file_size);
|
||||
auto opt_size = utils::file::file{source_path}.size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
EXPECT_EQ(static_cast<std::uint64_t>(data.size()), opt_size.value());
|
||||
}
|
||||
|
||||
fm.close(handle);
|
||||
@ -759,17 +759,17 @@ TEST(file_manager, can_evict_file) {
|
||||
return api_error::success;
|
||||
});
|
||||
EXPECT_TRUE(fm.evict_file("/test_evict.txt"));
|
||||
EXPECT_FALSE(utils::file::is_file(source_path));
|
||||
EXPECT_FALSE(utils::file::file(source_path).exists());
|
||||
|
||||
fm.stop();
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, evict_file_fails_if_file_is_pinned) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
cfg.set_enable_chunk_downloader_timeout(false);
|
||||
@ -791,11 +791,11 @@ TEST(file_manager, evict_file_fails_if_file_is_pinned) {
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, evict_file_fails_if_provider_is_direct_only) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -807,11 +807,11 @@ TEST(file_manager, evict_file_fails_if_provider_is_direct_only) {
|
||||
EXPECT_FALSE(fm.evict_file("/test.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, evict_file_fails_if_file_is_open) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -857,12 +857,12 @@ TEST(file_manager, evict_file_fails_if_file_is_open) {
|
||||
fm.close(handle);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager,
|
||||
evict_file_fails_if_unable_to_get_source_path_from_item_meta) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -892,11 +892,11 @@ TEST(file_manager,
|
||||
EXPECT_FALSE(fm.evict_file("/test_open.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, evict_file_fails_if_source_path_is_empty) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -926,11 +926,11 @@ TEST(file_manager, evict_file_fails_if_source_path_is_empty) {
|
||||
EXPECT_FALSE(fm.evict_file("/test_open.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, evict_file_fails_if_file_is_uploading) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
{
|
||||
console_consumer c;
|
||||
event_system::instance().start();
|
||||
@ -955,7 +955,7 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
|
||||
const auto source_path = utils::path::combine(
|
||||
cfg.get_cache_directory(), {utils::create_uuid_string()});
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
@ -1003,9 +1003,10 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_EQ(api_error::success, f->write(0U, data, bytes_written));
|
||||
|
||||
std::uint64_t file_size{};
|
||||
EXPECT_TRUE(utils::file::get_file_size(source_path, file_size));
|
||||
EXPECT_EQ(static_cast<std::uint64_t>(data.size()), file_size);
|
||||
auto opt_size = utils::file::file{source_path}.size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
EXPECT_EQ(static_cast<std::uint64_t>(data.size()), opt_size.value());
|
||||
|
||||
fm.close(handle);
|
||||
|
||||
EXPECT_TRUE(utils::retryable_action(
|
||||
@ -1015,17 +1016,17 @@ TEST(file_manager, evict_file_fails_if_file_is_uploading) {
|
||||
|
||||
capture.wait_for_empty();
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(source_path));
|
||||
EXPECT_TRUE(utils::file::file(source_path).exists());
|
||||
|
||||
fm.stop();
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, evict_file_fails_if_file_is_in_upload_queue) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1046,11 +1047,11 @@ TEST(file_manager, evict_file_fails_if_file_is_in_upload_queue) {
|
||||
EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, evict_file_fails_if_file_is_modified) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1092,11 +1093,11 @@ TEST(file_manager, evict_file_fails_if_file_is_modified) {
|
||||
EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, evict_file_fails_if_file_is_not_complete) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1140,11 +1141,11 @@ TEST(file_manager, evict_file_fails_if_file_is_not_complete) {
|
||||
EXPECT_FALSE(fm.evict_file("/test_evict.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, can_get_directory_items) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1174,11 +1175,11 @@ TEST(file_manager, can_get_directory_items) {
|
||||
EXPECT_EQ(std::size_t(2U), list.size());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1187,7 +1188,7 @@ TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
|
||||
|
||||
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, 1, "", 2, now + 3u, 3u, 4u, 0u, "/test_create.src", 10,
|
||||
@ -1210,11 +1211,11 @@ TEST(file_manager, file_is_not_opened_if_provider_create_file_fails) {
|
||||
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, create_fails_if_provider_create_is_unsuccessful) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1241,12 +1242,12 @@ TEST(file_manager, create_fails_if_provider_create_is_unsuccessful) {
|
||||
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, get_open_file_fails_if_file_is_not_open) {
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1265,12 +1266,12 @@ TEST(file_manager, get_open_file_fails_if_file_is_not_open) {
|
||||
EXPECT_FALSE(f);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager,
|
||||
get_open_file_promotes_non_writeable_file_if_writeable_is_specified) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1350,11 +1351,11 @@ TEST(file_manager,
|
||||
EXPECT_EQ(std::size_t(1U), fm.get_open_file_count());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, open_file_fails_if_file_is_not_found) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1375,11 +1376,11 @@ TEST(file_manager, open_file_fails_if_file_is_not_found) {
|
||||
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, open_file_fails_if_provider_get_filesystem_item_fails) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1419,11 +1420,11 @@ TEST(file_manager, open_file_fails_if_provider_get_filesystem_item_fails) {
|
||||
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, open_file_fails_if_provider_set_item_meta_fails) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1470,11 +1471,11 @@ TEST(file_manager, open_file_fails_if_provider_set_item_meta_fails) {
|
||||
EXPECT_EQ(std::size_t(0U), fm.get_open_file_count());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, open_file_creates_source_path_if_empty) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1533,11 +1534,11 @@ TEST(file_manager, open_file_creates_source_path_if_empty) {
|
||||
EXPECT_EQ(std::size_t(1U), fm.get_open_file_count());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, open_file_first_file_handle_is_not_zero) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1581,11 +1582,11 @@ TEST(file_manager, open_file_first_file_handle_is_not_zero) {
|
||||
EXPECT_GT(handle, std::uint64_t(0U));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, can_remove_file) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1600,7 +1601,7 @@ TEST(file_manager, can_remove_file) {
|
||||
auto file = utils::file::file::open_or_create_file("./test_remove.txt");
|
||||
EXPECT_TRUE(*file);
|
||||
}
|
||||
EXPECT_TRUE(utils::file::is_file("./test_remove.txt"));
|
||||
EXPECT_TRUE(utils::file::file("./test_remove.txt").exists());
|
||||
|
||||
EXPECT_CALL(mp, get_filesystem_item)
|
||||
.WillOnce([](const std::string &api_path, bool directory,
|
||||
@ -1619,14 +1620,14 @@ TEST(file_manager, can_remove_file) {
|
||||
|
||||
EXPECT_EQ(api_error::success, fm.remove_file("/test_remove.txt"));
|
||||
|
||||
EXPECT_FALSE(utils::file::is_file("./test_remove.txt"));
|
||||
EXPECT_FALSE(utils::file::file("./test_remove.txt").exists());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, can_queue_and_remove_upload) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
console_consumer c;
|
||||
event_system::instance().start();
|
||||
@ -1657,11 +1658,11 @@ TEST(file_manager, can_queue_and_remove_upload) {
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, remove_file_fails_if_open_file_is_modified) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1711,7 +1712,7 @@ TEST(file_manager, remove_file_fails_if_open_file_is_modified) {
|
||||
EXPECT_EQ(api_error::file_in_use, fm.remove_file("/test_remove.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, file_is_closed_after_download_timeout) {
|
||||
@ -1739,7 +1740,7 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
|
||||
ee.get_api_path().get<std::string>().c_str());
|
||||
});
|
||||
|
||||
const auto now = utils::time::get_file_time_now();
|
||||
const auto now = utils::time::get_time_now();
|
||||
auto meta = create_meta_attributes(
|
||||
now, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_ARCHIVE, now + 1u, now + 2u,
|
||||
false, 1, "key", 2, now + 3u, 3u, 4u,
|
||||
@ -1809,11 +1810,11 @@ TEST(file_manager, file_is_closed_after_download_timeout) {
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, remove_file_fails_if_file_does_not_exist) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
cfg.set_enable_chunk_downloader_timeout(false);
|
||||
@ -1834,11 +1835,11 @@ TEST(file_manager, remove_file_fails_if_file_does_not_exist) {
|
||||
EXPECT_EQ(api_error::item_not_found, fm.remove_file("/test_remove.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
|
||||
TEST(file_manager, remove_file_fails_if_provider_remove_file_fails) {
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
|
||||
{
|
||||
app_config cfg(provider_type::sia, file_manager_dir);
|
||||
@ -1866,6 +1867,6 @@ TEST(file_manager, remove_file_fails_if_provider_remove_file_fails) {
|
||||
EXPECT_EQ(api_error::item_not_found, fm.remove_file("/test_remove.txt"));
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(file_manager_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively());
|
||||
}
|
||||
} // namespace repertory
|
||||
|
@ -57,7 +57,7 @@ const auto check_forced_dirs = [](const repertory::directory_item_list &list) {
|
||||
|
||||
const auto create_directory = [](repertory::i_provider &provider,
|
||||
const std::string &api_path) {
|
||||
auto date = repertory::utils::time::get_file_time_now();
|
||||
auto date = repertory::utils::time::get_time_now();
|
||||
auto meta = repertory::create_meta_attributes(
|
||||
date, 1U, date + 1U, date + 2U, true, getgid(), "", 0700, date + 3U, 2U,
|
||||
3U, 0U, api_path + "_src", getuid(), date + 4U);
|
||||
@ -109,7 +109,7 @@ const auto create_file = [](repertory::i_provider &provider,
|
||||
const std::string &api_path) {
|
||||
auto source_path = repertory::test::generate_test_file_name("providers_test");
|
||||
|
||||
auto date = repertory::utils::time::get_file_time_now();
|
||||
auto date = repertory::utils::time::get_time_now();
|
||||
auto meta = repertory::create_meta_attributes(
|
||||
date, 1U, date + 1U, date + 2U, false, getgid(), "", 0700, date + 3U, 2U,
|
||||
3U, 0U, source_path, getuid(), date + 4U);
|
||||
@ -629,7 +629,7 @@ static void run_tests(const app_config &cfg, i_provider &provider) {
|
||||
TEST(providers, encrypt_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"encrypt_provider"});
|
||||
ASSERT_TRUE(utils::file::remove_directory(config_path, true));
|
||||
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
@ -672,7 +672,7 @@ TEST(providers, encrypt_provider) {
|
||||
TEST(providers, s3_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"s3_provider"});
|
||||
ASSERT_TRUE(utils::file::remove_directory(config_path, true));
|
||||
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
@ -711,7 +711,7 @@ TEST(providers, s3_provider) {
|
||||
TEST(providers, sia_provider) {
|
||||
const auto config_path =
|
||||
utils::path::combine(test::get_test_output_dir(), {"sia_provider"});
|
||||
ASSERT_TRUE(utils::file::remove_directory(config_path, true));
|
||||
ASSERT_TRUE(utils::file::directory(config_path).remove_recursively());
|
||||
|
||||
console_consumer consumer{};
|
||||
event_system::instance().start();
|
||||
|
@ -289,9 +289,9 @@ static void ftruncate_test(repertory::remote_fuse::remote_client &client) {
|
||||
EXPECT_EQ(0, client.fuse_ftruncate(api_path.c_str(), 100, handle));
|
||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
||||
|
||||
std::uint64_t file_size;
|
||||
EXPECT_TRUE(utils::file::get_file_size(test_file, file_size));
|
||||
EXPECT_EQ(100u, file_size);
|
||||
auto opt_size = utils::file::file{test_file}.size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
EXPECT_EQ(100U, opt_size.value());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
@ -434,16 +434,16 @@ static void mkdir_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_directory =
|
||||
utils::path::combine(fuse_remote_dir, {"mkdir_test"});
|
||||
const auto api_path = test_directory.substr(mount_location_.size());
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), 0));
|
||||
#else
|
||||
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), S_IRWXU));
|
||||
#endif
|
||||
EXPECT_TRUE(utils::file::is_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).exists());
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
}
|
||||
|
||||
static void open_test(repertory::remote_fuse::remote_client &client) {
|
||||
@ -479,20 +479,20 @@ opendir_and_releasedir_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_directory =
|
||||
utils::path::combine(fuse_remote_dir, {"opendir_and_release_dir"});
|
||||
const auto api_path = test_directory.substr(mount_location_.size());
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), 0));
|
||||
#else
|
||||
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), S_IRWXU));
|
||||
#endif
|
||||
EXPECT_TRUE(utils::file::is_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).exists());
|
||||
|
||||
remote::file_handle handle = 0;
|
||||
EXPECT_EQ(0, client.fuse_opendir(api_path.c_str(), handle));
|
||||
EXPECT_EQ(0, client.fuse_releasedir(api_path.c_str(), handle));
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
}
|
||||
|
||||
static void read_and_write_test(repertory::remote_fuse::remote_client &client) {
|
||||
@ -551,14 +551,14 @@ static void readdir_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_directory =
|
||||
utils::path::combine(fuse_remote_dir, {"readdir_test"});
|
||||
const auto api_path = test_directory.substr(mount_location_.size());
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), 0));
|
||||
#else
|
||||
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), S_IRWXU));
|
||||
#endif
|
||||
EXPECT_TRUE(utils::file::is_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).exists());
|
||||
|
||||
remote::file_handle handle = 0;
|
||||
EXPECT_EQ(0, client.fuse_opendir(api_path.c_str(), handle));
|
||||
@ -572,7 +572,7 @@ static void readdir_test(repertory::remote_fuse::remote_client &client) {
|
||||
|
||||
EXPECT_EQ(0, client.fuse_releasedir(api_path.c_str(), handle));
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
}
|
||||
|
||||
/*static void removexattr_test(repertory::remote_fuse::remote_client &client) {
|
||||
@ -621,8 +621,8 @@ static void rename_test(repertory::remote_fuse::remote_client &client) {
|
||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
||||
EXPECT_EQ(0,
|
||||
client.fuse_rename(api_path.c_str(), renamed_api_path.c_str()));
|
||||
EXPECT_FALSE(utils::file::is_file(test_file));
|
||||
EXPECT_TRUE(utils::file::is_file(renamed_test_file));
|
||||
EXPECT_FALSE(utils::file::file(test_file).exists());
|
||||
EXPECT_TRUE(utils::file::file(renamed_test_file).exists());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
@ -633,19 +633,19 @@ static void rmdir_test(repertory::remote_fuse::remote_client &client) {
|
||||
const auto test_directory =
|
||||
utils::path::combine(fuse_remote_dir, {"rmdir_test"});
|
||||
const auto api_path = test_directory.substr(mount_location_.size());
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), 0));
|
||||
#else
|
||||
EXPECT_EQ(0, client.fuse_mkdir(api_path.c_str(), S_IRWXU));
|
||||
#endif
|
||||
EXPECT_TRUE(utils::file::is_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).exists());
|
||||
|
||||
EXPECT_EQ(0, client.fuse_rmdir(api_path.c_str()));
|
||||
EXPECT_FALSE(utils::file::is_directory(test_directory));
|
||||
EXPECT_FALSE(utils::file::directory(test_directory).exists());
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
}
|
||||
|
||||
static void setattr_x_test(repertory::remote_fuse::remote_client &client) {
|
||||
@ -687,7 +687,7 @@ static void setbkuptime_test(repertory::remote_fuse::remote_client &client) {
|
||||
if (ret == 0) {
|
||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
||||
|
||||
remote::file_time ts = utils::time::get_file_time_now();
|
||||
remote::file_time ts = utils::time::get_time_now();
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setbkuptime(api_path.c_str(), ts));
|
||||
#else
|
||||
@ -712,7 +712,7 @@ static void setchgtime_test(repertory::remote_fuse::remote_client &client) {
|
||||
if (ret == 0) {
|
||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
||||
|
||||
remote::file_time ts = utils::time::get_file_time_now();
|
||||
remote::file_time ts = utils::time::get_time_now();
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setchgtime(api_path.c_str(), ts));
|
||||
#else
|
||||
@ -737,7 +737,7 @@ static void setcrtime_test(repertory::remote_fuse::remote_client &client) {
|
||||
if (ret == 0) {
|
||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
||||
|
||||
remote::file_time ts = utils::time::get_file_time_now();
|
||||
remote::file_time ts = utils::time::get_time_now();
|
||||
#if defined(_WIN32)
|
||||
EXPECT_EQ(NOT_IMPLEMENTED, client.fuse_setcrtime(api_path.c_str(), ts));
|
||||
#else
|
||||
@ -871,9 +871,9 @@ static void truncate_test(repertory::remote_fuse::remote_client &client) {
|
||||
|
||||
EXPECT_EQ(0, client.fuse_truncate(api_path.c_str(), 100));
|
||||
|
||||
std::uint64_t file_size;
|
||||
EXPECT_TRUE(utils::file::get_file_size(test_file, file_size));
|
||||
EXPECT_EQ(100u, file_size);
|
||||
auto opt_size = utils::file::file{test_file}.size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
EXPECT_EQ(100U, opt_size.value());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
@ -892,7 +892,7 @@ static void unlink_test(repertory::remote_fuse::remote_client &client) {
|
||||
if (ret == 0) {
|
||||
EXPECT_EQ(0, client.fuse_release(api_path.c_str(), handle));
|
||||
EXPECT_EQ(0, client.fuse_unlink(api_path.c_str()));
|
||||
EXPECT_FALSE(utils::file::is_file(test_file));
|
||||
EXPECT_FALSE(utils::file::file(test_file).exists());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(test_file));
|
||||
@ -990,6 +990,6 @@ TEST(remote_fuse, all_tests) {
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(fuse_remote_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(fuse_remote_dir).remove_recursively());
|
||||
}
|
||||
} // namespace fuse_test
|
||||
|
@ -265,7 +265,7 @@ static void overwrite_test(remote_client &client) {
|
||||
static void create_and_read_directory_test(remote_client &client) {
|
||||
const auto test_directory =
|
||||
utils::path::combine(win_remote_dir, {"read_directory"});
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
auto api_path =
|
||||
utils::string::from_utf8(test_directory).substr(mount_location_.size());
|
||||
|
||||
@ -278,7 +278,7 @@ static void create_and_read_directory_test(remote_client &client) {
|
||||
FILE_ATTRIBUTE_DIRECTORY, 0, &file_desc, &fi, normalized_name, exists);
|
||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
||||
|
||||
EXPECT_TRUE(utils::file::is_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).exists());
|
||||
|
||||
json list;
|
||||
ret = client.winfsp_read_directory(file_desc, nullptr, nullptr, list);
|
||||
@ -287,13 +287,13 @@ static void create_and_read_directory_test(remote_client &client) {
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
}
|
||||
|
||||
static void open_and_read_directory_test(remote_client &client) {
|
||||
const auto test_directory =
|
||||
utils::path::combine(win_remote_dir, {"open_and_read_directory"});
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
auto api_path =
|
||||
utils::string::from_utf8(test_directory).substr(mount_location_.size());
|
||||
|
||||
@ -308,7 +308,7 @@ static void open_and_read_directory_test(remote_client &client) {
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
||||
|
||||
EXPECT_TRUE(utils::file::is_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).exists());
|
||||
|
||||
file_desc = reinterpret_cast<PVOID>(REPERTORY_INVALID_HANDLE);
|
||||
ret = client.winfsp_open(&api_path[0], FILE_DIRECTORY_FILE,
|
||||
@ -323,7 +323,7 @@ static void open_and_read_directory_test(remote_client &client) {
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
||||
|
||||
EXPECT_TRUE(utils::file::remove_directory(test_directory));
|
||||
EXPECT_TRUE(utils::file::directory(test_directory).remove());
|
||||
}
|
||||
|
||||
static void read_and_write_test(remote_client &client) {
|
||||
@ -389,8 +389,8 @@ static void rename_test(remote_client &client) {
|
||||
|
||||
ret = client.winfsp_rename(file_desc, &api_path[0], &api_path2[0], 0);
|
||||
EXPECT_EQ(STATUS_SUCCESS, ret);
|
||||
EXPECT_TRUE(utils::file::is_file(test_file2));
|
||||
EXPECT_FALSE(utils::file::is_file(test_file));
|
||||
EXPECT_TRUE(utils::file::file(test_file2).exists());
|
||||
EXPECT_FALSE(utils::file::file(test_file).exists());
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
||||
|
||||
@ -472,9 +472,9 @@ static void set_file_size_test(remote_client &client) {
|
||||
client.winfsp_set_file_size(file_desc, new_file_size,
|
||||
set_allocation_size, &fi));
|
||||
|
||||
std::uint64_t file_size = 0u;
|
||||
EXPECT_TRUE(utils::file::get_file_size(test_file, file_size));
|
||||
EXPECT_EQ(34u, file_size);
|
||||
auto opt_size = utils::file::file{test_file}.size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
EXPECT_EQ(34U, opt_size.value());
|
||||
|
||||
EXPECT_EQ(STATUS_SUCCESS, client.winfsp_close(file_desc));
|
||||
|
||||
@ -535,6 +535,6 @@ TEST(remote_winfsp, all_tests) {
|
||||
}
|
||||
|
||||
event_system::instance().stop();
|
||||
EXPECT_TRUE(utils::file::remove_directory(win_remote_dir, true));
|
||||
EXPECT_TRUE(utils::file::directory(win_remote_dir).remove_recursively());
|
||||
}
|
||||
} // namespace winfsp_test
|
||||
|
@ -69,12 +69,12 @@ static void execute_mount(winfsp_test *test,
|
||||
|
||||
static void unmount(winfsp_test *test, const std::string &mount_point) {
|
||||
test->drive->shutdown();
|
||||
auto mounted = utils::file::is_directory(mount_point);
|
||||
auto mounted = utils::file::directory(mount_point).exists();
|
||||
for (auto i = 0; mounted && (i < 50); i++) {
|
||||
std::this_thread::sleep_for(100ms);
|
||||
mounted = utils::file::is_directory(mount_point);
|
||||
mounted = utils::file::directory(mount_point).exists();
|
||||
}
|
||||
EXPECT_FALSE(utils::file::is_directory(mount_point));
|
||||
EXPECT_FALSE(utils::file::directory(mount_point).exists());
|
||||
}
|
||||
|
||||
static void root_creation_test(const std::string &mount_point) {
|
||||
@ -96,11 +96,11 @@ static auto create_test(winfsp_test *test, const std::string &mount_point) {
|
||||
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
|
||||
EXPECT_TRUE(::CloseHandle(handle));
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(file));
|
||||
EXPECT_TRUE(utils::file::file(file).exists());
|
||||
|
||||
std::uint64_t file_size;
|
||||
EXPECT_TRUE(utils::file::get_file_size(file, file_size));
|
||||
EXPECT_EQ(0, file_size);
|
||||
auto opt_size = utils::file::file(file).size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
EXPECT_EQ(0, opt_size.value());
|
||||
|
||||
std::string attr;
|
||||
EXPECT_EQ(api_error::success, test->provider->get_item_meta(
|
||||
@ -114,7 +114,7 @@ static void delete_file_test(const std::string &file) {
|
||||
TEST_HEADER(__FUNCTION__);
|
||||
event_capture ec({"file_removed"});
|
||||
EXPECT_TRUE(utils::file::retry_delete_file(file));
|
||||
EXPECT_FALSE(utils::file::is_file(file));
|
||||
EXPECT_FALSE(utils::file::file(file).exists());
|
||||
}
|
||||
|
||||
static void create_directory_test(const std::string &directory) {
|
||||
@ -149,11 +149,11 @@ static void write_file_test(const std::string &mount_point) {
|
||||
EXPECT_EQ(10, bytes_written);
|
||||
EXPECT_TRUE(::CloseHandle(handle));
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(file));
|
||||
EXPECT_TRUE(utils::file::file(file).exists());
|
||||
|
||||
std::uint64_t file_size;
|
||||
EXPECT_TRUE(utils::file::get_file_size(file, file_size));
|
||||
EXPECT_EQ(10, file_size);
|
||||
auto opt_size = utils::file::file(file).size();
|
||||
EXPECT_TRUE(opt_size.has_value());
|
||||
EXPECT_EQ(10U, opt_size.value());
|
||||
}
|
||||
|
||||
static void read_file_test(const std::string &mount_point) {
|
||||
@ -199,8 +199,8 @@ static void rename_file_test(winfsp_test *test,
|
||||
const auto file2 = utils::path::combine(mount_point, {"rename_file2.txt"});
|
||||
EXPECT_TRUE(::MoveFile(&file[0], &file2[0]));
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(file2));
|
||||
EXPECT_FALSE(utils::file::is_file(file));
|
||||
EXPECT_TRUE(utils::file::file(file2).exists());
|
||||
EXPECT_FALSE(utils::file::file(file).exists());
|
||||
|
||||
api_meta_map meta2{};
|
||||
EXPECT_EQ(api_error::success,
|
||||
|
@ -27,6 +27,21 @@
|
||||
#include "utils/path.hpp"
|
||||
|
||||
namespace repertory::utils::file {
|
||||
[[nodiscard]] inline auto
|
||||
directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
file_exists_in_path(std::string_view path, std::string_view file_name) -> bool;
|
||||
|
||||
[[nodiscard]] inline auto
|
||||
file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool;
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBDSM)
|
||||
[[nodiscard]] auto
|
||||
smb_create_and_validate_relative_path(std::string_view smb_path,
|
||||
@ -61,6 +76,7 @@ smb_get_parent_path(std::string_view smb_path) -> std::string;
|
||||
|
||||
struct i_fs_item {
|
||||
using fs_item_t = std::unique_ptr<i_fs_item>;
|
||||
|
||||
enum class time_types {
|
||||
access,
|
||||
creation,
|
||||
@ -74,8 +90,7 @@ struct i_fs_item {
|
||||
|
||||
[[nodiscard]] virtual auto get_path() const -> std::string = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
get_time(time_types type) const -> std::uint64_t = 0;
|
||||
[[nodiscard]] virtual auto get_time(time_types type) const -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] virtual auto is_directory_item() const -> bool = 0;
|
||||
|
||||
@ -136,7 +151,7 @@ struct i_file : public i_fs_item {
|
||||
|
||||
virtual auto set_read_buffer_size(std::uint32_t size) -> std::uint32_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto size() const -> std::uint64_t = 0;
|
||||
[[nodiscard]] virtual auto size() const -> std::optional<std::uint64_t> = 0;
|
||||
|
||||
[[nodiscard]] virtual auto truncate() -> bool { return truncate(0U); }
|
||||
|
||||
@ -268,7 +283,7 @@ public:
|
||||
return read_buffer_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
@ -335,7 +350,9 @@ public:
|
||||
return file_->get_read_buffer_size();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override {
|
||||
return file_->get_time(type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_read_only() const -> bool override {
|
||||
return file_->is_read_only();
|
||||
@ -353,7 +370,7 @@ public:
|
||||
return file_->set_read_buffer_size(size);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
@ -445,7 +462,9 @@ public:
|
||||
return file_->get_read_buffer_size();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override {
|
||||
return file_->get_time(type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_read_only() const -> bool override {
|
||||
return file_->is_read_only();
|
||||
@ -463,7 +482,7 @@ public:
|
||||
return file_->set_read_buffer_size(size);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override;
|
||||
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
@ -497,7 +516,7 @@ struct i_directory : public i_fs_item {
|
||||
count(bool recursive = false) const -> std::uint64_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto
|
||||
create_directory(std::string_view path) const -> fs_directory_t = 0;
|
||||
create_directory(std::string_view path = "") const -> fs_directory_t = 0;
|
||||
|
||||
[[nodiscard]] virtual auto create_file(std::string_view file_name,
|
||||
bool read_only) const -> fs_file_t = 0;
|
||||
@ -559,7 +578,7 @@ public:
|
||||
count(bool recursive = false) const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_directory(std::string_view path) const -> fs_directory_t override;
|
||||
create_directory(std::string_view path = "") const -> fs_directory_t override;
|
||||
|
||||
[[nodiscard]] auto create_file(std::string_view file_name,
|
||||
bool read_only) const -> fs_file_t override;
|
||||
@ -581,8 +600,6 @@ public:
|
||||
|
||||
[[nodiscard]] auto get_path() const -> std::string override { return path_; }
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto move_to(std::string_view new_path) -> bool override;
|
||||
|
||||
[[nodiscard]] auto remove() -> bool override;
|
||||
@ -609,52 +626,35 @@ class smb_file final : public i_file {
|
||||
public:
|
||||
smb_file() = default;
|
||||
|
||||
smb_file(std::uint64_t access_time, std::uint64_t creation_time,
|
||||
std::optional<smb_fd> fd, std::uint64_t modified_time,
|
||||
std::string path, smb_session_t session, std::string_view share_name,
|
||||
smb_tid tid, std::uint64_t size, std::uint64_t write_time)
|
||||
: access_time_(access_time),
|
||||
creation_time_(creation_time),
|
||||
fd_(std::move(fd)),
|
||||
modified_time_(modified_time),
|
||||
smb_file(std::optional<smb_fd> fd, std::string path, smb_session_t session,
|
||||
std::string_view share_name, smb_tid tid)
|
||||
: fd_(std::move(fd)),
|
||||
path_(std::move(path)),
|
||||
session_(std::move(session)),
|
||||
share_name_(share_name),
|
||||
size_(size),
|
||||
tid_(tid),
|
||||
write_time_(write_time) {}
|
||||
tid_(tid) {}
|
||||
|
||||
smb_file(const smb_file &) = delete;
|
||||
|
||||
smb_file(smb_file &&f) noexcept
|
||||
: access_time_(f.access_time_),
|
||||
creation_time_(f.creation_time_),
|
||||
fd_(std::move(f.fd_)),
|
||||
modified_time_(f.modified_time_),
|
||||
: fd_(std::move(f.fd_)),
|
||||
path_(std::move(f.path_)),
|
||||
read_buffer_size(f.get_read_buffer_size()),
|
||||
read_only_(f.read_only_),
|
||||
session_(std::move(f.session_)),
|
||||
share_name_(std::move(f.share_name_)),
|
||||
size_(f.size_),
|
||||
tid_(f.tid_),
|
||||
write_time_(f.write_time_) {}
|
||||
tid_(f.tid_) {}
|
||||
|
||||
~smb_file() override { close(); }
|
||||
|
||||
private:
|
||||
std::uint64_t access_time_;
|
||||
std::uint64_t creation_time_;
|
||||
std::optional<smb_fd> fd_;
|
||||
std::uint64_t modified_time_;
|
||||
std::string path_;
|
||||
std::atomic_uint32_t read_buffer_size{65536U};
|
||||
bool read_only_;
|
||||
smb_session_t session_;
|
||||
std::string share_name_;
|
||||
std::uint64_t size_;
|
||||
smb_tid tid_;
|
||||
std::uint64_t write_time_;
|
||||
|
||||
public:
|
||||
void close() override;
|
||||
@ -673,20 +673,12 @@ public:
|
||||
return read_buffer_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] static auto get_time(smb_session *session, smb_tid tid,
|
||||
std::string path,
|
||||
time_types type) -> std::uint64_t;
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override {
|
||||
switch (type) {
|
||||
case time_types::access:
|
||||
return access_time_;
|
||||
|
||||
case time_types::creation:
|
||||
return creation_time_;
|
||||
|
||||
case time_types::modified:
|
||||
return modified_time_;
|
||||
|
||||
case time_types::write:
|
||||
return write_time_;
|
||||
}
|
||||
return get_time(session_.get(), tid_, path_, type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_unc_path() const -> std::string {
|
||||
@ -722,7 +714,7 @@ public:
|
||||
return read_buffer_size;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto size() const -> std::uint64_t override { return size_; }
|
||||
[[nodiscard]] auto size() const -> std::optional<std::uint64_t> override;
|
||||
|
||||
[[nodiscard]] auto truncate(std::size_t size) -> bool override;
|
||||
|
||||
@ -735,18 +727,13 @@ public:
|
||||
|
||||
auto operator=(smb_file &&move_file) noexcept -> smb_file & {
|
||||
if (this != &move_file) {
|
||||
access_time_ = move_file.access_time_;
|
||||
creation_time_ = move_file.creation_time_;
|
||||
fd_ = std::move(move_file.fd_);
|
||||
modified_time_ = move_file.modified_time_;
|
||||
path_ = std::move(move_file.path_);
|
||||
read_buffer_size = move_file.get_read_buffer_size();
|
||||
read_only_ = move_file.read_only_;
|
||||
session_ = std::move(move_file.session_);
|
||||
share_name_ = std::move(move_file.share_name_);
|
||||
size_ = move_file.size_;
|
||||
tid_ = move_file.tid_;
|
||||
write_time_ = move_file.write_time_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -796,7 +783,7 @@ public:
|
||||
count(bool recursive = false) const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_directory(std::string_view path) const -> fs_directory_t override;
|
||||
create_directory(std::string_view path = "") const -> fs_directory_t override;
|
||||
|
||||
[[nodiscard]] auto create_file(std::string_view file_name,
|
||||
bool read_only) const -> fs_file_t override;
|
||||
@ -818,7 +805,9 @@ public:
|
||||
|
||||
[[nodiscard]] auto get_path() const -> std::string override { return path_; }
|
||||
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override;
|
||||
[[nodiscard]] auto get_time(time_types type) const -> std::uint64_t override {
|
||||
return smb_file::get_time(session_.get(), tid_, path_, type);
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_unc_path() const -> std::string {
|
||||
return smb_get_unc_path(path_);
|
||||
@ -853,44 +842,6 @@ public:
|
||||
};
|
||||
#endif // defined(PROJECT_ENABLE_LIBDSM)
|
||||
|
||||
[[nodiscard]] auto create_directories(std::string_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto create_directories(std::wstring_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool;
|
||||
|
||||
[[nodiscard]] auto get_file_size(std::string_view path,
|
||||
std::uint64_t &file_size) -> bool;
|
||||
|
||||
[[nodiscard]] auto get_file_size(std::wstring_view path,
|
||||
std::uint64_t &file_size) -> bool;
|
||||
|
||||
[[nodiscard]] auto file_exists_in_path(std::string_view path,
|
||||
std::string_view file_name) -> bool;
|
||||
|
||||
[[nodiscard]] auto file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool;
|
||||
|
||||
[[nodiscard]] auto is_directory(std::string_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto is_directory(std::wstring_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto is_file(std::string_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto is_file(std::wstring_view path) -> bool;
|
||||
|
||||
[[nodiscard]] auto remove_directory(std::string_view path,
|
||||
bool recursive = false) -> bool;
|
||||
|
||||
[[nodiscard]] auto remove_directory(std::wstring_view path,
|
||||
bool recursive = false) -> bool;
|
||||
|
||||
#if defined(PROJECT_ENABLE_JSON)
|
||||
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||
[[nodiscard]] auto
|
||||
@ -924,18 +875,38 @@ read_json_file(std::string_view path, nlohmann::json &data,
|
||||
#endif // defined(PROJECT_ENABLE_JSON)
|
||||
|
||||
template <typename string_t>
|
||||
inline auto directory_exists_in_path_t(
|
||||
[[nodiscard]] inline auto directory_exists_in_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
std::basic_string_view<typename string_t::value_type> sub_directory)
|
||||
-> bool {
|
||||
return is_directory(utils::path::combine(path, {sub_directory}));
|
||||
return directory(utils::path::combine(path, {sub_directory})).exists();
|
||||
}
|
||||
|
||||
template <typename string_t>
|
||||
inline auto file_exists_in_path_t(
|
||||
[[nodiscard]] inline auto file_exists_in_path_t(
|
||||
std::basic_string_view<typename string_t::value_type> path,
|
||||
std::basic_string_view<typename string_t::value_type> file_name) -> bool {
|
||||
return is_file(utils::path::combine(path, {file_name}));
|
||||
return file(utils::path::combine(path, {file_name})).exists();
|
||||
}
|
||||
|
||||
inline auto directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool {
|
||||
return directory_exists_in_path_t<std::string>(path, sub_directory);
|
||||
}
|
||||
|
||||
inline auto directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool {
|
||||
return directory_exists_in_path_t<std::wstring>(path, sub_directory);
|
||||
}
|
||||
|
||||
inline auto file_exists_in_path(std::string_view path,
|
||||
std::string_view file_name) -> bool {
|
||||
return file_exists_in_path_t<std::string>(path, file_name);
|
||||
}
|
||||
|
||||
inline auto file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool {
|
||||
return file_exists_in_path_t<std::wstring>(path, file_name);
|
||||
}
|
||||
} // namespace repertory::utils::file
|
||||
|
||||
|
@ -46,8 +46,6 @@ filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t;
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_SPDLOG) || defined(PROJECT_ENABLE_FMT)
|
||||
|
||||
[[nodiscard]] auto get_file_time_now() -> std::uint64_t;
|
||||
|
||||
void get_local_time_now(struct tm &local_time);
|
||||
|
||||
[[nodiscard]] auto get_time_now() -> std::uint64_t;
|
||||
|
@ -127,10 +127,11 @@ protected:
|
||||
|
||||
reader_.set_read_position(reinterpret_cast<std::uintptr_t>(gptr()));
|
||||
|
||||
const auto res = encrypting_reader::reader_function(
|
||||
auto res = encrypting_reader::reader_function(
|
||||
ptr, 1U, static_cast<std::size_t>(count), &reader_);
|
||||
if ((res == reader_.get_error_return()) ||
|
||||
(reader_.get_stop_requested() && (res == CURL_READFUNC_ABORT))) {
|
||||
(reader_.get_stop_requested() &&
|
||||
(res == static_cast<std::size_t>(CURL_READFUNC_ABORT)))) {
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
@ -200,7 +201,13 @@ encrypting_reader::encrypting_reader(
|
||||
encrypted_file_path_ += '/' + encrypted_file_name_;
|
||||
}
|
||||
|
||||
auto file_size = source_file_->size();
|
||||
auto opt_size = source_file_->size();
|
||||
if (not opt_size.has_value()) {
|
||||
throw std::runtime_error("failed to get file size|" +
|
||||
source_file_->get_path());
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
@ -234,7 +241,13 @@ encrypting_reader::encrypting_reader(std::string_view encrypted_file_path,
|
||||
encrypted_file_path_ = encrypted_file_path;
|
||||
encrypted_file_name_ = utils::path::strip_to_file_name(encrypted_file_path_);
|
||||
|
||||
auto file_size = source_file_->size();
|
||||
auto opt_size = source_file_->size();
|
||||
if (not opt_size.has_value()) {
|
||||
throw std::runtime_error("failed to get file size|" +
|
||||
source_file_->get_path());
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
@ -270,7 +283,14 @@ encrypting_reader::encrypting_reader(
|
||||
encrypted_file_path_ = encrypted_file_path;
|
||||
encrypted_file_name_ = utils::path::strip_to_file_name(encrypted_file_path_);
|
||||
|
||||
auto file_size = source_file_->size();
|
||||
auto opt_size = source_file_->size();
|
||||
if (not opt_size.has_value()) {
|
||||
throw std::runtime_error("get file size failed|src|" +
|
||||
source_file_->get_path() + '|' +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
@ -313,13 +333,15 @@ auto encrypting_reader::calculate_decrypted_size(std::uint64_t total_size)
|
||||
|
||||
auto encrypting_reader::calculate_encrypted_size(std::string_view source_path)
|
||||
-> std::uint64_t {
|
||||
std::uint64_t file_size{};
|
||||
if (not utils::file::get_file_size(source_path, file_size)) {
|
||||
auto opt_size = utils::file::file{source_path}.size();
|
||||
if (not opt_size.has_value()) {
|
||||
throw std::runtime_error("get file size failed|src|" +
|
||||
std::string{source_path} + '|' +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
auto file_size{opt_size.value()};
|
||||
|
||||
const auto total_chunks = utils::divide_with_ceiling(
|
||||
file_size, static_cast<std::uint64_t>(data_chunk_size_));
|
||||
return file_size + (total_chunks * encryption_header_size);
|
||||
@ -387,7 +409,7 @@ auto encrypting_reader::reader_function(char *buffer, size_t size,
|
||||
}
|
||||
}
|
||||
|
||||
return stop_requested_ ? CURL_READFUNC_ABORT
|
||||
return stop_requested_ ? static_cast<std::size_t>(CURL_READFUNC_ABORT)
|
||||
: ret ? total_read
|
||||
: error_return_;
|
||||
}
|
||||
|
@ -26,56 +26,6 @@
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace {
|
||||
[[nodiscard]] auto remove_directory_recursively(std::string_view path) -> bool {
|
||||
#if defined(_WIN32)
|
||||
WIN32_FIND_DATAA fd{};
|
||||
auto search = repertory::utils::path::combine(path, {"*.*"});
|
||||
auto find = ::FindFirstFileA(search.c_str(), &fd);
|
||||
if (find != INVALID_HANDLE_VALUE) {
|
||||
auto res{true};
|
||||
do {
|
||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
if ((std::string(fd.cFileName) != ".") &&
|
||||
(std::string(fd.cFileName) != "..")) {
|
||||
res = remove_directory_recursively(
|
||||
repertory::utils::path::combine(path, {fd.cFileName}));
|
||||
}
|
||||
} else {
|
||||
res = repertory::utils::file::file(
|
||||
repertory::utils::path::combine(path, {fd.cFileName}))
|
||||
.remove();
|
||||
}
|
||||
} while (res && (::FindNextFileA(find, &fd) != 0));
|
||||
|
||||
::FindClose(find);
|
||||
}
|
||||
#else
|
||||
auto *root = opendir(std::string{path}.c_str());
|
||||
if (root != nullptr) {
|
||||
auto res{true};
|
||||
struct dirent *de{};
|
||||
while (res && (de = readdir(root))) {
|
||||
if (de->d_type == DT_DIR) {
|
||||
if ((strcmp(de->d_name, ".") != 0) && (strcmp(de->d_name, "..") != 0)) {
|
||||
res = remove_directory_recursively(
|
||||
repertory::utils::path::combine(path, {de->d_name}));
|
||||
}
|
||||
} else {
|
||||
res = repertory::utils::file::file(
|
||||
repertory::utils::path::combine(path, {de->d_name}))
|
||||
.remove();
|
||||
}
|
||||
}
|
||||
|
||||
closedir(root);
|
||||
}
|
||||
#endif
|
||||
|
||||
return repertory::utils::file::remove_directory(path, false);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace repertory::utils::file {
|
||||
auto i_file::read_all(data_buffer &data, std::uint64_t offset,
|
||||
std::size_t *total_read) -> bool {
|
||||
@ -107,131 +57,64 @@ auto i_file::read_all(data_buffer &data, std::uint64_t offset,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto create_directories(std::string_view path) -> bool {
|
||||
if (is_directory(path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
return (::SHCreateDirectory(
|
||||
nullptr,
|
||||
utils::string::from_utf8(utils::path::absolute(path)).c_str()) ==
|
||||
ERROR_SUCCESS);
|
||||
#else // !defined(_WIN32)
|
||||
auto ret{true};
|
||||
auto paths = utils::string::split(utils::path::absolute(path),
|
||||
utils::path::directory_seperator, false);
|
||||
|
||||
std::string current_path;
|
||||
for (std::size_t idx = 0U; ret && (idx < paths.size()); idx++) {
|
||||
if (paths.at(idx).empty()) {
|
||||
current_path = utils::path::directory_seperator;
|
||||
continue;
|
||||
}
|
||||
|
||||
current_path = utils::path::combine(current_path, {paths.at(idx)});
|
||||
auto status = mkdir(current_path.c_str(), S_IRWXU);
|
||||
ret = ((status == 0) || (errno == EEXIST));
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
auto create_directories(std::wstring_view path) -> bool {
|
||||
return create_directories(utils::string::to_utf8(path));
|
||||
}
|
||||
|
||||
auto directory_exists_in_path(std::string_view path,
|
||||
std::string_view sub_directory) -> bool {
|
||||
return directory_exists_in_path_t<std::string>(path, sub_directory);
|
||||
}
|
||||
|
||||
auto directory_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view sub_directory) -> bool {
|
||||
return directory_exists_in_path_t<std::wstring>(path, sub_directory);
|
||||
}
|
||||
|
||||
auto file_exists_in_path(std::string_view path,
|
||||
std::string_view file_name) -> bool {
|
||||
return file_exists_in_path_t<std::string>(path, file_name);
|
||||
}
|
||||
|
||||
auto file_exists_in_path(std::wstring_view path,
|
||||
std::wstring_view file_name) -> bool {
|
||||
return file_exists_in_path_t<std::wstring>(path, file_name);
|
||||
}
|
||||
|
||||
auto get_file_size(std::string_view path, std::uint64_t &file_size) -> bool {
|
||||
auto abs_path = utils::path::absolute(path);
|
||||
file_size = 0U;
|
||||
auto i_fs_item::get_time(time_types type) const -> std::uint64_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
#if defined(_WIN32)
|
||||
struct _stat64 st {};
|
||||
auto res = _stat64(std::string{path}.c_str(), &st);
|
||||
if (res != 0) {
|
||||
_stat64(get_path().c_str(), &st);
|
||||
#else // !defined(_WIN32)
|
||||
struct stat st {};
|
||||
stat(get_path().c_str(), &st);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
switch (type) {
|
||||
case time_types::access:
|
||||
#if defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_atime);
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_atim.tv_nsec +
|
||||
st.st_atim.tv_sec *
|
||||
utils::time::NANOS_PER_SECOND);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
case time_types::creation:
|
||||
#if defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_ctime);
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_ctim.tv_nsec +
|
||||
st.st_ctim.tv_sec *
|
||||
utils::time::NANOS_PER_SECOND);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
case time_types::modified:
|
||||
#if defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_mtime);
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
|
||||
st.st_mtim.tv_sec *
|
||||
utils::time::NANOS_PER_SECOND);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
case time_types::write:
|
||||
#if defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_mtime);
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
|
||||
st.st_mtim.tv_sec *
|
||||
utils::time::NANOS_PER_SECOND);
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
file_size = static_cast<std::uint64_t>(st.st_size);
|
||||
return true;
|
||||
#else // !defined(_WIN32)
|
||||
std::error_code ec{};
|
||||
file_size = std::filesystem::file_size(abs_path, ec);
|
||||
return (ec.value() == 0);
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
auto get_file_size(std::wstring_view path, std::uint64_t &file_size) -> bool {
|
||||
return get_file_size(utils::string::to_utf8(path), file_size);
|
||||
}
|
||||
|
||||
auto is_directory(std::string_view path) -> bool {
|
||||
auto abs_path = utils::path::absolute(path);
|
||||
|
||||
#if defined(_WIN32)
|
||||
return ::PathIsDirectoryA(abs_path.c_str()) != 0;
|
||||
#else // !defined(_WIN32)
|
||||
struct stat st {};
|
||||
return (stat(abs_path.c_str(), &st) == 0 && S_ISDIR(st.st_mode));
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
auto is_directory(std::wstring_view path) -> bool {
|
||||
return is_directory(utils::string::to_utf8(path));
|
||||
}
|
||||
|
||||
auto is_file(std::string_view path) -> bool {
|
||||
auto abs_path = utils::path::absolute(path);
|
||||
|
||||
#if defined(_WIN32)
|
||||
return (::PathFileExistsA(abs_path.c_str()) &&
|
||||
not ::PathIsDirectoryA(abs_path.c_str()));
|
||||
#else // !defined(_WIN32)
|
||||
struct stat st {};
|
||||
return (stat(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode));
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
auto is_file(std::wstring_view path) -> bool {
|
||||
return is_file(utils::string::to_utf8(path));
|
||||
}
|
||||
|
||||
auto remove_directory(std::string_view path, bool recursive) -> bool {
|
||||
auto abs_path = utils::path::absolute(path);
|
||||
if (recursive) {
|
||||
return remove_directory_recursively(abs_path);
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
return (not is_directory(abs_path) || ::RemoveDirectoryA(abs_path.c_str()));
|
||||
#else // !defined(_WIN32)
|
||||
return not is_directory(abs_path) || (rmdir(abs_path.c_str()) == 0);
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
auto remove_directory(std::wstring_view path, bool recursive) -> bool {
|
||||
return remove_directory(utils::string::to_utf8(path), recursive);
|
||||
}
|
||||
|
||||
#if defined(PROJECT_ENABLE_JSON)
|
||||
|
@ -21,35 +21,384 @@
|
||||
*/
|
||||
#include "utils/file.hpp"
|
||||
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/unix.hpp"
|
||||
#include "utils/windows.hpp"
|
||||
|
||||
namespace {
|
||||
auto traverse_directory(
|
||||
std::string_view path,
|
||||
std::function<bool(repertory::utils::file::directory)> directory_action,
|
||||
std::function<bool(repertory::utils::file::file)> file_action) -> bool {
|
||||
auto res{true};
|
||||
|
||||
#if defined(_WIN32)
|
||||
WIN32_FIND_DATAA fd{};
|
||||
auto search = repertory::utils::path::combine(path, {"*.*"});
|
||||
auto find = ::FindFirstFileA(search.c_str(), &fd);
|
||||
if (find == INVALID_HANDLE_VALUE) {
|
||||
throw std::runtime_error(
|
||||
"failed to open directory|" + std::string{path} + '|' +
|
||||
std::to_string(repertory::utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
do {
|
||||
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
if ((std::string_view(fd.cFileName) != ".") &&
|
||||
(std::string_view(fd.cFileName) != "..")) {
|
||||
res = directory_action(repertory::utils::file::directory{
|
||||
repertory::utils::path::combine(path, {fd.cFileName})});
|
||||
}
|
||||
} else {
|
||||
res = file_action(repertory::utils::file::file(
|
||||
repertory::utils::path::combine(path, {fd.cFileName})));
|
||||
}
|
||||
} while (res && (::FindNextFileA(find, &fd) != 0));
|
||||
|
||||
::FindClose(find);
|
||||
#else // !defined(_WIN32)
|
||||
auto *root = opendir(path.c_str());
|
||||
if (root == nullptr) {
|
||||
throw std::runtime_error("failed to open directory|" + std::string{path} +
|
||||
'|' +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
}
|
||||
|
||||
struct dirent *de{};
|
||||
while (res && (de = readdir(root))) {
|
||||
if (de->d_type == DT_DIR) {
|
||||
if ((strcmp(de->d_name, ".") != 0) && (strcmp(de->d_name, "..") != 0)) {
|
||||
res = directory_action(repertory::utils::file::directory(
|
||||
repertory::utils::path::combine(path, {de->d_name})));
|
||||
}
|
||||
} else {
|
||||
res = file_action(repertory::utils::file::file(
|
||||
repertory::utils::path::combine(path, {de->d_name})));
|
||||
}
|
||||
}
|
||||
|
||||
closedir(root);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
return res;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace repertory::utils::file {
|
||||
auto directory::count(bool recursive) const -> std::uint64_t { return 0U; }
|
||||
auto directory::count(bool recursive) const -> std::uint64_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
std::uint64_t ret{0U};
|
||||
|
||||
traverse_directory(
|
||||
path_,
|
||||
[&ret, &recursive](auto dir_item) -> bool {
|
||||
if (recursive) {
|
||||
ret += dir_item.count(true);
|
||||
}
|
||||
|
||||
++ret;
|
||||
return true;
|
||||
},
|
||||
[&ret](auto /* file_item */) -> bool {
|
||||
++ret;
|
||||
return true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
auto directory::create_directory(std::string_view path) const
|
||||
-> fs_directory_t {}
|
||||
-> fs_directory_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
auto directory::exists() const -> bool { return false; }
|
||||
try {
|
||||
auto abs_path = utils::path::combine(path_, {path});
|
||||
if (directory{abs_path}.exists()) {
|
||||
return std::make_unique<directory>(abs_path);
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
auto res = ::SHCreateDirectory(nullptr,
|
||||
utils::string::from_utf8(abs_path).c_str());
|
||||
if (res != ERROR_SUCCESS) {
|
||||
throw std::runtime_error("failed to create directory|" +
|
||||
std::string{abs_path} + '|' +
|
||||
std::to_string(res));
|
||||
}
|
||||
#else // !defined(_WIN32)
|
||||
auto ret{true};
|
||||
auto paths =
|
||||
utils::string::split(abs_path, utils::path::directory_seperator, false);
|
||||
|
||||
std::string current_path;
|
||||
for (std::size_t idx = 0U; ret && (idx < paths.size()); ++idx) {
|
||||
if (paths.at(idx).empty()) {
|
||||
current_path = utils::path::directory_seperator;
|
||||
continue;
|
||||
}
|
||||
|
||||
current_path = utils::path::combine(current_path, {paths.at(idx)});
|
||||
auto status = mkdir(current_path.c_str(), S_IRWXU);
|
||||
ret = ((status == 0) || (errno == EEXIST));
|
||||
}
|
||||
#endif
|
||||
|
||||
return std::make_unique<directory>(abs_path);
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto directory::exists() const -> bool {
|
||||
#if defined(_WIN32)
|
||||
return ::PathIsDirectoryA(path_.c_str()) != 0;
|
||||
#else // !defined(_WIN32)
|
||||
struct stat st {};
|
||||
return (stat(path_.c_str(), &st) == 0 && S_ISDIR(st.st_mode));
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
auto directory::get_directory(std::string_view path) const -> fs_directory_t {
|
||||
return {};
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
auto dir_path = utils::path::combine(path_, {path});
|
||||
return fs_directory_t{
|
||||
directory{dir_path}.exists() ? new directory{dir_path} : nullptr,
|
||||
};
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto directory::get_directories() const -> std::vector<fs_directory_t> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
std::vector<fs_directory_t> ret{};
|
||||
|
||||
traverse_directory(
|
||||
path_,
|
||||
[&ret](auto dir_item) -> bool {
|
||||
ret.emplace_back(fs_directory_t{
|
||||
new directory(dir_item.get_path()),
|
||||
});
|
||||
|
||||
return true;
|
||||
},
|
||||
[](auto /* file_item */) -> bool { return true; });
|
||||
|
||||
return ret;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
auto directory::get_time(time_types type) const -> std::uint64_t {}
|
||||
auto directory::create_file(std::string_view file_name,
|
||||
bool read_only) const -> fs_file_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
auto directory::get_file(std::string_view path) const -> fs_file_t {}
|
||||
try {
|
||||
auto file_path = utils::path::combine(path_, {file_name});
|
||||
return file::open_or_create_file(file_path, read_only);
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
auto directory::get_files() const -> std::vector<fs_file_t> { return {}; }
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto directory::get_items() const -> std::vector<fs_item_t> { return {}; }
|
||||
auto directory::get_file(std::string_view path) const -> fs_file_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
auto file_path = utils::path::combine(path_, {path});
|
||||
return fs_file_t{
|
||||
file{file_path}.exists() ? new file(file_path) : nullptr,
|
||||
};
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto directory::get_files() const -> std::vector<fs_file_t> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
std::vector<fs_file_t> ret{};
|
||||
|
||||
traverse_directory(
|
||||
path_, [](auto /* dir_item */) -> bool { return true; },
|
||||
[&ret](auto file_item) -> bool {
|
||||
ret.emplace_back(fs_file_t{
|
||||
new file(file_item.get_path()),
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
auto directory::get_items() const -> std::vector<fs_item_t> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
std::vector<fs_item_t> ret{};
|
||||
|
||||
traverse_directory(
|
||||
path_,
|
||||
[&ret](auto dir_item) -> bool {
|
||||
ret.emplace_back(fs_item_t{
|
||||
new directory(dir_item.get_path()),
|
||||
});
|
||||
return true;
|
||||
},
|
||||
[&ret](auto file_item) -> bool {
|
||||
ret.emplace_back(fs_item_t{
|
||||
new file(file_item.get_path()),
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
auto directory::move_to(std::string_view new_path) -> bool { return false; }
|
||||
|
||||
auto directory::remove() -> bool { return false; }
|
||||
auto directory::remove() -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
auto directory::remove_recursively() -> bool { return false; }
|
||||
try {
|
||||
#if defined(_WIN32)
|
||||
return (not exists() || ::RemoveDirectoryA(path_.c_str()));
|
||||
#else // !defined(_WIN32)
|
||||
return not exists() || (rmdir(path_.c_str()) == 0);
|
||||
#endif // defined(_WIN32)
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
auto directory::size(bool recursive) const -> std::uint64_t { return 0U; }
|
||||
return false;
|
||||
}
|
||||
|
||||
auto directory::remove_recursively() -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
if (not traverse_directory(
|
||||
path_,
|
||||
[](auto dir_item) -> bool { return dir_item.remove_recursively(); },
|
||||
[](auto file_item) -> bool { return file_item.remove(); })) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return remove();
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
auto directory::size(bool recursive) const -> std::uint64_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
std::uint64_t ret{0U};
|
||||
|
||||
traverse_directory(
|
||||
path_,
|
||||
[&ret, &recursive](auto dir_item) -> bool {
|
||||
if (recursive) {
|
||||
ret += dir_item.size(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
[&ret](auto file_item) -> bool {
|
||||
auto cur_size = file_item.size();
|
||||
if (cur_size.has_value()) {
|
||||
ret += cur_size.value();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return ret;
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return 0U;
|
||||
}
|
||||
} // namespace repertory::utils::file
|
||||
|
@ -32,8 +32,6 @@ void enc_file::close() {}
|
||||
|
||||
void enc_file::flush() const {}
|
||||
|
||||
auto enc_file::get_time(time_types type) const -> std::uint64_t {}
|
||||
|
||||
auto enc_file::move_to(std::string_view path) -> bool {}
|
||||
|
||||
auto enc_file::read(unsigned char *data, std::size_t to_read,
|
||||
@ -46,7 +44,7 @@ auto enc_file::truncate(std::size_t size) -> bool {}
|
||||
auto enc_file::write(const unsigned char *data, std::size_t to_write,
|
||||
std::size_t offset, std::size_t *total_written) -> bool {}
|
||||
|
||||
auto enc_file::size() const -> std::uint64_t {}
|
||||
auto enc_file::size() const -> std::optional<std::uint64_t> {}
|
||||
} // namespace repertory::utils::file
|
||||
|
||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||
|
@ -27,6 +27,41 @@
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace {
|
||||
[[nodiscard]] auto get_file_size(std::string_view path,
|
||||
std::uint64_t &file_size) -> bool {
|
||||
auto abs_path = repertory::utils::path::absolute(path);
|
||||
file_size = 0U;
|
||||
|
||||
#if defined(_WIN32)
|
||||
struct _stat64 st {};
|
||||
auto res = _stat64(std::string{path}.c_str(), &st);
|
||||
if (res != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
file_size = static_cast<std::uint64_t>(st.st_size);
|
||||
return true;
|
||||
#else // !defined(_WIN32)
|
||||
std::error_code ec{};
|
||||
file_size = std::filesystem::file_size(abs_path, ec);
|
||||
return (ec.value() == 0);
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
[[nodiscard]] auto is_file(std::string_view path) -> bool {
|
||||
auto abs_path = repertory::utils::path::absolute(path);
|
||||
|
||||
#if defined(_WIN32)
|
||||
return (::PathFileExistsA(abs_path.c_str()) &&
|
||||
not ::PathIsDirectoryA(abs_path.c_str()));
|
||||
#else // !defined(_WIN32)
|
||||
struct stat st {};
|
||||
return (stat(abs_path.c_str(), &st) == 0 && not S_ISDIR(st.st_mode));
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace repertory::utils::file {
|
||||
// auto file::attach_file(native_handle handle,
|
||||
// bool read_only) -> fs_file_t {
|
||||
@ -189,65 +224,11 @@ auto file::get_handle() const -> native_handle {
|
||||
}
|
||||
|
||||
auto file::get_time(time_types type) const -> std::uint64_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
try {
|
||||
#if defined(_WIN32)
|
||||
#else // !defined(_WIN32)
|
||||
struct stat st {};
|
||||
stat(path_.c_str(), &st);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
switch (type) {
|
||||
case time_types::access:
|
||||
#if defined(_WIN32)
|
||||
break;
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_atim.tv_nsec +
|
||||
st.st_atim.tv_sec *
|
||||
utils::time::NANOS_PER_SECOND);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
case time_types::creation:
|
||||
#if defined(_WIN32)
|
||||
break;
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_ctim.tv_nsec +
|
||||
st.st_ctim.tv_sec *
|
||||
utils::time::NANOS_PER_SECOND);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
case time_types::modified:
|
||||
#if defined(_WIN32)
|
||||
break;
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
|
||||
st.st_mtim.tv_sec *
|
||||
utils::time::NANOS_PER_SECOND);
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
case time_types::write:
|
||||
#if defined(_WIN32)
|
||||
break;
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(st.st_mtim.tv_nsec +
|
||||
st.st_mtim.tv_sec *
|
||||
utils::time::NANOS_PER_SECOND);
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
return i_fs_item::get_time(type);
|
||||
}
|
||||
|
||||
auto file::move_to(std::string_view path) -> bool {
|
||||
@ -456,7 +437,7 @@ auto file::write(const unsigned char *data, std::size_t to_write,
|
||||
return false;
|
||||
}
|
||||
|
||||
auto file::size() const -> std::uint64_t {
|
||||
auto file::size() const -> std::optional<std::uint64_t> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
@ -491,6 +472,6 @@ auto file::size() const -> std::uint64_t {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return 0U;
|
||||
return std::nullopt;
|
||||
}
|
||||
} // namespace repertory::utils::file
|
||||
|
@ -201,19 +201,9 @@ auto smb_directory::create_file(std::string_view file_name,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
smb_stat_t st{smb_fstat(session_.get(), tid_, rel_path.c_str())};
|
||||
if (not st) {
|
||||
smb_fclose(session_.get(), fd);
|
||||
throw std::runtime_error("failed to stat file|" + rel_path);
|
||||
}
|
||||
|
||||
return std::make_unique<smb_file>(
|
||||
smb_stat_get(st.get(), SMB_STAT_ATIME),
|
||||
smb_stat_get(st.get(), SMB_STAT_CTIME), fd,
|
||||
smb_stat_get(st.get(), SMB_STAT_MTIME),
|
||||
smb_create_smb_path(path_, std::string{rel_path}), session_,
|
||||
share_name_, smb_stat_get(st.get(), SMB_STAT_SIZE), tid_,
|
||||
smb_stat_get(st.get(), SMB_STAT_WTIME));
|
||||
fd, smb_create_smb_path(path_, std::string{rel_path}), session_,
|
||||
share_name_, tid_);
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
@ -361,12 +351,8 @@ auto smb_directory::get_file(std::string_view path) const -> fs_file_t {
|
||||
}
|
||||
|
||||
return std::make_unique<smb_file>(
|
||||
smb_stat_get(st.get(), SMB_STAT_ATIME),
|
||||
smb_stat_get(st.get(), SMB_STAT_CTIME), std::nullopt,
|
||||
smb_stat_get(st.get(), SMB_STAT_MTIME),
|
||||
smb_create_smb_path(path_, std::string{rel_path}), session_,
|
||||
share_name_, smb_stat_get(st.get(), SMB_STAT_SIZE), tid_,
|
||||
smb_stat_get(st.get(), SMB_STAT_WTIME));
|
||||
std::nullopt, smb_create_smb_path(path_, std::string{rel_path}),
|
||||
session_, share_name_, tid_);
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
@ -404,11 +390,8 @@ auto smb_directory::get_files() const -> std::vector<fs_file_t> {
|
||||
|
||||
std::string name{smb_stat_name(st)};
|
||||
ret.emplace_back(std::make_unique<smb_file>(
|
||||
smb_stat_get(st, SMB_STAT_ATIME), smb_stat_get(st, SMB_STAT_CTIME),
|
||||
std::nullopt, smb_stat_get(st, SMB_STAT_MTIME),
|
||||
smb_create_smb_path(path_, name), session_, share_name_,
|
||||
smb_stat_get(st, SMB_STAT_SIZE), tid_,
|
||||
smb_stat_get(st, SMB_STAT_WTIME)));
|
||||
std::nullopt, smb_create_smb_path(path_, name), session_, share_name_,
|
||||
tid_));
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -462,10 +445,8 @@ auto smb_directory::get_items() const -> std::vector<fs_item_t> {
|
||||
}
|
||||
|
||||
ret.emplace_back(std::make_unique<smb_file>(
|
||||
smb_stat_get(st, SMB_STAT_ATIME), smb_stat_get(st, SMB_STAT_CTIME),
|
||||
std::nullopt, smb_stat_get(st, SMB_STAT_MTIME),
|
||||
smb_create_smb_path(path_, name), session_, share_name_, tid_,
|
||||
smb_stat_get(st, SMB_STAT_SIZE), smb_stat_get(st, SMB_STAT_WTIME)));
|
||||
std::nullopt, smb_create_smb_path(path_, name), session_, share_name_,
|
||||
tid_));
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -478,44 +459,6 @@ auto smb_directory::get_items() const -> std::vector<fs_item_t> {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto smb_directory::get_time(time_types type) const -> std::uint64_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
if (not session_) {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_relative_path(path_);
|
||||
smb_stat_t st{smb_fstat(session_.get(), tid_, rel_path.c_str())};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat directory|" + rel_path);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case time_types::access:
|
||||
return smb_stat_get(st.get(), SMB_STAT_ATIME);
|
||||
|
||||
case time_types::creation:
|
||||
return smb_stat_get(st.get(), SMB_STAT_CTIME);
|
||||
|
||||
case time_types::modified:
|
||||
return smb_stat_get(st.get(), SMB_STAT_MTIME);
|
||||
|
||||
case time_types::write:
|
||||
return smb_stat_get(st.get(), SMB_STAT_WTIME);
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
auto smb_directory::move_to(std::string_view new_path) -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
|
@ -75,6 +75,45 @@ void smb_file::flush() const {
|
||||
}
|
||||
}
|
||||
|
||||
auto smb_file::get_time(smb_session *session, smb_tid tid, std::string path,
|
||||
time_types type) -> std::uint64_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
if (session == nullptr) {
|
||||
throw std::runtime_error("session not found|" + path);
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_relative_path(path);
|
||||
smb_stat_t st{smb_fstat(session, tid, rel_path.c_str())};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat directory|" + rel_path);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case time_types::access:
|
||||
return smb_stat_get(st.get(), SMB_STAT_ATIME);
|
||||
|
||||
case time_types::creation:
|
||||
return smb_stat_get(st.get(), SMB_STAT_CTIME);
|
||||
|
||||
case time_types::modified:
|
||||
return smb_stat_get(st.get(), SMB_STAT_MTIME);
|
||||
|
||||
case time_types::write:
|
||||
return smb_stat_get(st.get(), SMB_STAT_WTIME);
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
auto smb_file::move_to(std::string_view new_path) -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
@ -259,6 +298,32 @@ auto smb_file::remove() -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto smb_file::size() const -> std::optional<std::uint64_t> {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
if (not session_) {
|
||||
throw std::runtime_error("session not found|" + path_);
|
||||
}
|
||||
|
||||
auto rel_path = smb_create_relative_path(path_);
|
||||
smb_stat_t st{smb_fstat(session_.get(), tid_, rel_path.c_str())};
|
||||
if (not st) {
|
||||
throw std::runtime_error("failed to stat directory|" + rel_path);
|
||||
}
|
||||
|
||||
return smb_stat_get(st.get(), SMB_STAT_SIZE);
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto smb_file::truncate(std::size_t size) -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
|
@ -39,8 +39,6 @@ void thread_file::close() {}
|
||||
|
||||
void thread_file::flush() const {}
|
||||
|
||||
auto thread_file::get_time(time_types type) const -> std::uint64_t {}
|
||||
|
||||
auto thread_file::move_to(std::string_view path) -> bool {}
|
||||
|
||||
auto thread_file::read(unsigned char *data, std::size_t to_read,
|
||||
@ -54,5 +52,5 @@ auto thread_file::write(const unsigned char *data, std::size_t to_write,
|
||||
std::size_t offset,
|
||||
std::size_t *total_written) -> bool {}
|
||||
|
||||
auto thread_file::size() const -> std::uint64_t {}
|
||||
auto thread_file::size() const -> std::optional<std::uint64_t> {}
|
||||
} // namespace repertory::utils::file
|
||||
|
@ -148,7 +148,7 @@ auto find_program_in_path(const std::string &name_without_extension)
|
||||
for (auto &&extension : extension_list) {
|
||||
auto exec_path = combine(
|
||||
search_path, {name_without_extension + std::string{extension}});
|
||||
if (utils::file::is_file(exec_path)) {
|
||||
if (utils::file::file(exec_path).exists()) {
|
||||
found_items[name_without_extension] = exec_path;
|
||||
return exec_path;
|
||||
}
|
||||
|
@ -34,20 +34,6 @@ auto filetime_to_unix_time(const FILETIME &file_time) -> std::uint64_t {
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
auto get_file_time_now() -> std::uint64_t {
|
||||
#if defined(_WIN32)
|
||||
SYSTEMTIME sys_time{};
|
||||
::GetSystemTime(&sys_time);
|
||||
|
||||
FILETIME file_time{};
|
||||
::SystemTimeToFileTime(&sys_time, &file_time);
|
||||
return static_cast<std::uint64_t>(
|
||||
(reinterpret_cast<LARGE_INTEGER *>(&file_time))->QuadPart);
|
||||
#else // !defined(_WIN32)
|
||||
return get_time_now();
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
void get_local_time_now(struct tm &local_time) {
|
||||
std::memset(&local_time, 0, sizeof(local_time));
|
||||
|
||||
@ -62,20 +48,10 @@ void get_local_time_now(struct tm &local_time) {
|
||||
|
||||
auto get_time_now() -> std::uint64_t {
|
||||
#if defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()));
|
||||
return static_cast<std::uint64_t>(_time64(nullptr));
|
||||
#else // !defined(_WIN32)
|
||||
return static_cast<std::uint64_t>(time(nullptr));
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
#if defined(__APPLE__)
|
||||
return std::chrono::nanoseconds(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
.count();
|
||||
#else // !defined(__APPLE__)
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::nanoseconds(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch())
|
||||
.count());
|
||||
#endif // defined(__APPLE__)
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
@ -41,7 +41,8 @@ static void delete_generated_files() {
|
||||
generated_files.clear();
|
||||
|
||||
if (parent_path.has_value()) {
|
||||
EXPECT_TRUE(repertory::utils::file::remove_directory(*parent_path, true));
|
||||
EXPECT_TRUE(
|
||||
repertory::utils::file::directory(*parent_path).remove_recursively());
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,8 +111,8 @@ auto get_test_output_dir() -> std::string {
|
||||
auto path = utils::path::combine("/tmp", {temp});
|
||||
#endif // defined(_WIN32)
|
||||
|
||||
if (not utils::file::is_directory(path)) {
|
||||
EXPECT_TRUE(utils::file::create_directories(path));
|
||||
if (not utils::file::directory(path).exists()) {
|
||||
EXPECT_TRUE(utils::file::directory{path}.create_directory());
|
||||
}
|
||||
|
||||
return path;
|
||||
|
@ -29,13 +29,14 @@ namespace repertory {
|
||||
TEST(utils_file, can_create_file) {
|
||||
for (auto idx = 0U; idx < file_type_count; ++idx) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
EXPECT_FALSE(utils::file::is_file(path) || utils::file::is_directory(path));
|
||||
EXPECT_FALSE(utils::file::file(path).exists() ||
|
||||
utils::file::directory(path).exists());
|
||||
|
||||
auto file = idx == 0U ? utils::file::file::open_or_create_file(path)
|
||||
: utils::file::thread_file::open_or_create_file(path);
|
||||
EXPECT_TRUE(*file);
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(path));
|
||||
EXPECT_TRUE(utils::file::file(path).exists());
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,7 +76,7 @@ TEST(utils_file, write_fails_for_read_only_file) {
|
||||
auto file = idx == 0U
|
||||
? utils::file::file::open_or_create_file(path, true)
|
||||
: utils::file::thread_file::open_or_create_file(path, true);
|
||||
EXPECT_TRUE(utils::file::is_file(path));
|
||||
EXPECT_TRUE(utils::file::file(path).exists());
|
||||
EXPECT_TRUE(*file);
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_FALSE(file->write(reinterpret_cast<const unsigned char *>("0"), 1U,
|
||||
|
Reference in New Issue
Block a user