MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / RemoveFileIfExists

Function RemoveFileIfExists

Bcore/src/main/cpp/android-base/file.cpp:199–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199bool RemoveFileIfExists(const std::string& path, std::string* err) {
200 struct stat st;
201#if defined(_WIN32)
202 //TODO: Windows version can't handle symbol link correctly.
203 int result = stat(path.c_str(), &st);
204 bool file_type_removable = (result == 0 && S_ISREG(st.st_mode));
205#else
206 int result = lstat(path.c_str(), &st);
207 bool file_type_removable = (result == 0 && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)));
208#endif
209 if (result == 0) {
210 if (!file_type_removable) {
211 if (err != nullptr) {
212 *err = "is not a regular or symbol link file";
213 }
214 return false;
215 }
216 if (unlink(path.c_str()) == -1) {
217 if (err != nullptr) {
218 *err = strerror(errno);
219 }
220 return false;
221 }
222 }
223 return true;
224}
225
226#if !defined(_WIN32)
227bool Readlink(const std::string& path, std::string* result) {

Callers

nothing calls this directly

Calls 2

c_strMethod · 0.80
statClass · 0.70

Tested by

no test coverage detected