Add error details when offline license is not found
[ Merge of http://go/wvgerrit/171310 ] Offline license not found errors are identified by CdmResponseEnum 347 (KEYSET_ID_NOT_FOUND_4). No addition file system information is shared. Checks for file existance use the stat command. The stat call can return error codes from errno.h when the command fails. These are now converted into sub error codes and returned along with the offline license file not found error. This also includes a change to log stat errors other than ENOENT (no such file or directory) as a warning rather than verbose. Bug: 276225520 Test: file_store_unittest, file_utils_unittest, GtsMediaTestCases Change-Id: Ic09d036549582cd65783b49fa96ffefc4bf562c7
This commit is contained in:
@@ -58,6 +58,7 @@ class FileSystem {
|
||||
virtual std::unique_ptr<File> Open(const std::string& file_path, int flags);
|
||||
|
||||
virtual bool Exists(const std::string& file_path);
|
||||
virtual bool Exists(const std::string& file_path, int* errno_value);
|
||||
virtual bool Remove(const std::string& file_path);
|
||||
virtual ssize_t FileSize(const std::string& file_path);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ bool IsCurrentOrParentDirectory(const char* dir);
|
||||
class FileUtils {
|
||||
public:
|
||||
static bool Exists(const std::string& src);
|
||||
static bool Exists(const std::string& src, int* errno_value);
|
||||
// The caller may only specifying a single wildcard
|
||||
static bool Remove(const std::string& src);
|
||||
static bool Copy(const std::string& src, const std::string& dest);
|
||||
|
||||
@@ -497,6 +497,11 @@ std::unique_ptr<File> FileSystem::Open(const std::string& file_name,
|
||||
return std::unique_ptr<File>(new AndroidFile(fd, flags, file_path));
|
||||
}
|
||||
|
||||
bool FileSystem::Exists(const std::string& path, int* errno_value) {
|
||||
return FileUtils::Exists(GetFileNameForIdentifier(path, identifier_),
|
||||
errno_value);
|
||||
}
|
||||
|
||||
bool FileSystem::Exists(const std::string& path) {
|
||||
return FileUtils::Exists(GetFileNameForIdentifier(path, identifier_));
|
||||
}
|
||||
|
||||
@@ -25,11 +25,22 @@ bool IsCurrentOrParentDirectory(const char* dir) {
|
||||
}
|
||||
|
||||
bool FileUtils::Exists(const std::string& path) {
|
||||
return Exists(path, nullptr);
|
||||
}
|
||||
|
||||
bool FileUtils::Exists(const std::string& path, int* errno_value) {
|
||||
struct stat buf;
|
||||
int error = 0;
|
||||
int res = stat(path.c_str(), &buf) == 0;
|
||||
if (!res) {
|
||||
LOGV("File::Exists: stat failed: %d, %s", errno, strerror(errno));
|
||||
error = errno;
|
||||
if (error == ENOENT) {
|
||||
LOGI("stat failed: ENOENT");
|
||||
} else {
|
||||
LOGE("stat failed: %d, %s", error, strerror(error));
|
||||
}
|
||||
}
|
||||
if (errno_value != nullptr) *errno_value = error;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,17 @@ class FileTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(FileTest, FileExists) {
|
||||
int errno_value = -1;
|
||||
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kExistentFile));
|
||||
EXPECT_TRUE(
|
||||
file_system_.Exists(wvcdm::test_vectors::kExistentFile, &errno_value));
|
||||
EXPECT_EQ(0, errno_value);
|
||||
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kExistentDir));
|
||||
|
||||
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kNonExistentFile));
|
||||
EXPECT_FALSE(
|
||||
file_system_.Exists(wvcdm::test_vectors::kNonExistentFile, &errno_value));
|
||||
EXPECT_EQ(ENOENT, errno_value);
|
||||
EXPECT_FALSE(file_system_.Exists(wvcdm::test_vectors::kNonExistentDir));
|
||||
}
|
||||
|
||||
|
||||
@@ -98,6 +98,29 @@ TEST_F(FileUtilsTest, IsRegularFile) {
|
||||
EXPECT_FALSE(FileUtils::IsRegularFile(wvcdm::test_vectors::kTestDir));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilsTest, FileExists) {
|
||||
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
|
||||
std::string path2 = wvcdm::test_vectors::kTestDir + kTestFileName2;
|
||||
file_system_.Remove(path);
|
||||
file_system_.Remove(path2);
|
||||
|
||||
std::unique_ptr<File> file = file_system_.Open(path, FileSystem::kCreate);
|
||||
EXPECT_TRUE(file);
|
||||
|
||||
EXPECT_TRUE(file_system_.Exists(path));
|
||||
int errno_value = -1;
|
||||
EXPECT_TRUE(file_system_.Exists(path, &errno_value));
|
||||
EXPECT_EQ(0, errno_value);
|
||||
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
|
||||
EXPECT_TRUE(file_system_.Exists(path, nullptr));
|
||||
|
||||
EXPECT_FALSE(file_system_.Exists(path2));
|
||||
EXPECT_FALSE(file_system_.Exists(path2, &errno_value));
|
||||
EXPECT_EQ(ENOENT, errno_value);
|
||||
EXPECT_TRUE(file_system_.Exists(wvcdm::test_vectors::kTestDir));
|
||||
EXPECT_FALSE(file_system_.Exists(path2, nullptr));
|
||||
}
|
||||
|
||||
TEST_F(FileUtilsTest, CopyFile) {
|
||||
std::string path = wvcdm::test_vectors::kTestDir + kTestFileName;
|
||||
file_system_.Remove(path);
|
||||
|
||||
Reference in New Issue
Block a user