Move pathExists() to Utils.cpp

This is useful as a general utility function.

Change-Id: Id43fc106dc6c544c6e4ce65f10c7d4246b99e54a
This commit is contained in:
Eric Biggers 2021-02-16 15:59:17 -08:00
parent 810bcca4d0
commit bd138dd08a
4 changed files with 6 additions and 7 deletions

View file

@ -606,10 +606,6 @@ static bool decryptWithoutKeymaster(const std::string& preKey, const std::string
return true;
}
bool pathExists(const std::string& path) {
return access(path.c_str(), F_OK) == 0;
}
bool storeKey(const std::string& dir, const KeyAuthentication& auth, const KeyBuffer& key) {
if (TEMP_FAILURE_RETRY(mkdir(dir.c_str(), 0700)) == -1) {
PLOG(ERROR) << "key mkdir " << dir;

View file

@ -43,9 +43,6 @@ class KeyAuthentication {
extern const KeyAuthentication kEmptyAuthentication;
// Checks if path "path" exists.
bool pathExists(const std::string& path);
bool createSecdiscardable(const std::string& path, std::string* hash);
bool readSecdiscardable(const std::string& path, std::string* hash);

View file

@ -1349,6 +1349,10 @@ status_t WaitForFile(const char* filename, std::chrono::nanoseconds timeout) {
return -1;
}
bool pathExists(const std::string& path) {
return access(path.c_str(), F_OK) == 0;
}
bool FsyncDirectory(const std::string& dirname) {
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dirname.c_str(), O_RDONLY | O_CLOEXEC)));
if (fd == -1) {

View file

@ -179,6 +179,8 @@ status_t DeleteDirContents(const std::string& pathname);
status_t WaitForFile(const char* filename, std::chrono::nanoseconds timeout);
bool pathExists(const std::string& path);
bool FsyncDirectory(const std::string& dirname);
bool writeStringToFile(const std::string& payload, const std::string& filename);