using ::aidl::com::android::server::art::FsPermission; using ::android::base::Error; using ::android::base::ReadFileToString; using ::android::base::Result; using ::android::base::WriteStringToFd; using ::android::base::WriteStringToFile; using ::android::base::testing::HasError; using ::android::base::testing::HasValue; using ::android::base::testing::Ok; using ::android::base::testing::WithMessage; using ::testing::ContainsRegex; using ::testing::IsEmpty; using ::testing::NotNull;
// New files are committed.
CheckContent(file_1_path, "new_file_1");
CheckContent(file_2_path, "new_file_2");
// New files are no longer at the temporary paths.
EXPECT_FALSE(std::filesystem::exists(new_file_1->TempPath()));
EXPECT_FALSE(std::filesystem::exists(new_file_2->TempPath()));
}
// New files are committed.
CheckContent(file_1_path, "new_file_1");
CheckContent(file_2_path, "new_file_2");
// New files are no longer at the temporary paths.
EXPECT_FALSE(std::filesystem::exists(new_file_1->TempPath()));
EXPECT_FALSE(std::filesystem::exists(new_file_2->TempPath()));
}
// New files are committed.
CheckContent(file_1_path, "new_file_1");
CheckContent(file_2_path, "new_file_2");
// New files are no longer at the temporary paths.
EXPECT_FALSE(std::filesystem::exists(new_file_1->TempPath()));
EXPECT_FALSE(std::filesystem::exists(new_file_2->TempPath()));
}
// New files are committed.
CheckContent(file_1_path, "new_file_1");
CheckContent(file_2_path, "new_file_2");
EXPECT_FALSE(std::filesystem::exists(file_3_path)); // Extra file removed.
// New files are no longer at the temporary paths.
EXPECT_FALSE(std::filesystem::exists(new_file_1->TempPath()));
EXPECT_FALSE(std::filesystem::exists(new_file_2->TempPath()));
}
// Old files are fine.
CheckContent(file_1_path, "old_file_1");
CheckContent(file_2_path, "old_file_2");
CheckContent(file_3_path, "old_file_3");
// New files are abandoned.
EXPECT_FALSE(std::filesystem::exists(new_file_1->TempPath()));
EXPECT_FALSE(std::filesystem::exists(new_file_2->TempPath()));
}
{ // Make `new_file_2` fail to commit. auto scoped_inaccessible = ScopedInaccessible(dir_2_path);
std::filesystem::permissions(
dir_2_path, std::filesystem::perms::owner_exec, std::filesystem::perm_options::add); auto scoped_unroot = ScopedUnroot();
EXPECT_THAT(NewFile::CommitAllOrAbandon({new_file_1.get(), new_file_2.get()}),
HasError(WithMessage(ContainsRegex("Failed to move file .*file_2.*"))));
}
// Files are abandoned at best effort. File 1 is abandoned, but file 2 cannot be abandoned due to // permission denied.
EXPECT_FALSE(std::filesystem::exists(new_file_1->TempPath()));
EXPECT_FALSE(std::filesystem::exists(new_file_1->FinalPath()));
EXPECT_TRUE(std::filesystem::exists(new_file_2->TempPath()));
EXPECT_FALSE(std::filesystem::exists(new_file_2->FinalPath()));
}
// file_2 is not movable because it is a directory.
EXPECT_THAT(NewFile::CommitAllOrAbandon({new_file_1.get(), new_file_2.get()}, {file_3_path}),
HasError(WithMessage(ContainsRegex("Old file '.*/file_2' is a directory"))));
// Old files are fine.
CheckContent(file_1_path, "old_file_1");
EXPECT_TRUE(std::filesystem::is_directory(file_2_path));
CheckContent(file_3_path, "old_file_3");
// New files are abandoned.
EXPECT_FALSE(std::filesystem::exists(new_file_1->TempPath()));
EXPECT_FALSE(std::filesystem::exists(new_file_2->TempPath()));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.