gchar* mu_msg_part_get_cache_path (MuMsg *msg, MuMsgOptions opts, guint partid, GError **err) { char *dirname, *filepath; const char* path; g_return_val_if_fail (msg, NULL); if (!mu_msg_load_msg_file (msg, NULL)) return NULL; path = mu_msg_get_path (msg); /* g_compute_checksum_for_string may be better, but requires * rel. new glib (2.16) */ dirname = g_strdup_printf ("%s%c%x%c%u", mu_util_cache_dir(), G_DIR_SEPARATOR, g_str_hash (path), G_DIR_SEPARATOR, partid); if (!mu_util_create_dir_maybe (dirname, 0700, FALSE)) { mu_util_g_set_error (err, MU_ERROR_FILE, "failed to create dir %s", dirname); g_free (dirname); return NULL; } filepath = mu_msg_part_get_path (msg, opts, dirname, partid, err); g_free (dirname); return filepath; }
static gboolean print_to_pdf (WebKitWebFrame *frame, GError **err) { GtkPrintOperation *op; GtkPrintOperationResult res; char *path; gboolean rv; path = g_strdup_printf ("%s%c%x.pdf",mu_util_cache_dir(), G_DIR_SEPARATOR, (unsigned)random()); if (!mu_util_create_dir_maybe (mu_util_cache_dir(),0700,FALSE)) { g_warning ("Couldn't create tempdir"); return FALSE; } op = gtk_print_operation_new (); gtk_print_operation_set_export_filename (GTK_PRINT_OPERATION(op), path); res = webkit_web_frame_print_full (frame, op, GTK_PRINT_OPERATION_ACTION_EXPORT, err); g_object_unref (op); rv = (res != GTK_PRINT_OPERATION_RESULT_ERROR); if (rv) g_print ("%s\n", path); g_free (path); return rv; }
static gboolean create_dirs_maybe (MuRuntimeData *data) { if (!mu_util_create_dir_maybe (data->_str[MU_RUNTIME_PATH_CACHE], 0700, TRUE)) { g_warning ("failed to create cache dir"); return FALSE; } if (!mu_util_create_dir_maybe (data->_str[MU_RUNTIME_PATH_LOG], 0700, TRUE)) { g_warning ("failed to create log dir"); return FALSE; } return TRUE; }
char* mu_util_create_tmpdir (void) { gchar *dirname; dirname = g_strdup_printf ("%s%cmu-%d%c%x", g_get_tmp_dir(), G_DIR_SEPARATOR, getuid(), G_DIR_SEPARATOR, (int)random()*getpid()*(int)time(NULL)); if (!mu_util_create_dir_maybe (dirname, 0700, FALSE)) { g_free (dirname); return NULL; } return dirname; }
gboolean mu_runtime_init (const char* muhome_arg, const char *name) { gchar *muhome; g_return_val_if_fail (!_initialized, FALSE); g_return_val_if_fail (name, FALSE); setlocale (LC_ALL, ""); #ifndef GLIB_VERSION_2_36 g_type_init (); #endif /*GLIB_VERSION_2_36*/ if (muhome_arg) muhome = g_strdup (muhome_arg); else muhome = mu_util_guess_mu_homedir (); if (!mu_util_create_dir_maybe (muhome, 0700, TRUE)) { g_printerr ("mu: invalid mu homedir specified;" " use --muhome=<dir>\n"); runtime_free (); return FALSE; } _data = g_new0 (MuRuntimeData, 1); _data->_str[MU_RUNTIME_PATH_MUHOME] = muhome; init_paths (muhome, _data); _data->_name = g_strdup (name); if (!init_log (muhome, name, MU_LOG_OPTIONS_BACKUP)) { runtime_free (); g_free (muhome); return FALSE; } return _initialized = TRUE; }
gboolean mu_runtime_init_from_cmdline (int *pargc, char ***pargv, const char *name) { g_return_val_if_fail (!_initialized, FALSE); g_return_val_if_fail (name, FALSE); setlocale (LC_ALL, ""); g_type_init (); _data = g_new0 (MuRuntimeData, 1); _data->_config = mu_config_init (pargc, pargv); if (!_data->_config) { runtime_free (); return FALSE; } if (!mu_util_create_dir_maybe (_data->_config->muhome, 0700, TRUE)) { g_printerr ("mu: invalid mu homedir specified;" " use --muhome=<dir>\n"); runtime_free (); return FALSE; } _data->_name = g_strdup (name); _data->_str[MU_RUNTIME_PATH_MUHOME] = g_strdup (_data->_config->muhome); init_paths (_data->_str[MU_RUNTIME_PATH_MUHOME], _data); if (!init_log (runtime_path(MU_RUNTIME_PATH_MUHOME), name, _data->_config->log_stderr, _data->_config->quiet, _data->_config->debug)) { runtime_free (); return FALSE; } return _initialized = TRUE; }