From 39c12039cbd44edba5911807e4c0ec30be264c05 Mon Sep 17 00:00:00 2001 From: Alex Dale Date: Tue, 5 Nov 2024 14:40:42 -0800 Subject: [PATCH] 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 --- libwvdrmengine/cdm/util/src/file_store.cpp | 16 +++++++++++++++- .../cdm/util/test/file_store_unittest.cpp | 11 +++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/libwvdrmengine/cdm/util/src/file_store.cpp b/libwvdrmengine/cdm/util/src/file_store.cpp index 63f3b716..4623fece 100644 --- a/libwvdrmengine/cdm/util/src/file_store.cpp +++ b/libwvdrmengine/cdm/util/src/file_store.cpp @@ -530,7 +530,21 @@ ssize_t FileSystem::FileSize(const std::string& file_name) { bool FileSystem::List(const std::string& path, std::vector* 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; } diff --git a/libwvdrmengine/cdm/util/test/file_store_unittest.cpp b/libwvdrmengine/cdm/util/test/file_store_unittest.cpp index ad30ac26..aaa86124 100644 --- a/libwvdrmengine/cdm/util/test/file_store_unittest.cpp +++ b/libwvdrmengine/cdm/util/test/file_store_unittest.cpp @@ -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_system_.Open(file_path, FileSystem::kCreate); + ASSERT_TRUE(file) << "Failed to create file: " << kTestFilename; + file.reset(); // Close file + std::vector 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) {