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) {