This commit is contained in:
parent
25c445b889
commit
5bd780ef07
@ -395,18 +395,20 @@ 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) {
|
}
|
||||||
queue_upload(to_api_path, source_path, false);
|
|
||||||
}
|
if (should_upload) {
|
||||||
} else if (should_upload) {
|
queue_upload(to_api_path, source_path, false);
|
||||||
queue_upload(from_api_path, source_path, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -537,11 +539,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);
|
||||||
@ -765,27 +762,6 @@ auto file_manager::rename_file(const std::string &from_api_path,
|
|||||||
return api_error::file_in_use;
|
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 +772,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user