Remove Stale Licenses on Reprovisioning
Merges change 267713c (Remove stale licenses on reprovisioning) from the Widevine CDM repository. This change removes licenses belonging to the previous provisioning when provisioning changes. Bug: 9761923 Change-Id: I473816dd11dd950f4fb009b5b004630bd2d2b579
This commit is contained in:
@@ -14,9 +14,11 @@
|
||||
#include "log.h"
|
||||
|
||||
namespace {
|
||||
const char* kCurrentDirectory = ".";
|
||||
const char* kParentDirectory = "..";
|
||||
} // namespace
|
||||
const char kCurrentDirectory[] = ".";
|
||||
const char kParentDirectory[] = "..";
|
||||
const char kPathDelimiter[] = "/";
|
||||
const char kWildcard[] = "*";
|
||||
} // namespace
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
@@ -49,9 +51,9 @@ bool File::Open(const std::string& name, int flags) {
|
||||
}
|
||||
|
||||
if (flags & File::kBinary) {
|
||||
open_flags = (flags & File::kReadOnly)? "rb" : "rb+";
|
||||
open_flags = (flags & File::kReadOnly) ? "rb" : "rb+";
|
||||
} else {
|
||||
open_flags = (flags & File::kReadOnly)? "r" : "r+";
|
||||
open_flags = (flags & File::kReadOnly) ? "r" : "r+";
|
||||
}
|
||||
|
||||
impl_->file_ = fopen(name.c_str(), open_flags.c_str());
|
||||
@@ -104,14 +106,15 @@ bool File::Exists(const std::string& path) {
|
||||
|
||||
bool File::Remove(const std::string& path) {
|
||||
if (IsDirectory(path)) {
|
||||
// Handle directory deletion
|
||||
DIR* dir;
|
||||
if ((dir = opendir(path.c_str())) != NULL) {
|
||||
// first remove files and dir within it
|
||||
struct dirent* entry;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
if (strcmp(entry->d_name, kCurrentDirectory) &&
|
||||
(strcmp(entry->d_name, kParentDirectory))) {
|
||||
std::string path_to_remove = path + '/';
|
||||
(strcmp(entry->d_name, kParentDirectory))) {
|
||||
std::string path_to_remove = path + kPathDelimiter;
|
||||
path_to_remove += entry->d_name;
|
||||
if (!Remove(path_to_remove)) {
|
||||
closedir(dir);
|
||||
@@ -127,9 +130,46 @@ bool File::Remove(const std::string& path) {
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (unlink(path.c_str()) && (errno != ENOENT)) {
|
||||
LOGW("File::Remove: unlink failed: %d", errno);
|
||||
return false;
|
||||
size_t wildcard_pos = path.find(kWildcard);
|
||||
if (wildcard_pos == std::string::npos) {
|
||||
// Handle file deletion
|
||||
if (unlink(path.c_str()) && (errno != ENOENT)) {
|
||||
LOGW("File::Remove: unlink failed: %d", errno);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Handle wildcard specified file deletion
|
||||
size_t delimiter_pos = path.rfind(kPathDelimiter, wildcard_pos);
|
||||
if (delimiter_pos == std::string::npos) {
|
||||
LOGW("File::Remove: unable to find path delimiter before wildcard");
|
||||
return false;
|
||||
}
|
||||
|
||||
DIR* dir;
|
||||
std::string dir_path = path.substr(0, delimiter_pos);
|
||||
if ((dir = opendir(dir_path.c_str())) == NULL) {
|
||||
LOGW("File::Remove: directory open failed for wildcard");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct dirent* entry;
|
||||
std::string ext = path.substr(wildcard_pos + 1);
|
||||
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
size_t filename_len = strlen(entry->d_name);
|
||||
if (filename_len > ext.size()) {
|
||||
if (strcmp(entry->d_name + filename_len - ext.size(), ext.c_str()) ==
|
||||
0) {
|
||||
std::string file_path_to_remove =
|
||||
dir_path + kPathDelimiter + entry->d_name;
|
||||
if (!Remove(file_path_to_remove)) {
|
||||
closedir(dir);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -137,13 +177,11 @@ bool File::Remove(const std::string& path) {
|
||||
|
||||
bool File::CreateDirectory(std::string path) {
|
||||
size_t size = path.size();
|
||||
if ((size == 1) && (path[0] == '/'))
|
||||
return true;
|
||||
if ((size == 1) && (path[0] == '/')) return true;
|
||||
|
||||
if (size <= 1)
|
||||
return false;
|
||||
if (size <= 1) return false;
|
||||
|
||||
if (path.at(size-1) == '/') {
|
||||
if (path.at(size - 1) == '/') {
|
||||
--size;
|
||||
path.resize(size);
|
||||
}
|
||||
@@ -158,7 +196,7 @@ bool File::CreateDirectory(std::string path) {
|
||||
}
|
||||
}
|
||||
path.at(pos) = '/';
|
||||
pos = path.find('/', pos+1);
|
||||
pos = path.find('/', pos + 1);
|
||||
}
|
||||
if (mkdir(path.c_str(), 0775) != 0) {
|
||||
if (errno != EEXIST) {
|
||||
|
||||
Reference in New Issue
Block a user