mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 22:56:12 -04:00
Fixed the file implementations, they weren't using a mode, and the base path was always set to /tmp/.
We now get the systems idea of where the users download folder is and use that as the base path when receiving a file. PiperOrigin-RevId: 406406731
This commit is contained in:
committed by
Copybara-Service
parent
acf516189b
commit
44fad7d8fb
@@ -150,8 +150,6 @@ cc_test(
|
||||
"count_down_latch_test.cc",
|
||||
"crypto_test.cc",
|
||||
"executor_test.cc",
|
||||
"input_file_test.cc",
|
||||
"output_file_test.cc",
|
||||
"scheduled_executor_test.cc",
|
||||
"submittable_executor_test.cc",
|
||||
],
|
||||
|
||||
@@ -105,7 +105,7 @@ ExceptionOr<ByteArray> BluetoothSocket::BluetoothInputStream::Read(
|
||||
|
||||
Buffer buffer = Buffer(size);
|
||||
|
||||
winrt_stream_.ReadAsync(buffer, size, InputStreamOptions::None).get();
|
||||
winrt_stream_.ReadAsync(buffer, size, InputStreamOptions::Partial).get();
|
||||
|
||||
DataReader dataReader = DataReader::FromBuffer(buffer);
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ TEST_F(InputFileTests, SuccessfulGetFilePath) {
|
||||
EXPECT_EQ(inputFile->Close(),
|
||||
location::nearby::Exception{location::nearby::Exception::kSuccess});
|
||||
|
||||
EXPECT_EQ(fileName, TEST_PATH);
|
||||
EXPECT_EQ(fileName, test_utils::GetPayloadPath(payloadId).c_str());
|
||||
}
|
||||
|
||||
TEST_F(InputFileTests, SuccessfulGetTotalSize) {
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
|
||||
#include "platform/api/platform.h"
|
||||
|
||||
#include <shlobj.h>
|
||||
|
||||
#include "platform/impl/shared/count_down_latch.h"
|
||||
#include "platform/impl/shared/file.h"
|
||||
#include "platform/impl/windows/atomic_boolean.h"
|
||||
#include "platform/impl/windows/atomic_reference.h"
|
||||
@@ -22,7 +25,6 @@
|
||||
#include "platform/impl/windows/bluetooth_classic_medium.h"
|
||||
#include "platform/impl/windows/cancelable.h"
|
||||
#include "platform/impl/windows/condition_variable.h"
|
||||
#include "platform/impl/shared/count_down_latch.h"
|
||||
#include "platform/impl/windows/executor.h"
|
||||
#include "platform/impl/windows/future.h"
|
||||
#include "platform/impl/windows/listenable_future.h"
|
||||
@@ -41,7 +43,28 @@ namespace api {
|
||||
namespace {
|
||||
|
||||
std::string GetPayloadPath(PayloadId payload_id) {
|
||||
return absl::StrCat("/tmp/", payload_id);
|
||||
PWSTR basePath;
|
||||
|
||||
// Retrieves the full path of a known folder identified by the folder's
|
||||
// KNOWNFOLDERID.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath
|
||||
SHGetKnownFolderPath(
|
||||
FOLDERID_Downloads, // rfid: A reference to the KNOWNFOLDERID that
|
||||
// identifies the folder.
|
||||
0, // dwFlags: Flags that specify special retrieval options.
|
||||
NULL, // hToken: An access token that represents a particular user.
|
||||
&basePath); // ppszPath: When this method returns, contains the address
|
||||
// of a pointer to a null-terminated Unicode string that
|
||||
// specifies the path of the known folder. The calling
|
||||
// process is responsible for freeing this resource once it
|
||||
// is no longer needed by calling CoTaskMemFree, whether
|
||||
// SHGetKnownFolderPath succeeds or not.
|
||||
|
||||
char* fullpathUTF8 = new char((wcslen(basePath) + 1) * sizeof(char));
|
||||
wcstombs(fullpathUTF8, basePath, (wcslen(basePath) + 1) * sizeof(char));
|
||||
std::string fullPath = std::string(fullpathUTF8);
|
||||
auto retval = absl::StrCat(fullPath += "/", payload_id);
|
||||
return retval;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -71,14 +94,13 @@ ImplementationPlatform::CreateConditionVariable(Mutex* mutex) {
|
||||
|
||||
std::unique_ptr<InputFile> ImplementationPlatform::CreateInputFile(
|
||||
PayloadId payload_id, std::int64_t total_size) {
|
||||
return absl::make_unique<shared::InputFile>(
|
||||
GetPayloadPath(payload_id), total_size);
|
||||
return absl::make_unique<shared::InputFile>(GetPayloadPath(payload_id),
|
||||
total_size);
|
||||
}
|
||||
|
||||
std::unique_ptr<OutputFile> ImplementationPlatform::CreateOutputFile(
|
||||
PayloadId payload_id) {
|
||||
return absl::make_unique<shared::OutputFile>(
|
||||
GetPayloadPath(payload_id));
|
||||
return absl::make_unique<shared::OutputFile>(GetPayloadPath(payload_id));
|
||||
}
|
||||
|
||||
// TODO(b/184975123): replace with real implementation.
|
||||
@@ -111,8 +133,7 @@ ImplementationPlatform::CreateBluetoothAdapter() {
|
||||
std::unique_ptr<BluetoothClassicMedium>
|
||||
ImplementationPlatform::CreateBluetoothClassicMedium(
|
||||
nearby::api::BluetoothAdapter& adapter) {
|
||||
return absl::make_unique<windows::BluetoothClassicMedium>(
|
||||
adapter);
|
||||
return absl::make_unique<windows::BluetoothClassicMedium>(adapter);
|
||||
}
|
||||
|
||||
// TODO(b/184975123): replace with real implementation.
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
#include "platform/impl/windows/test_utils.h"
|
||||
|
||||
#include <shlobj.h>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
|
||||
namespace test_utils {
|
||||
@@ -29,8 +31,27 @@ std::wstring StringToWideString(const std::string& s) {
|
||||
}
|
||||
|
||||
std::string GetPayloadPath(location::nearby::PayloadId payload_id) {
|
||||
auto returnString = absl::StrCat("/tmp/", payload_id);
|
||||
PWSTR basePath;
|
||||
|
||||
return returnString;
|
||||
// Retrieves the full path of a known folder identified by the folder's
|
||||
// KNOWNFOLDERID.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath
|
||||
SHGetKnownFolderPath(
|
||||
FOLDERID_Downloads, // rfid: A reference to the KNOWNFOLDERID that
|
||||
// identifies the folder.
|
||||
0, // dwFlags: Flags that specify special retrieval options.
|
||||
NULL, // hToken: An access token that represents a particular user.
|
||||
&basePath); // ppszPath: When this method returns, contains the address
|
||||
// of a pointer to a null-terminated Unicode string that
|
||||
// specifies the path of the known folder. The calling
|
||||
// process is responsible for freeing this resource once it
|
||||
// is no longer needed by calling CoTaskMemFree, whether
|
||||
// SHGetKnownFolderPath succeeds or not.
|
||||
|
||||
char* fullpathUTF8 = new char((wcslen(basePath) + 1) * sizeof(char));
|
||||
wcstombs(fullpathUTF8, basePath, (wcslen(basePath) + 1) * sizeof(char));
|
||||
std::string fullPath = std::string(fullpathUTF8);
|
||||
auto retval = absl::StrCat(fullPath += "/", payload_id);
|
||||
return retval;
|
||||
}
|
||||
} // namespace test_utils
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "platform/base/payload_id.h"
|
||||
|
||||
#define TEST_BUFFER_SIZE 256
|
||||
#define TEST_PATH "/tmp/64"
|
||||
#define TEST_PAYLOAD_ID 64l
|
||||
#define TEST_STRING \
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas " \
|
||||
|
||||
Reference in New Issue
Block a user