Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fcitx
Browse files Browse the repository at this point in the history
  • Loading branch information
Fcitx Bot committed Dec 20, 2024
2 parents fe4c963 + b7faa84 commit 22ab9e6
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 131 deletions.
4 changes: 2 additions & 2 deletions src/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ bazel_dep(
version = "1.7.1",
)

# rules_python: 0.34.0 2024-07-01
# rules_python: 1.0.0 2024-12-06
# https://github.com/bazelbuild/rules_python/
bazel_dep(
name = "rules_python",
version = "0.34.0",
version = "1.0.0",
)

# Bazel macOS build (3.16.1 2024-12-13)
Expand Down
36 changes: 0 additions & 36 deletions src/base/file_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -701,40 +701,4 @@ void FileUtil::SetMockForUnitTest(FileUtilInterface *mock) {
FileUtilSingleton::SetMock(mock);
}

absl::Status FileUtil::LinkOrCopyFile(const std::string &src_path,
const std::string &dst_path) {
absl::StatusOr<bool> is_equiv = FileUtil::IsEquivalent(src_path, dst_path);
if (!is_equiv.ok()) {
LOG(WARNING) << "Cannot test file equivalence: " << is_equiv.status();
// Try hard link or copy.
} else if (*is_equiv) {
// IsEquivalent() checks if src and dst are the same path or sym/hard link.
// This does not check the contents of the files.
return absl::OkStatus();
}

const std::string tmp_dst_path = dst_path + ".tmp";
FileUtil::UnlinkOrLogError(tmp_dst_path);
if (absl::Status s = FileUtil::CreateHardLink(src_path, tmp_dst_path);
!s.ok()) {
LOG(WARNING) << "Cannot create hardlink from " << src_path << " to "
<< tmp_dst_path << ": " << s;
// If an error happens, fallback to file copy.
if (absl::Status s = FileUtil::CopyFile(src_path, tmp_dst_path); !s.ok()) {
return absl::Status(
s.code(), absl::StrCat("Cannot copy file. from: ", src_path,
" to: ", tmp_dst_path, ": ", s.message()));
}
}

if (absl::Status s = FileUtil::AtomicRename(tmp_dst_path, dst_path);
!s.ok()) {
return absl::Status(
s.code(), absl::StrCat("AtomicRename failed: ", s.message(),
"; from: ", tmp_dst_path, ", to: ", dst_path));
}

return absl::OkStatus();
}

} // namespace mozc
4 changes: 0 additions & 4 deletions src/base/file_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ class FileUtil {

// Sets a mock for unittest.
static void SetMockForUnitTest(FileUtilInterface *mock);

// Make a hard-link or copy of `src_file`.
static absl::Status LinkOrCopyFile(const std::string &src_path,
const std::string &dst_path);
};

// RAII wrapper for a file. Unlinks the file when this instance goes out of
Expand Down
14 changes: 0 additions & 14 deletions src/base/file_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,19 +548,5 @@ TEST(FileUtilTest, FileUnlinker) {
EXPECT_FALSE(FileUtil::FileExists(temp_file->path()).ok());
}

TEST(FileUtilTest, LinkOrCopyFile) {
TempDirectory temp_dir = testing::MakeTempDirectoryOrDie();
const std::string from =
FileUtil::JoinPath(temp_dir.path(), "link_or_copy_test_from.txt");
const std::string to =
FileUtil::JoinPath(temp_dir.path(), "link_or_copy_test_to.txt");
EXPECT_TRUE(!FileUtil::LinkOrCopyFile(from, to).ok());
ASSERT_OK(FileUtil::SetContents(from, "test"));
EXPECT_OK(FileUtil::LinkOrCopyFile(from, to));
auto s = FileUtil::IsEqualFile(from, to);
EXPECT_OK(s);
EXPECT_TRUE(*s);
}

} // namespace
} // namespace mozc
11 changes: 0 additions & 11 deletions src/engine/data_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,6 @@ std::unique_ptr<DataLoader::Response> DataLoader::BuildResponse(
}
}

// Copies file to install location.
if (request.has_install_location()) {
const absl::Status status = FileUtil::LinkOrCopyFile(
request.file_path(), request.install_location());
if (!status.ok()) {
LOG(ERROR) << "Copy faild: [" << status << "] " << request_data;
result->response.set_status(EngineReloadResponse::INSTALL_FAILURE);
return result;
}
}

