[PATCH] cachefile-fat32-comptatible



Hi,

The attached patch change cache filename in order to be compatible with
FAT32 Partions, like we discussed on IRC.

Is it OK ?

Regards,
-- 
Thomas Guillem
Etudiant en GI03 (Génie Informatique) à l'UTBM (http://www.utbm.fr)
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.c	(revision 3801)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.c	(working copy)
@@ -260,7 +260,6 @@
 	CamelStream *stream;
 	int fd;
 
-#ifdef G_OS_WIN32
 	/* Trailing periods in file names are silently dropped on
 	 * Win32, argh. The code in this file requires the period to
 	 * be there. So in case part_spec is empty, use a tilde (just
@@ -268,7 +267,6 @@
 	 */
 	if (!*part_spec)
 		part_spec = "~";
-#endif
 	*path = g_strdup_printf ("%s/%s.%s", cache->path, uid, part_spec);
 	*key = strrchr (*path, '/') + 1;
 	stream = g_hash_table_lookup (cache->parts, *key);
@@ -343,18 +341,41 @@
 	return insert_finish (cache, uid, path, key, stream);
 }
 
+static gchar*
+cachefile_get(const char *path, const char *uid, const char *part_spec)
+{
+	gchar *file;
+	if (part_spec && *part_spec) {
+		file = g_strdup_printf ("%s/%s.%s", path, uid, part_spec);
+	} else {
+		char tmp [512];
+		int len = snprintf(tmp, 512, "%s/%s.~", path, uid);
+		file = g_strdup(tmp);
+		if (!g_file_test(tmp, G_FILE_TEST_IS_REGULAR)) {
+			tmp [len - 1] = '\0';
+			if (g_file_test(tmp, G_FILE_TEST_IS_REGULAR)) {
+				/*  Compatibility with old cache file */
+				g_free(file);
+				file = g_strdup(tmp);
+			}
+		}
+	}
+	return file;
+}
+
 void
 camel_imap_message_cache_set_flags (const gchar *folder_dir, CamelMessageInfoBase *mi)
 {
-	char mystring [512];
+	gchar *cachefile;
 
 	if( !folder_dir ){
 		return;
 	}
+	cachefile = cachefile_get(folder_dir, mi->uid, NULL);
+	if (g_file_test (cachefile, G_FILE_TEST_IS_REGULAR))
+	{
+		char mystring [512];
 
-	snprintf (mystring, 512, "%s/%s.", folder_dir, mi->uid);
-	if (g_file_test (mystring, G_FILE_TEST_IS_REGULAR))
-	{
 		mi->flags |= CAMEL_MESSAGE_CACHED;
 		snprintf (mystring, 512, "%s/%s.partial", folder_dir, mi->uid);
 		if (g_file_test (mystring, G_FILE_TEST_IS_REGULAR))
@@ -365,6 +386,7 @@
 		mi->flags &= ~CAMEL_MESSAGE_CACHED;
 		mi->flags &= ~CAMEL_MESSAGE_PARTIAL;
 	}
+	g_free(cachefile);
 }
 
 gboolean
@@ -557,12 +579,7 @@
 	if (uid[0] == 0)
 		return NULL;
 
-#ifdef G_OS_WIN32
-	/* See comment in insert_setup() */
-	if (!*part_spec)
-		part_spec = "~";
-#endif
-	path = g_strdup_printf ("%s/%s.%s", cache->path, uid, part_spec);
+	path = cachefile_get(cache->path, uid, part_spec);
 	key = strrchr (path, '/') + 1;
 
 	stream = g_hash_table_lookup (cache->parts, key);
@@ -735,8 +752,8 @@
 void camel_imap_message_cache_replace_cache (CamelImapMessageCache *cache, const char *uid, const char *part_spec,
 					  const char *dest_uid, const char *dest_part_spec)
 {
-	gchar *real = g_strdup_printf ("%s/%s.%s", cache->path, uid, (part_spec)?part_spec:"");
-	gchar *dest_real = g_strdup_printf ("%s/%s.%s", cache->path, dest_uid, (dest_part_spec)?dest_part_spec:"");
+	gchar *real = cachefile_get(cache->path, uid, part_spec);
+	gchar *dest_real = g_strdup_printf ("%s/%s.%s", cache->path, dest_uid, (dest_part_spec)?dest_part_spec:"~");
 
 	rename (dest_real, real);
 
@@ -748,8 +765,8 @@
 camel_imap_message_cache_delete_attachments (CamelImapMessageCache *cache, const char *uid)
 {
   CamelStream *in = camel_imap_message_cache_get (cache, uid, "", NULL);
-  gchar *real1 = g_strdup_printf ("%s/%s.", cache->path, uid);
-  gchar *real = g_strdup_printf ("%s.tmp", real1);
+  gchar *real1 = cachefile_get(cache->path, uid, NULL);
+  gchar *real = g_strdup_printf ("%s/%s.tmp", cache->path, uid);
   CamelStream *to = camel_stream_fs_new_with_name (real, O_RDWR|O_CREAT|O_TRUNC, 0600);
   int n;
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 3801)
+++ ChangeLog	(working copy)
@@ -1,3 +1,10 @@
+2008-11-13  Thomas Guillem  <thomas guillem gmail com>
+
+	* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-message-cache.c:
+	Change the default cache filename from "uid." to "uid.~" in order to
+	keep compatibility with FAT32 partitions. (a FAT32 file can't end with '.')
+	Old cache files ("uid.") are still compatible.
+	
 2008-11-10  Jose Dapena Paz  <jdapena igalia com>
 
 	Complete rework of the lock behavior of Tinymail

Attachment: pgpBvsNt7DoLC.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]