OSDN Git Service

Move pathExists() to Utils.cpp
authorEric Biggers <ebiggers@google.com>
Tue, 16 Feb 2021 23:59:17 +0000 (15:59 -0800)
committerEric Biggers <ebiggers@google.com>
Wed, 17 Feb 2021 00:05:38 +0000 (16:05 -0800)
This is useful as a general utility function.

Change-Id: Id43fc106dc6c544c6e4ce65f10c7d4246b99e54a

KeyStorage.cpp
KeyStorage.h
Utils.cpp
Utils.h

index 89844aa..fb94ae5 100644 (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;
index a69dbf7..a8908d4 100644 (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);
 
index 98797b2..c74feb4 100644 (file)
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -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) {
diff --git a/Utils.h b/Utils.h
index a727e63..cf85136 100644 (file)
--- a/Utils.h
+++ b/Utils.h
@@ -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);