diff options
author | Yabin Cui <yabinc@google.com> | 2016-02-02 06:23:38 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-02-02 06:23:38 +0000 |
commit | ab8ec9ca0e96425b22867deb311fe9dde3db14ea (patch) | |
tree | 5f9bb82075ddc85e20369c0e9c1dc01c9915b488 | |
parent | b764f45fd9758c8222bc08d7fa4944e8f7da6f40 (diff) | |
parent | 0ed5aacf696bbf8c6a87ce3c07f33c1b3ce33bd4 (diff) | |
download | extras-ab8ec9ca0e96425b22867deb311fe9dde3db14ea.tar.gz |
Merge "simpleperf: use RemoveFileIfExists in libbase."
-rw-r--r-- | simpleperf/record_file_writer.cpp | 6 | ||||
-rw-r--r-- | simpleperf/utils.cpp | 15 | ||||
-rw-r--r-- | simpleperf/utils.h | 1 |
3 files changed, 5 insertions, 17 deletions
diff --git a/simpleperf/record_file_writer.cpp b/simpleperf/record_file_writer.cpp index ca1845a9..dddd0b05 100644 --- a/simpleperf/record_file_writer.cpp +++ b/simpleperf/record_file_writer.cpp @@ -21,8 +21,10 @@ #include <sys/mman.h> #include <unistd.h> #include <set> +#include <string> #include <vector> +#include <android-base/file.h> #include <android-base/logging.h> #include "perf_event.h" @@ -33,7 +35,9 @@ using namespace PerfFileFormat; std::unique_ptr<RecordFileWriter> RecordFileWriter::CreateInstance(const std::string& filename) { // Remove old perf.data to avoid file ownership problems. - if (!RemovePossibleFile(filename)) { + std::string err; + if (!android::base::RemoveFileIfExists(filename, &err)) { + LOG(ERROR) << "failed to remove file " << filename << ": " << err; return nullptr; } FILE* fp = fopen(filename.c_str(), "web+"); diff --git a/simpleperf/utils.cpp b/simpleperf/utils.cpp index aa5d2eea..ae157b53 100644 --- a/simpleperf/utils.cpp +++ b/simpleperf/utils.cpp @@ -115,21 +115,6 @@ bool IsRegularFile(const std::string& filename) { return false; } -bool RemovePossibleFile(const std::string& filename) { - struct stat st; - if (stat(filename.c_str(), &st) == 0) { - if (!S_ISREG(st.st_mode)) { - LOG(ERROR) << filename << " is not a file."; - return false; - } - if (unlink(filename.c_str()) == -1) { - PLOG(ERROR) << "unlink(" << filename << ") failed"; - return false; - } - } - return true; -} - bool StringToPid(const std::string& s, int* pid) { char* endptr; *pid = static_cast<int>(strtol(s.c_str(), &endptr, 10)); diff --git a/simpleperf/utils.h b/simpleperf/utils.h index e8310a63..c63ac6c2 100644 --- a/simpleperf/utils.h +++ b/simpleperf/utils.h @@ -66,7 +66,6 @@ void GetEntriesInDir(const std::string& dirpath, std::vector<std::string>* files std::vector<std::string>* subdirs); bool IsDir(const std::string& dirpath); bool IsRegularFile(const std::string& filename); -bool RemovePossibleFile(const std::string& filename); bool StringToPid(const std::string& s, int* pid); #endif // SIMPLE_PERF_UTILS_H_ |