Author: post
Date: 2010-03-28 14:09:47 +0200 (Sun, 28 Mar 2010)
New Revision: 3270

Modified:
   trunk/librawstudio/rs-utils.c
Log:
When reading from a read-only media, generate a directory in the home directory 
using md5 of the image, and store settings there.

Modified: trunk/librawstudio/rs-utils.c
===================================================================
--- trunk/librawstudio/rs-utils.c       2010-03-28 10:52:23 UTC (rev 3269)
+++ trunk/librawstudio/rs-utils.c       2010-03-28 12:09:47 UTC (rev 3270)
@@ -340,7 +340,7 @@
 gchar *
 rs_dotdir_get(const gchar *filename)
 {
-       gchar *ret;
+       gchar *ret = NULL;
        gchar *directory;
        GString *dotdir;
        gboolean dotdir_is_local = FALSE;
@@ -370,8 +370,28 @@
                else
                        ret = dotdir->str;
        }
-       else
+       else if (g_file_test(dotdir->str, G_FILE_TEST_IS_DIR))
                ret = dotdir->str;
+       else 
+               ret = NULL;
+
+       /* If we for some reason cannot write to the current directory, */
+       /* we save it to a new folder named as the md5 of the file content, */
+       /* not particularly fast, but ensures that the images can be moved */
+       if (ret == NULL)
+       {
+               g_string_free(dotdir, TRUE);
+               g_free(directory);
+               gchar* md5 = rs_file_checksum(filename);
+               ret = g_strdup_printf("%s/read-only-cache/%s", 
rs_confdir_get(), md5);
+               g_free(md5);
+               if (!g_file_test(ret, (G_FILE_TEST_EXISTS | 
G_FILE_TEST_IS_DIR)))
+               {
+                       if (g_mkdir_with_parents(ret, 0700) != 0)
+                               ret = NULL;
+               }
+               return ret;
+       }
        g_free(directory);
        g_string_free(dotdir, FALSE);
        return (ret);


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to