mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
The file was overwritten when transferring a file that already existed in the downloads folder. With this change we now add " (x)", where x is an incrementing number, starting at 1, using the next non-existing number, to the file name, just before the first dot, or at the end if no dot. This has been applied to the GetDownloadPath method in the platform api.
PiperOrigin-RevId: 457530287
This commit is contained in:
committed by
Copybara-Service
parent
9ce81d8534
commit
87c76ea235
@@ -14,8 +14,10 @@
|
||||
|
||||
#include "internal/platform/implementation/shared/file.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
@@ -42,10 +44,9 @@ std::unique_ptr<IOFile> IOFile::CreateOutputFile(const absl::string_view path) {
|
||||
}
|
||||
|
||||
IOFile::IOFile(const absl::string_view file_path)
|
||||
: file_(std::string(file_path.data(), file_path.size()),
|
||||
std::ios::binary | std::ios::out | std::ios::trunc),
|
||||
path_({file_path.data(), file_path.size()}),
|
||||
total_size_(0) {}
|
||||
: file_(), path_(file_path), total_size_(0) {
|
||||
file_.open(path_, std::ios::binary | std::ios::out);
|
||||
}
|
||||
|
||||
ExceptionOr<ByteArray> IOFile::Read(std::int64_t size) {
|
||||
if (!file_.is_open()) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/exception.h"
|
||||
@@ -35,9 +36,9 @@ class IOFile final : public api::InputFile, public api::OutputFile {
|
||||
static std::unique_ptr<IOFile> CreateOutputFile(const absl::string_view path);
|
||||
|
||||
ExceptionOr<ByteArray> Read(std::int64_t size) override;
|
||||
std::string GetFilePath() const override {
|
||||
return std::string(path_.data(), path_.size());
|
||||
}
|
||||
|
||||
std::string GetFilePath() const override { return path_; }
|
||||
|
||||
std::int64_t GetTotalSize() const override { return total_size_; }
|
||||
Exception Close() override;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "file/util/temp_path.h"
|
||||
#include "gtest/gtest.h"
|
||||
@@ -133,7 +134,8 @@ TEST_F(FileTest, IOFile_Write) {
|
||||
ByteArray bytes2("bc");
|
||||
EXPECT_EQ(io_file_output->Write(bytes1), Exception{Exception::kSuccess});
|
||||
EXPECT_EQ(io_file_output->Write(bytes2), Exception{Exception::kSuccess});
|
||||
auto io_file_input = shared::IOFile::CreateInputFile(path_, GetSize());
|
||||
auto io_file_input =
|
||||
shared::IOFile::CreateInputFile(io_file_output->GetFilePath(), GetSize());
|
||||
AssertEquals(io_file_input->Read(kMaxSize), "abc");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user