auto modules = std::make_unique<engine::Modules>();
{
const absl::Status status = modules->Init(std::move(data_manager));
Expand Down
57 changes: 1 addition & 56 deletions src/engine/data_loader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ class DataLoaderTest : public testing::TestWithTempUserProfile,
EngineReloadRequest oss_request_;
};

TEST_P(DataLoaderTest, AsyncBuildWithoutInstall) {
// Test request without install.
TEST_P(DataLoaderTest, AsyncBuild) {
request_.set_engine_type(GetParam().type);
request_.set_file_path(mock_data_path_);
request_.set_magic_number(kMockMagicNumber);
Expand Down Expand Up @@ -139,60 +138,6 @@ TEST_P(DataLoaderTest, AsyncBuildWithoutInstall) {
EXPECT_EQ(callback_called, 1);
}

TEST_P(DataLoaderTest, AsyncBuildWithInstall) {
// Test request with install. Since the requested file is copied,
// |mock_data_path_| is copied to a temporary file.
TempDirectory temp_dir = testing::MakeTempDirectoryOrDie();
const std::string src_path =
FileUtil::JoinPath({temp_dir.path(), "src.data"});
ASSERT_OK(FileUtil::CopyFile(mock_data_path_, src_path));

const std::string install_path =
FileUtil::JoinPath({temp_dir.path(), "dst.data"});

request_.set_engine_type(GetParam().type);
request_.set_file_path(src_path);
request_.set_install_location(install_path);
request_.set_magic_number(kMockMagicNumber);

DataManager data_manager;
data_manager.InitFromFile(src_path, kMockMagicNumber);
absl::string_view expected_version = data_manager.GetDataVersion();
const std::string expected_filename = data_manager.GetFilename().value();

DataLoader loader;
loader.NotifyHighPriorityDataRegisteredForTesting();

int callback_called = 0;
EXPECT_TRUE(loader.StartNewDataBuildTask(
request_, [&](std::unique_ptr<DataLoader::Response> response) {
const DataManagerInterface &response_data_manager =
response->modules->GetDataManager();
EXPECT_EQ(response_data_manager.GetDataVersion(), expected_version);
EXPECT_TRUE(response_data_manager.GetFilename());
EXPECT_EQ(response_data_manager.GetFilename().value(),
expected_filename);
EXPECT_EQ(response->response.request().engine_type(), GetParam().type);
++callback_called;
return absl::OkStatus();
}));

// Sends the same request. It is accepted, but callback is not called.
EXPECT_TRUE(loader.StartNewDataBuildTask(request_, kNeverCalled));

loader.Wait();

// Sends the same request. It is NOT accepted, as the loader finishes
// the loading process.
EXPECT_FALSE(loader.StartNewDataBuildTask(request_, kNeverCalled));

EXPECT_EQ(callback_called, 1);

// Verify |src_path| was copied.
EXPECT_OK(FileUtil::FileExists(src_path));
EXPECT_OK(FileUtil::FileExists(install_path));
}

TEST_P(DataLoaderTest, AsyncBuildRepeatedly) {
absl::BitGen bitgen;

Expand Down
10 changes: 2 additions & 8 deletions src/protocol/engine_builder.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ message EngineReloadRequest {
// Path to the data file to be loaded in a new engine.
required string file_path = 2;

// If provided, also atomically renames |file_path| to this location. Since
// EngineBuilder validates the data file content before creating a new engine
// instance, this option is useful when you want to perform i) data
// verification, ii) install (file rename), and iii) engine reload at the same
// time in Mozc server side.
optional string install_location = 3;
reserved 3; // Deprecated install_location

// Explicitly specifies the magic number to be used for data validation.
// Since acceptable magic number is embedded in Mozc server, this option is
Expand Down Expand Up @@ -89,8 +84,7 @@ message EngineReloadResponse {
// File doesn't exist or underlying memory mapping failed.
MMAP_FAILURE = 7;

// File rename is failed.
INSTALL_FAILURE = 8;
reserved "INSTALL_FAILURE"; // Deprecated INSTALL_FAILURE

UNKNOWN_ERROR = 9;
}
Expand Down

0 comments on commit 22ab9e6

Please sign in to comment.