summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2012-02-03 11:45:51 -0500
committerDan Winship <danw@gnome.org>2012-02-09 06:48:12 -0500
commitca5ed93fde448943d7ab62b057a9b16e6ed85621 (patch)
treefc945be6e65a4ff1521b71f12e3a8b8b7f66ff85
parenta067df5d720096a62736d26c9e971363c0843d91 (diff)
downloadglib-ca5ed93fde448943d7ab62b057a9b16e6ed85621.tar.gz
glocalfile: fix error code when opening a directory on win32
g_file_read() was returning G_IO_ERROR_IS_DIRECTORY when you tried to open a directory on unix, but G_IO_ERROR_PERMISSION_DENIED on win32. Fix that, and add a test to tests/file.c Pointed out on IRC by Paweł Forysiuk. https://bugzilla.gnome.org/show_bug.cgi?id=669330
-rw-r--r--gio/glocalfile.c14
-rw-r--r--gio/tests/file.c5
2 files changed, 19 insertions, 0 deletions
diff --git a/gio/glocalfile.c b/gio/glocalfile.c
index cfd805a1b..176817d70 100644
--- a/gio/glocalfile.c
+++ b/gio/glocalfile.c
@@ -1314,6 +1314,20 @@ g_local_file_read (GFile *file,
{
int errsv = errno;
+#ifdef G_OS_WIN32
+ if (errsv == EACCES)
+ {
+ ret = _stati64 (local->filename, &buf);
+ if (ret == 0 && S_ISDIR (buf.st_mode))
+ {
+ g_set_error_literal (error, G_IO_ERROR,
+ G_IO_ERROR_IS_DIRECTORY,
+ _("Can't open directory"));
+ return NULL;
+ }
+ }
+#endif
+
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errsv),
_("Error opening file: %s"),
diff --git a/gio/tests/file.c b/gio/tests/file.c
index 35bb2cd22..c7f840be6 100644
--- a/gio/tests/file.c
+++ b/gio/tests/file.c
@@ -78,6 +78,7 @@ test_type (void)
{
GFile *file;
GFileType type;
+ GError *error = NULL;
file = g_file_new_for_path (SRCDIR "/file.c");
type = g_file_query_file_type (file, 0, NULL);
@@ -87,6 +88,10 @@ test_type (void)
file = g_file_new_for_path (SRCDIR "/schema-tests");
type = g_file_query_file_type (file, 0, NULL);
g_assert_cmpint (type, ==, G_FILE_TYPE_DIRECTORY);
+
+ g_file_read (file, NULL, &error);
+ g_assert_error (error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY);
+ g_error_free (error);
g_object_unref (file);
}