1 |
lack 08/01/24 20:08:12 |
2 |
|
3 |
Added: rox-2.7-text_plain.patch digest-rox-2.7.1-r1 |
4 |
Removed: digest-rox-2.7.1 |
5 |
Log: |
6 |
Added patch to fix detection of text/plain files. |
7 |
(Portage version: 2.1.4_rc14) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 rox-base/rox/files/rox-2.7-text_plain.patch |
11 |
|
12 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/rox/files/rox-2.7-text_plain.patch?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/rox/files/rox-2.7-text_plain.patch?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: rox-2.7-text_plain.patch |
16 |
=================================================================== |
17 |
commit ed0adb6e4e873eca15b4765035d3c89888c74a72 |
18 |
Author: Stephen Watson <stephen@××××××××××××××××.uk> |
19 |
Date: Mon Jan 21 23:33:13 2008 +0000 |
20 |
|
21 |
MIME magic lookup now returns text/plain for certain unknown file types. |
22 |
Restored the code, lost in the update to the newer XDG MIME code, which checks |
23 |
unknown files to see if they are text. |
24 |
|
25 |
Modifications to the XDG code are tagged with ROX: comments. |
26 |
|
27 |
diff --git a/ROX-Filer/src/xdgmime.c b/ROX-Filer/src/xdgmime.c |
28 |
index 133282d..51d38d6 100644 |
29 |
--- a/ROX-Filer/src/xdgmime.c |
30 |
+++ b/ROX-Filer/src/xdgmime.c |
31 |
@@ -65,6 +65,7 @@ XdgMimeCache **_xdg_mime_caches = NULL; |
32 |
static int n_caches = 0; |
33 |
|
34 |
const char xdg_mime_type_unknown[] = "application/octet-stream"; |
35 |
+const char xdg_mime_type_unknown_text[] = "text/plain"; /* ROX: */ |
36 |
|
37 |
|
38 |
enum |
39 |
diff --git a/ROX-Filer/src/xdgmime.h b/ROX-Filer/src/xdgmime.h |
40 |
index 82b5585..52d1524 100644 |
41 |
--- a/ROX-Filer/src/xdgmime.h |
42 |
+++ b/ROX-Filer/src/xdgmime.h |
43 |
@@ -74,7 +74,11 @@ typedef void (*XdgMimeDestroy) (void *user_data); |
44 |
#endif |
45 |
|
46 |
extern const char xdg_mime_type_unknown[]; |
47 |
-#define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown |
48 |
+#define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown |
49 |
+ |
50 |
+/* ROX: */ |
51 |
+extern const char xdg_mime_type_unknown_text[]; |
52 |
+#define XDG_MIME_TYPE_UNKNOWN_TEXT xdg_mime_type_unknown_text |
53 |
|
54 |
const char *xdg_mime_get_mime_type_for_data (const void *data, |
55 |
size_t len); |
56 |
diff --git a/ROX-Filer/src/xdgmimemagic.c b/ROX-Filer/src/xdgmimemagic.c |
57 |
index 892688b..d1d04b6 100644 |
58 |
--- a/ROX-Filer/src/xdgmimemagic.c |
59 |
+++ b/ROX-Filer/src/xdgmimemagic.c |
60 |
@@ -39,6 +39,9 @@ |
61 |
#include <errno.h> |
62 |
#include <limits.h> |
63 |
|
64 |
+/* ROX: */ |
65 |
+#include <glib.h> |
66 |
+ |
67 |
#ifndef FALSE |
68 |
#define FALSE (0) |
69 |
#endif |
70 |
@@ -654,6 +657,83 @@ _xdg_mime_magic_get_buffer_extents (XdgMimeMagic *mime_magic) |
71 |
return mime_magic->max_extent; |
72 |
} |
73 |
|
74 |
+static gboolean _rox_buffer_looks_like_text (const void *data, |
75 |
+ const size_t len) |
76 |
+{ |
77 |
+ gchar *end; |
78 |
+ |
79 |
+ if (g_utf8_validate (data, len, (const gchar**)&end)) |
80 |
+ { |
81 |
+ /* g_utf8_validate allows control characters */ |
82 |
+ int i; |
83 |
+ for (i = 0; i < len; i++) |
84 |
+ { |
85 |
+ unsigned char c = ((const guchar *) data)[i]; |
86 |
+ if (c < 32 && c != '\r' && c != '\n' && c != '\t') |
87 |
+ return FALSE; |
88 |
+ } |
89 |
+ return TRUE; |
90 |
+ |
91 |
+ } else { |
92 |
+ /* Check whether the string was truncated in the middle of |
93 |
+ * a valid UTF8 char, or if we really have an invalid |
94 |
+ * UTF8 string |
95 |
+ */ |
96 |
+ gint remaining_bytes = len; |
97 |
+ |
98 |
+ remaining_bytes -= (end-((gchar*)data)); |
99 |
+ |
100 |
+ if (g_utf8_get_char_validated(end, remaining_bytes) == -2) |
101 |
+ return TRUE; |
102 |
+#if defined(HAVE_WCTYPE_H) && defined (HAVE_MBRTOWC) |
103 |
+ else { |
104 |
+ size_t wlen; |
105 |
+ wchar_t wc; |
106 |
+ gchar *src, *end; |
107 |
+ mbstate_t state; |
108 |
+ |
109 |
+ src = data; |
110 |
+ end = data+len; |
111 |
+ |
112 |
+ memset (&state, 0, sizeof (state)); |
113 |
+ while (src < end) { |
114 |
+ /* Don't allow embedded zeros in textfiles */ |
115 |
+ if (*src == 0) |
116 |
+ return FALSE; |
117 |
+ |
118 |
+ wlen = mbrtowc(&wc, src, end - src, &state); |
119 |
+ |
120 |
+ if (wlen == (size_t)(-1)) { |
121 |
+ /* Illegal mb sequence */ |
122 |
+ return FALSE; |
123 |
+ } |
124 |
+ |
125 |
+ if (wlen == (size_t)(-2)) { |
126 |
+ /* No complete mb char before end |
127 |
+ * Probably a cut off char which is ok */ |
128 |
+ return TRUE; |
129 |
+ } |
130 |
+ |
131 |
+ if (wlen == 0) { |
132 |
+ /* Don't allow embedded zeros in textfiles */ |
133 |
+ return FALSE; |
134 |
+ } |
135 |
+ |
136 |
+ if (!iswspace (wc) && !iswprint(wc)) { |
137 |
+ /* Not a printable or whitspace |
138 |
+ * Probably not a text file */ |
139 |
+ return FALSE; |
140 |
+ } |
141 |
+ |
142 |
+ src += wlen; |
143 |
+ } |
144 |
+ return TRUE; |
145 |
+ } |
146 |
+#endif /* defined(HAVE_WCTYPE_H) && defined (HAVE_MBRTOWC) */ |
147 |
+ } |
148 |
+ return FALSE; |
149 |
+} |
150 |
+ |
151 |
const char * |
152 |
_xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic, |
153 |
const void *data, |
154 |
@@ -708,6 +788,12 @@ _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic, |
155 |
} |
156 |
} |
157 |
|
158 |
+ if (mime_type == NULL) |
159 |
+ { |
160 |
+ if(_rox_buffer_looks_like_text(data, len)) |
161 |
+ mime_type = XDG_MIME_TYPE_UNKNOWN_TEXT; |
162 |
+ } |
163 |
+ |
164 |
return mime_type; |
165 |
} |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
1.1 rox-base/rox/files/digest-rox-2.7.1-r1 |
171 |
|
172 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/rox/files/digest-rox-2.7.1-r1?rev=1.1&view=markup |
173 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/rox-base/rox/files/digest-rox-2.7.1-r1?rev=1.1&content-type=text/plain |
174 |
|
175 |
Index: digest-rox-2.7.1-r1 |
176 |
=================================================================== |
177 |
MD5 6302280f57d1f02c07da5637a2609a4f rox-filer-2.7.1.tar.bz2 1835501 |
178 |
RMD160 f1face1871d641b7bea4b66a5de9a9a78ea7a25a rox-filer-2.7.1.tar.bz2 1835501 |
179 |
SHA256 3a565cc47f8ad2cba5972e2494e9f9380b7fc68a2ba0467aef6f2e1340695f92 rox-filer-2.7.1.tar.bz2 1835501 |
180 |
|
181 |
|
182 |
|
183 |
-- |
184 |
gentoo-commits@l.g.o mailing list |