diff options
| author | 2016-10-21 17:55:42 +0000 | |
|---|---|---|
| committer | 2016-10-21 17:55:46 +0000 | |
| commit | 2f99e60d71684d0f0296ce252a0683dc02cd93bd (patch) | |
| tree | bb0621fe13b3387f11f339aa2edb88e54599ca6a /tools/bit/util.h | |
| parent | 10842783e1955c4a0aa2e640cd4531b17a0b4b1d (diff) | |
| parent | 0578cbc6c527bc09a38a0fcd8b9642c25c8ea023 (diff) | |
Merge changes from topic 'am_instrument'
* changes:
Add a new build, install, test development (bit) tool
am instrument gets protobuf
Fix bad type codes in streaming proto compiler
Diffstat (limited to 'tools/bit/util.h')
| -rw-r--r-- | tools/bit/util.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tools/bit/util.h b/tools/bit/util.h new file mode 100644 index 000000000000..718f1474a969 --- /dev/null +++ b/tools/bit/util.h @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UTIL_H +#define UTIL_H + +#include <map> +#include <string> +#include <vector> + +using namespace std; + +struct FileInfo +{ + bool exists; + time_t mtime; + time_t ctime; + off_t size; + + FileInfo(); + FileInfo(const FileInfo& that); + explicit FileInfo(const string& filename); + ~FileInfo(); + + bool operator==(const FileInfo& that) const; + bool operator!=(const FileInfo& that) const; +}; + + +/** + * Record for a file that we are watching + */ +struct TrackedFile { + string filename; + FileInfo fileInfo; + + TrackedFile(); + TrackedFile(const TrackedFile& that); + explicit TrackedFile(const string& filename); + ~TrackedFile(); + + // Returns if the file has changed. If it doesn't currently exist, returns true. + bool HasChanged() const; +}; + +/** + * Get FileInfo structures recursively for all the files and symlinks in a directory. + * Does not traverse symlinks, but it does record them. + */ +void get_directory_contents(const string& dir, map<string,FileInfo>* results); + +bool directory_contents_differ(const map<string,FileInfo>& before, + const map<string,FileInfo>& after); + +string escape_quotes(const char* str); + +string escape_for_commandline(const char* str); + +string trim(const string& trim); + +bool starts_with(const string& str, const string& prefix); + +bool ends_with(const string& str, const string& suffix); + +void split_lines(vector<string>* result, const string& str); + +string read_file(const string& filename); + +#endif // UTIL_H + |