summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2016-02-02 06:23:38 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-02-02 06:23:38 +0000
commitab8ec9ca0e96425b22867deb311fe9dde3db14ea (patch)
tree5f9bb82075ddc85e20369c0e9c1dc01c9915b488
parentb764f45fd9758c8222bc08d7fa4944e8f7da6f40 (diff)
parent0ed5aacf696bbf8c6a87ce3c07f33c1b3ce33bd4 (diff)
downloadextras-ab8ec9ca0e96425b22867deb311fe9dde3db14ea.tar.gz
Merge "simpleperf: use RemoveFileIfExists in libbase."
-rw-r--r--simpleperf/record_file_writer.cpp6
-rw-r--r--simpleperf/utils.cpp15
-rw-r--r--simpleperf/utils.h1
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_