mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Prevent crash when failed to create output dir.
PiperOrigin-RevId: 712709379
This commit is contained in:
committed by
Copybara-Service
parent
e458d6afaa
commit
b7de2347b8
@@ -61,6 +61,7 @@ OutputFile::~OutputFile() = default;
|
||||
OutputFile::OutputFile(OutputFile&&) noexcept = default;
|
||||
OutputFile& OutputFile::operator=(OutputFile&&) = default;
|
||||
|
||||
bool OutputFile::IsValid() const { return impl_ != nullptr; }
|
||||
// Writes all data from ByteArray object to the underlying stream.
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
Exception OutputFile::Write(const ByteArray& data) {
|
||||
|
||||
@@ -77,6 +77,8 @@ class OutputFile final {
|
||||
OutputFile(OutputFile&&) noexcept;
|
||||
OutputFile& operator=(OutputFile&&);
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
// Writes all data from ByteArray object to the underlying stream.
|
||||
// Returns Exception::kIo on error, Exception::kSuccess otherwise.
|
||||
Exception Write(const ByteArray& data);
|
||||
|
||||
@@ -155,7 +155,9 @@ cc_library(
|
||||
":comm",
|
||||
":crypto", # build_cleaner: keep
|
||||
":types",
|
||||
"//internal/base:files",
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform:test_util",
|
||||
"//internal/platform/implementation:comm",
|
||||
"//internal/platform/implementation:platform",
|
||||
@@ -163,11 +165,9 @@ cc_library(
|
||||
"//internal/platform/implementation/shared:count_down_latch",
|
||||
"//internal/platform/implementation/shared:file",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/memory",
|
||||
"@com_google_absl//absl/status",
|
||||
"@com_google_absl//absl/status:statusor",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/time",
|
||||
"@com_google_nisaba//nisaba/port:thread_pool",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -14,19 +14,18 @@
|
||||
|
||||
#include "internal/platform/implementation/platform.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem> // NOLINT
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/base/files.h"
|
||||
#include "internal/platform/implementation/atomic_boolean.h"
|
||||
#include "internal/platform/implementation/atomic_reference.h"
|
||||
#include "internal/platform/implementation/ble.h"
|
||||
@@ -51,6 +50,7 @@
|
||||
#include "internal/platform/implementation/wifi_direct.h"
|
||||
#include "internal/platform/implementation/wifi_hotspot.h"
|
||||
#include "internal/platform/implementation/wifi_lan.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/os_name.h"
|
||||
#include "internal/platform/payload_id.h"
|
||||
#include "thread/thread.h"
|
||||
@@ -86,7 +86,7 @@ namespace api {
|
||||
|
||||
std::string ImplementationPlatform::GetCustomSavePath(
|
||||
const std::string& parent_folder, const std::string& file_name) {
|
||||
return absl::StrCat(parent_folder, file_name);
|
||||
return absl::StrCat(parent_folder, "/", file_name);
|
||||
}
|
||||
|
||||
std::string ImplementationPlatform::GetDownloadPath(
|
||||
@@ -162,6 +162,15 @@ std::unique_ptr<OutputFile> ImplementationPlatform::CreateOutputFile(
|
||||
|
||||
std::unique_ptr<OutputFile> ImplementationPlatform::CreateOutputFile(
|
||||
const std::string& file_path) {
|
||||
std::filesystem::path path = std::filesystem::u8path(file_path);
|
||||
std::filesystem::path folder_path = path.parent_path();
|
||||
// Verifies that a path is a valid directory.
|
||||
if (!sharing::DirectoryExists(folder_path)) {
|
||||
if (!sharing::CreateDirectories(folder_path)) {
|
||||
LOG(ERROR) << "Failed to create directory: " << folder_path.string();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return shared::IOFile::CreateOutputFile(file_path);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user