This commit is contained in:
@ -48,8 +48,6 @@ get_total_drive_space(const std::string &path) -> std::uint64_t;
|
||||
is_modified_date_older_than(std::string_view path,
|
||||
const std::chrono::hours &hours) -> bool;
|
||||
|
||||
[[nodiscard]] auto move_file(std::string from, std::string to) -> bool;
|
||||
|
||||
[[nodiscard]] auto
|
||||
read_file_lines(const std::string &path) -> std::vector<std::string>;
|
||||
|
||||
|
@ -248,24 +248,6 @@ auto is_modified_date_older_than(std::string_view path,
|
||||
utils::time::get_time_now();
|
||||
}
|
||||
|
||||
auto move_file(std::string from, std::string to) -> bool {
|
||||
from = utils::path::absolute(from);
|
||||
to = utils::path::absolute(to);
|
||||
|
||||
const auto directory = utils::path::get_parent_directory(to);
|
||||
if (not utils::file::directory(directory).create_directory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
const bool ret = ::MoveFile(from.c_str(), to.c_str()) != 0;
|
||||
#else
|
||||
const bool ret = (rename(from.c_str(), to.c_str()) == 0);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto read_file_lines(const std::string &path) -> std::vector<std::string> {
|
||||
std::vector<std::string> ret;
|
||||
if (utils::file::file(path).exists()) {
|
||||
|
@ -86,6 +86,14 @@ struct i_fs_item {
|
||||
|
||||
virtual ~i_fs_item() = default;
|
||||
|
||||
[[nodiscard]] virtual auto copy_to(std::string_view to_path,
|
||||
bool overwrite) const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto copy_to(std::wstring_view new_path,
|
||||
bool overwrite) -> bool {
|
||||
return copy_to(utils::string::to_utf8(new_path), overwrite);
|
||||
}
|
||||
|
||||
[[nodiscard]] virtual auto exists() const -> bool = 0;
|
||||
|
||||
[[nodiscard]] virtual auto get_path() const -> std::string = 0;
|
||||
@ -252,6 +260,9 @@ private:
|
||||
public:
|
||||
void close() override;
|
||||
|
||||
[[nodiscard]] auto copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto exists() const -> bool override;
|
||||
|
||||
void flush() const override;
|
||||
@ -338,6 +349,9 @@ private:
|
||||
public:
|
||||
void close() override;
|
||||
|
||||
[[nodiscard]] auto copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto exists() const -> bool override { return file_->exists(); }
|
||||
|
||||
void flush() const override;
|
||||
@ -450,6 +464,9 @@ private:
|
||||
public:
|
||||
void close() override;
|
||||
|
||||
[[nodiscard]] auto copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto exists() const -> bool override { return file_->exists(); }
|
||||
|
||||
void flush() const override;
|
||||
@ -578,6 +595,9 @@ private:
|
||||
std::string path_;
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
count(bool recursive = false) const -> std::uint64_t override;
|
||||
|
||||
@ -663,6 +683,9 @@ private:
|
||||
public:
|
||||
void close() override;
|
||||
|
||||
[[nodiscard]] auto copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto exists() const -> bool override;
|
||||
|
||||
void flush() const override;
|
||||
@ -786,6 +809,9 @@ public:
|
||||
[[nodiscard]] auto
|
||||
count(bool recursive = false) const -> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_directory(std::string_view path = "") const -> fs_directory_t override;
|
||||
|
||||
|
@ -86,6 +86,11 @@ auto traverse_directory(
|
||||
} // namespace
|
||||
|
||||
namespace repertory::utils::file {
|
||||
auto directory::copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto directory::count(bool recursive) const -> std::uint64_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
|
@ -30,6 +30,9 @@ enc_file::enc_file(fs_file_t file) : file_(std::move(file)) {}
|
||||
|
||||
void enc_file::close() {}
|
||||
|
||||
auto enc_file::copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool {}
|
||||
|
||||
void enc_file::flush() const {}
|
||||
|
||||
auto enc_file::move_to(std::string_view path) -> bool {}
|
||||
|
@ -23,11 +23,8 @@
|
||||
|
||||
#include "utils/collection.hpp"
|
||||
#include "utils/common.hpp"
|
||||
#include "utils/encryption.hpp"
|
||||
#include "utils/error.hpp"
|
||||
#include "utils/path.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "utils/time.hpp"
|
||||
|
||||
namespace {
|
||||
[[nodiscard]] auto get_file_size(std::string_view path,
|
||||
@ -190,6 +187,35 @@ void file::close() {
|
||||
file_.reset();
|
||||
}
|
||||
|
||||
auto file::copy_to(std::string_view new_path, bool overwrite) const -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
};
|
||||
|
||||
try {
|
||||
auto to_path = utils::path::absolute(new_path);
|
||||
if (directory(to_path).exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
return ::CopyFileA(path_.c_str(), to_path.c_str(),
|
||||
overwrite ? TRUE : FALSE);
|
||||
#else // !defined(_WIN32)
|
||||
return std::filesystem::copy_file(
|
||||
path_, to_path,
|
||||
overwrite ? std::filesystem::copy_options::overwrite_existing
|
||||
: std::filesystem::copy_options::skip_existing);
|
||||
#endif // defined(_WIN32)
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
auto file::exists() const -> bool {
|
||||
#if defined(_WIN32)
|
||||
recur_mutex_lock lock{*mtx_};
|
||||
|
@ -102,6 +102,30 @@ auto smb_directory::open(std::wstring_view host, std::wstring_view user,
|
||||
utils::string::to_utf8(share_name));
|
||||
}
|
||||
|
||||
auto smb_directory::copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool {
|
||||
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 to_path = utils::path::absolute(new_path);
|
||||
|
||||
throw std::runtime_error("failed to copy directory|" + path_ + '|' +
|
||||
std::string{new_path} + "|not implemented");
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
auto smb_directory::count(bool recursive) const -> std::uint64_t {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
|
@ -35,6 +35,30 @@ void smb_file::close() {
|
||||
}
|
||||
}
|
||||
|
||||
auto smb_file::copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool {
|
||||
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 to_path = utils::path::absolute(new_path);
|
||||
|
||||
throw std::runtime_error("failed to copy file|" + path_ + '|' +
|
||||
std::string{new_path} + "|not implemented");
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::handle_exception(function_name, e);
|
||||
} catch (...) {
|
||||
utils::error::handle_exception(function_name);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
auto smb_file::exists() const -> bool {
|
||||
static constexpr const std::string_view function_name{
|
||||
static_cast<const char *>(__FUNCTION__),
|
||||
|
@ -37,6 +37,9 @@ thread_file::thread_file(fs_file_t file) : file_(std::move(file)) {}
|
||||
|
||||
void thread_file::close() {}
|
||||
|
||||
auto thread_file::copy_to(std::string_view new_path,
|
||||
bool overwrite) const -> bool {}
|
||||
|
||||
void thread_file::flush() const {}
|
||||
|
||||
auto thread_file::move_to(std::string_view path) -> bool {}
|
||||
|
Reference in New Issue
Block a user