summaryrefslogtreecommitdiffstats
path: root/base/file.cpp
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) {
bool RemoveFileIfExists(const std::string& path, std::string* err) {
struct stat st;
#if defined(_WIN32)
- //TODO: Windows version can't handle symbol link correctly.
+ // TODO: Windows version can't handle symbolic links correctly.
int result = stat(path.c_str(), &st);
bool file_type_removable = (result == 0 && S_ISREG(st.st_mode));
#else
int result = lstat(path.c_str(), &st);
bool file_type_removable = (result == 0 && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)));
#endif
+ if (result == -1) {
+ if (errno == ENOENT || errno == ENOTDIR) return true;
+ if (err != nullptr) *err = strerror(errno);
+ return false;
+ }
+
if (result == 0) {
if (!file_type_removable) {
if (err != nullptr) {
- *err = "is not a regular or symbol link file";
+ *err = "is not a regular file or symbolic link";
}
return false;
}