summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'base/file.cpp')
-rw-r--r--base/file.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/base/file.cpp b/base/file.cpp
index 2f697a1cc..d6fe753d1 100644
--- a/base/file.cpp
+++ b/base/file.cpp
@@ -199,17 +199,23 @@ bool WriteFully(int fd, const void* data, size_t byte_count) {
199bool RemoveFileIfExists(const std::string& path, std::string* err) { 199bool RemoveFileIfExists(const std::string& path, std::string* err) {
200 struct stat st; 200 struct stat st;
201#if defined(_WIN32) 201#if defined(_WIN32)
202 //TODO: Windows version can't handle symbol link correctly. 202 // TODO: Windows version can't handle symbolic links correctly.
203 int result = stat(path.c_str(), &st); 203 int result = stat(path.c_str(), &st);
204 bool file_type_removable = (result == 0 && S_ISREG(st.st_mode)); 204 bool file_type_removable = (result == 0 && S_ISREG(st.st_mode));
205#else 205#else
206 int result = lstat(path.c_str(), &st); 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))); 207 bool file_type_removable = (result == 0 && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)));
208#endif 208#endif
209 if (result == -1) {
210 if (errno == ENOENT || errno == ENOTDIR) return true;
211 if (err != nullptr) *err = strerror(errno);
212 return false;
213 }
214
209 if (result == 0) { 215 if (result == 0) {
210 if (!file_type_removable) { 216 if (!file_type_removable) {
211 if (err != nullptr) { 217 if (err != nullptr) {
212 *err = "is not a regular or symbol link file"; 218 *err = "is not a regular file or symbolic link";
213 } 219 }
214 return false; 220 return false;
215 } 221 }