Patch Android FileSystem::List for non-existing directory.
[ Merge of http://go/wvgerrit/210651 ] The Android FileSystem implementation for List() would return an error if the directory does not exist. This creates an issue for the case where the CDM attempts to list offline licenses after clearing all data. This typically won't effect a regular user, it causes integration tests which re-provision to fail. Bug: 372105842 Test: file_store_unittest on Oriole Change-Id: I121b52ab95e36249ae5b196e987bc950a278131f
This commit is contained in:
@@ -530,7 +530,21 @@ ssize_t FileSystem::FileSize(const std::string& file_name) {
|
||||
|
||||
bool FileSystem::List(const std::string& path,
|
||||
std::vector<std::string>* filenames) {
|
||||
return FileUtils::List(GetFileNameForIdentifier(path, origin_), filenames);
|
||||
if (filenames == nullptr) {
|
||||
LOGE("Output |filenames| is null");
|
||||
return false;
|
||||
}
|
||||
const std::string effective_path = GetFileNameForIdentifier(path, origin_);
|
||||
int errno_value = 0;
|
||||
if (FileUtils::Exists(effective_path, &errno_value)) {
|
||||
return FileUtils::List(effective_path, filenames);
|
||||
}
|
||||
filenames->clear();
|
||||
if (errno_value == 0 || errno_value == ENOENT) {
|
||||
return true;
|
||||
}
|
||||
LOGE("Cannot list: errno = %d", errno_value);
|
||||
return false;
|
||||
}
|
||||
|
||||
void FileSystem::set_origin(const std::string& origin) { origin_ = origin; }
|
||||
|
||||
@@ -265,10 +265,17 @@ TEST_F(FileTest, ListFiles) {
|
||||
}
|
||||
|
||||
TEST_F(FileTest, ListFiles_NotAPath) {
|
||||
const std::string not_path("zzz/xxx");
|
||||
const std::string kTestFilename = "zzz.txt";
|
||||
const std::string dir_path = wvcdm::test_vectors::kTestDir;
|
||||
const std::string file_path = PathJoin(dir_path, kTestFilename);
|
||||
std::unique_ptr<File> file =
|
||||
file_system_.Open(file_path, FileSystem::kCreate);
|
||||
ASSERT_TRUE(file) << "Failed to create file: " << kTestFilename;
|
||||
file.reset(); // Close file
|
||||
|
||||
std::vector<std::string> names;
|
||||
// Ask for non-existent path.
|
||||
EXPECT_FALSE(file_system_.List(not_path, &names));
|
||||
EXPECT_FALSE(file_system_.List(file_path, &names));
|
||||
}
|
||||
|
||||
TEST_F(FileTest, ListFiles_NullParameter) {
|
||||
|
||||
Reference in New Issue
Block a user