Add parent_folder support for custom save path

PiperOrigin-RevId: 493415518
This commit is contained in:
Aaron Yu
2022-12-06 14:39:07 -08:00
committed by Copybara-Service
parent fa7c8a2ec8
commit 4762d1e3ee
@@ -315,23 +315,25 @@ std::unique_ptr<InternalPayload> CreateOutgoingInternalPayload(
}
}
std::string make_path(std::string& parent_folder, std::string& file_name) {
if (!parent_folder.empty()) {
return std::string(api::ImplementationPlatform::GetCustomSavePath(
parent_folder, file_name));
// if custom_save_path is empty, default download path is used
std::string make_path(const std::string& custom_save_path,
std::string& parent_folder, std::string& file_name) {
if (!custom_save_path.empty()) {
std::string path = absl::StrCat(custom_save_path, "/", parent_folder);
return api::ImplementationPlatform::GetCustomSavePath(path, file_name);
}
return std::string(
api::ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
return api::ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
}
std::string make_path(std::string& parent_folder, int64_t id) {
// if custom_save_path is empty, default download path is used
std::string make_path(const std::string& custom_save_path,
std::string& parent_folder, int64_t id) {
std::string file_name(std::to_string(id));
if (!parent_folder.empty()) {
return std::string(api::ImplementationPlatform::GetCustomSavePath(
parent_folder, file_name));
if (!custom_save_path.empty()) {
std::string path = absl::StrCat(custom_save_path, "/", parent_folder);
return api::ImplementationPlatform::GetCustomSavePath(path, file_name);
}
return std::string(
api::ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
return api::ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
}
std::unique_ptr<InternalPayload> CreateIncomingInternalPayload(
@@ -359,9 +361,9 @@ std::unique_ptr<InternalPayload> CreateIncomingInternalPayload(
}
case PayloadTransferFrame::PayloadHeader::FILE: {
std::string parent_folder(custom_save_path);
std::string file_name("");
std::string file_path("");
std::string parent_folder;
std::string file_name;
std::string file_path;
int64_t total_size = 0;
@@ -371,11 +373,13 @@ std::unique_ptr<InternalPayload> CreateIncomingInternalPayload(
if (frame.payload_header().has_file_name()) {
file_name = frame.payload_header().file_name();
file_path = make_path(parent_folder, file_name);
// if custom_save_path is empty, default download path is used
file_path = make_path(custom_save_path, parent_folder, file_name);
} else {
if (frame.payload_header().has_id()) {
file_name = std::to_string(frame.payload_header().id());
file_path = make_path(parent_folder, file_name);
// if custom_save_path is empty, default download path is used
file_path = make_path(custom_save_path, parent_folder, file_name);
} else {
// This is an error condition, we don't have any way to generate a
// file name for the output file.