UpdateIO.cxx: use file system API, log in UTF-8

This commit is contained in:
Denis Krjuchkov 2013-02-02 20:25:13 +06:00
parent d818b618af
commit 99526219b7

View File

@ -36,12 +36,15 @@ stat_directory(const Directory *directory, struct stat *st)
if (path_fs.IsNull()) if (path_fs.IsNull())
return -1; return -1;
int ret = stat(path_fs.c_str(), st); if (!StatFile(path_fs, *st)) {
if (ret < 0) int error = errno;
const std::string path_utf8 = path_fs.ToUTF8();
g_warning("Failed to stat %s: %s", g_warning("Failed to stat %s: %s",
path_fs.c_str(), g_strerror(errno)); path_utf8.c_str(), g_strerror(error));
return -1;
}
return ret; return 0;
} }
int int
@ -52,12 +55,15 @@ stat_directory_child(const Directory *parent, const char *name,
if (path_fs.IsNull()) if (path_fs.IsNull())
return -1; return -1;
int ret = stat(path_fs.c_str(), st); if (!StatFile(path_fs, *st)) {
if (ret < 0) int error = errno;
const std::string path_utf8 = path_fs.ToUTF8();
g_warning("Failed to stat %s: %s", g_warning("Failed to stat %s: %s",
path_fs.c_str(), g_strerror(errno)); path_utf8.c_str(), g_strerror(error));
return -1;
}
return ret; return 0;
} }
bool bool
@ -82,8 +88,7 @@ directory_child_is_regular(const Directory *directory,
if (path_fs.IsNull()) if (path_fs.IsNull())
return false; return false;
struct stat st; return FileExists(path_fs);
return stat(path_fs.c_str(), &st) == 0 && S_ISREG(st.st_mode);
} }
bool bool
@ -91,7 +96,7 @@ directory_child_access(const Directory *directory,
const char *name, int mode) const char *name, int mode)
{ {
#ifdef WIN32 #ifdef WIN32
/* access() is useless on WIN32 */ /* CheckAccess() is useless on WIN32 */
(void)directory; (void)directory;
(void)name; (void)name;
(void)mode; (void)mode;
@ -103,6 +108,6 @@ directory_child_access(const Directory *directory,
problem */ problem */
return true; return true;
return access(path.c_str(), mode) == 0 || errno != EACCES; return CheckAccess(path, mode) || errno != EACCES;
#endif #endif
} }