Merge branch 'development' of https://git.fifthgrid.com/blockstorage/repertory into development
This commit is contained in:
commit
bd8da9b987
@ -72,27 +72,22 @@ E_SIMPLE3(download_restore_failed, error, true,
|
|||||||
std::string, error, err, E_STRING
|
std::string, error, err, E_STRING
|
||||||
);
|
);
|
||||||
|
|
||||||
E_SIMPLE2(download_resumed, info, true,
|
E_SIMPLE3(download_resume_add_failed, error, true,
|
||||||
std::string, api_path, ap, E_STRING,
|
|
||||||
std::string, dest_path, dest, E_STRING
|
|
||||||
);
|
|
||||||
|
|
||||||
E_SIMPLE2(download_stored, info, true,
|
|
||||||
std::string, api_path, ap, E_STRING,
|
|
||||||
std::string, dest_path, dest, E_STRING
|
|
||||||
);
|
|
||||||
|
|
||||||
E_SIMPLE2(download_stored_removed, info, true,
|
|
||||||
std::string, api_path, ap, E_STRING,
|
|
||||||
std::string, dest_path, dest, E_STRING
|
|
||||||
);
|
|
||||||
|
|
||||||
E_SIMPLE3(download_stored_failed, error, true,
|
|
||||||
std::string, api_path, ap, E_STRING,
|
std::string, api_path, ap, E_STRING,
|
||||||
std::string, dest_path, dest, E_STRING,
|
std::string, dest_path, dest, E_STRING,
|
||||||
std::string, error, err, E_STRING
|
std::string, error, err, E_STRING
|
||||||
);
|
);
|
||||||
|
|
||||||
|
E_SIMPLE2(download_resume_added, info, true,
|
||||||
|
std::string, api_path, ap, E_STRING,
|
||||||
|
std::string, dest_path, dest, E_STRING
|
||||||
|
);
|
||||||
|
|
||||||
|
E_SIMPLE2(download_resume_removed, info, true,
|
||||||
|
std::string, api_path, ap, E_STRING,
|
||||||
|
std::string, dest_path, dest, E_STRING
|
||||||
|
);
|
||||||
|
|
||||||
E_SIMPLE1(item_timeout, debug, true,
|
E_SIMPLE1(item_timeout, debug, true,
|
||||||
std::string, api_path, ap, E_STRING
|
std::string, api_path, ap, E_STRING
|
||||||
);
|
);
|
||||||
|
@ -380,11 +380,18 @@ auto file_manager::get_stored_downloads() const -> std::vector<json> {
|
|||||||
auto file_manager::handle_file_rename(const std::string &from_api_path,
|
auto file_manager::handle_file_rename(const std::string &from_api_path,
|
||||||
const std::string &to_api_path)
|
const std::string &to_api_path)
|
||||||
-> api_error {
|
-> api_error {
|
||||||
|
auto should_upload{false};
|
||||||
std::string source_path{};
|
std::string source_path{};
|
||||||
bool should_upload{upload_lookup_.contains(from_api_path)};
|
auto file_iter = open_file_lookup_.find(from_api_path);
|
||||||
|
if (file_iter != open_file_lookup_.end()) {
|
||||||
|
should_upload = file_iter->second->is_modified();
|
||||||
|
source_path = file_iter->second->get_source_path();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (not should_upload) {
|
||||||
|
should_upload = upload_lookup_.contains(from_api_path);
|
||||||
if (should_upload) {
|
if (should_upload) {
|
||||||
source_path = upload_lookup_.at(from_api_path)->get_source_path();
|
source_path = upload_lookup_.at(from_api_path)->get_source_path();
|
||||||
remove_upload(from_api_path);
|
|
||||||
} else {
|
} else {
|
||||||
auto result = db::db_select{*db_.get(), upload_table}
|
auto result = db::db_select{*db_.get(), upload_table}
|
||||||
.column("source_path")
|
.column("source_path")
|
||||||
@ -395,19 +402,22 @@ auto file_manager::handle_file_rename(const std::string &from_api_path,
|
|||||||
should_upload = result.get_row(row) && row.has_value();
|
should_upload = result.get_row(row) && row.has_value();
|
||||||
if (should_upload) {
|
if (should_upload) {
|
||||||
source_path = row->get_column("source_path").get_value<std::string>();
|
source_path = row->get_column("source_path").get_value<std::string>();
|
||||||
remove_upload(from_api_path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (should_upload) {
|
||||||
|
remove_upload(from_api_path);
|
||||||
|
}
|
||||||
|
|
||||||
auto ret = provider_.rename_file(from_api_path, to_api_path);
|
auto ret = provider_.rename_file(from_api_path, to_api_path);
|
||||||
if (ret == api_error::success) {
|
if (ret == api_error::success) {
|
||||||
swap_renamed_items(from_api_path, to_api_path);
|
swap_renamed_items(from_api_path, to_api_path);
|
||||||
|
}
|
||||||
|
|
||||||
if (should_upload) {
|
if (should_upload) {
|
||||||
queue_upload(to_api_path, source_path, false);
|
queue_upload(to_api_path, source_path, false);
|
||||||
}
|
}
|
||||||
} else if (should_upload) {
|
|
||||||
queue_upload(from_api_path, source_path, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -537,11 +547,6 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
|||||||
};
|
};
|
||||||
|
|
||||||
recur_mutex_lock open_lock(open_file_mtx_);
|
recur_mutex_lock open_lock(open_file_mtx_);
|
||||||
auto file_iter = open_file_lookup_.find(api_path);
|
|
||||||
if (file_iter != open_file_lookup_.end() &&
|
|
||||||
file_iter->second->is_modified()) {
|
|
||||||
return api_error::file_in_use;
|
|
||||||
}
|
|
||||||
|
|
||||||
filesystem_item fsi{};
|
filesystem_item fsi{};
|
||||||
auto res = provider_.get_filesystem_item(api_path, false, fsi);
|
auto res = provider_.get_filesystem_item(api_path, false, fsi);
|
||||||
@ -561,7 +566,6 @@ auto file_manager::remove_file(const std::string &api_path) -> api_error {
|
|||||||
utils::error::raise_api_path_error(
|
utils::error::raise_api_path_error(
|
||||||
function_name, fsi.api_path, fsi.source_path,
|
function_name, fsi.api_path, fsi.source_path,
|
||||||
utils::get_last_error_code(), "failed to delete source");
|
utils::get_last_error_code(), "failed to delete source");
|
||||||
return api_error::success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return api_error::success;
|
return api_error::success;
|
||||||
@ -575,7 +579,7 @@ void file_manager::remove_resume(const std::string &api_path,
|
|||||||
.equals(api_path)
|
.equals(api_path)
|
||||||
.go();
|
.go();
|
||||||
if (result.ok()) {
|
if (result.ok()) {
|
||||||
event_system::instance().raise<download_stored_removed>(api_path,
|
event_system::instance().raise<download_resume_removed>(api_path,
|
||||||
source_path);
|
source_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -760,32 +764,6 @@ auto file_manager::rename_file(const std::string &from_api_path,
|
|||||||
return api_error::item_exists;
|
return api_error::item_exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't rename if destination file has open handles
|
|
||||||
if (get_open_file_count(to_api_path) != 0U) {
|
|
||||||
return api_error::file_in_use;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle destination file exists (should overwrite)
|
|
||||||
if (dest_exists) {
|
|
||||||
filesystem_item fsi{};
|
|
||||||
res = provider_.get_filesystem_item(to_api_path, false, fsi);
|
|
||||||
if (res != api_error::success) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = remove_file(to_api_path);
|
|
||||||
if ((res == api_error::success) || (res == api_error::item_not_found)) {
|
|
||||||
if (not utils::file::file(fsi.source_path).remove()) {
|
|
||||||
utils::error::raise_api_path_error(
|
|
||||||
function_name, fsi.api_path, fsi.source_path,
|
|
||||||
utils::get_last_error_code(), "failed to delete source path");
|
|
||||||
}
|
|
||||||
return handle_file_rename(from_api_path, to_api_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check destination parent directory exists
|
// Check destination parent directory exists
|
||||||
res = provider_.is_directory(utils::path::get_parent_api_path(to_api_path),
|
res = provider_.is_directory(utils::path::get_parent_api_path(to_api_path),
|
||||||
exists);
|
exists);
|
||||||
@ -796,6 +774,14 @@ auto file_manager::rename_file(const std::string &from_api_path,
|
|||||||
return api_error::directory_not_found;
|
return api_error::directory_not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle destination file exists (should overwrite)
|
||||||
|
if (dest_exists) {
|
||||||
|
res = remove_file(to_api_path);
|
||||||
|
if ((res != api_error::success) && (res != api_error::item_not_found)) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return handle_file_rename(from_api_path, to_api_path);
|
return handle_file_rename(from_api_path, to_api_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -966,12 +952,12 @@ void file_manager::store_resume(const i_open_file &file) {
|
|||||||
.column_value("data", create_resume_entry(file).dump())
|
.column_value("data", create_resume_entry(file).dump())
|
||||||
.go();
|
.go();
|
||||||
if (result.ok()) {
|
if (result.ok()) {
|
||||||
event_system::instance().raise<download_stored>(file.get_api_path(),
|
event_system::instance().raise<download_resume_added>(
|
||||||
file.get_source_path());
|
file.get_api_path(), file.get_source_path());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_system::instance().raise<download_stored_failed>(
|
event_system::instance().raise<download_resume_add_failed>(
|
||||||
file.get_api_path(), file.get_source_path(),
|
file.get_api_path(), file.get_source_path(),
|
||||||
"failed to insert|" + std::to_string(result.get_error()) + '|' +
|
"failed to insert|" + std::to_string(result.get_error()) + '|' +
|
||||||
result.get_error_str());
|
result.get_error_str());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user