commit 211cb0478112f813743d1a43266f1eef946c6bd2
parent 5407e4537cd183c0239d1424bb3e010ff57bb07f
Author: Andrej Kacian <ticho@claws-mail.org>
Date: Sun, 29 Oct 2017 18:31:18 +0100
Use GIO API instead of g_stat() on Windows in compose_add_attachments() and get_file_size().
Diffstat:
2 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/src/common/utils.c b/src/common/utils.c
@@ -2028,6 +2028,27 @@ const gchar *get_domain_name(void)
off_t get_file_size(const gchar *file)
{
+#ifdef G_OS_WIN32
+ GFile *f;
+ GFileInfo *fi;
+ GError *error = NULL;
+ goffset size;
+
+ f = g_file_new_for_path(file);
+ fi = g_file_query_info(f, "standard::size",
+ G_FILE_QUERY_INFO_NONE, NULL, &error);
+ if (error != NULL) {
+ debug_print("get_file_size error: %s\n", error->message);
+ g_error_free(error);
+ g_object_unref(f);
+ return -1;
+ }
+ size = g_file_info_get_size(fi);
+ g_object_unref(fi);
+ g_object_unref(f);
+ return size;
+
+#else
GStatBuf s;
if (g_stat(file, &s) < 0) {
@@ -2036,6 +2057,7 @@ off_t get_file_size(const gchar *file)
}
return s.st_size;
+#endif
}
time_t get_file_mtime(const gchar *file)
diff --git a/src/compose.c b/src/compose.c
@@ -6352,7 +6352,14 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
AttachInfo *ainfo;
GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
MimeInfo *mimepart;
+#ifdef G_OS_WIN32
+ GFile *f;
+ GFileInfo *fi;
+ GError *error = NULL;
+#else
GStatBuf statbuf;
+#endif
+ goffset size;
gchar *type, *subtype;
GtkTreeModel *model;
GtkTreeIter iter;
@@ -6374,15 +6381,31 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
}
continue;
}
+#ifdef G_OS_WIN32
+ f = g_file_new_for_path(ainfo->file);
+ fi = g_file_query_info(f, "standard::size",
+ G_FILE_QUERY_INFO_NONE, NULL, &error);
+ if (error != NULL) {
+ g_warning(error->message);
+ g_error_free(error);
+ g_object_unref(f);
+ return -1;
+ }
+ size = g_file_info_get_size(fi);
+ g_object_unref(fi);
+ g_object_unref(f);
+#else
if (g_stat(ainfo->file, &statbuf) < 0)
return -1;
+ size = statbuf.st_size;
+#endif
mimepart = procmime_mimeinfo_new();
mimepart->content = MIMECONTENT_FILE;
mimepart->data.filename = g_strdup(ainfo->file);
mimepart->tmp = FALSE; /* or we destroy our attachment */
mimepart->offset = 0;
- mimepart->length = statbuf.st_size;
+ mimepart->length = size;
type = g_strdup(ainfo->content_type);