static gint collection_save_private(CollectionData *cd, const gchar *path) { FILE *f; GList *work; gchar *tmp_path; gchar *pathl; mode_t save_mask; if (!path && !cd->path) return FALSE; if (!path) { path = cd->path; } tmp_path = unique_filename(path, ".tmp", "_", 3); if (!tmp_path) return FALSE; pathl = path_from_utf8(tmp_path); save_mask = umask(0077); f = fopen(pathl, "w"); umask(save_mask); g_free(pathl); if (!f) { /* file open failed */ printf("failed to open collection (write) \"%s\"\n", tmp_path); g_free(tmp_path); return FALSE; } fprintf(f, "%s collection\n", GQVIEW_COLLECTION_MARKER); fprintf(f, "#created with GQview version %s\n", VERSION); collection_update_geometry(cd); if (cd->window_read) { fprintf(f, "#geometry: %d %d %d %d\n", cd->window_x, cd->window_y, cd->window_w, cd->window_h); } work = cd->list; while (work) { CollectInfo *ci = work->data; if (fprintf(f, "\"%s\"\n", ci->path) < 0) { fclose(f); printf("Error writing to %s\n", tmp_path); unlink_file(tmp_path); g_free(tmp_path); return FALSE; } work = work->next; } fprintf(f, "#end\n"); fclose(f); copy_file_attributes(path, tmp_path, TRUE, FALSE); if (!rename_file(tmp_path, path)) { printf("collection save unable to rename %s to %s\n", tmp_path, path); unlink_file(tmp_path); g_free(tmp_path); return FALSE; } g_free(tmp_path); if (!cd->path || strcmp(path, cd->path) != 0) { gchar *buf = cd->path; cd->path = g_strdup(path); path = cd->path; g_free(buf); g_free(cd->name); cd->name = g_strdup(filename_from_path(cd->path)); collection_path_changed(cd); } cd->changed = FALSE; return TRUE; }
static gboolean collection_save_private(CollectionData *cd, const gchar *path) { SecureSaveInfo *ssi; GList *work; gchar *pathl; if (!path && !cd->path) return FALSE; if (!path) { path = cd->path; } pathl = path_from_utf8(path); ssi = secure_open(pathl); g_free(pathl); if (!ssi) { log_printf(_("failed to open collection (write) \"%s\"\n"), path); return FALSE; } secure_fprintf(ssi, "%s collection\n", GQ_COLLECTION_MARKER); secure_fprintf(ssi, "#created with %s version %s\n", GQ_APPNAME, VERSION); collection_update_geometry(cd); if (cd->window_read) { secure_fprintf(ssi, "#geometry: %d %d %d %d\n", cd->window_x, cd->window_y, cd->window_w, cd->window_h); } work = cd->list; while (work && secsave_errno == SS_ERR_NONE) { CollectInfo *ci = work->data; secure_fprintf(ssi, "\"%s\"\n", ci->fd->path); work = work->next; } secure_fprintf(ssi, "#end\n"); if (secure_close(ssi)) { log_printf(_("error saving collection file: %s\nerror: %s\n"), path, secsave_strerror(secsave_errno)); return FALSE; } if (!cd->path || strcmp(path, cd->path) != 0) { gchar *buf = cd->path; cd->path = g_strdup(path); path = cd->path; g_free(buf); g_free(cd->name); cd->name = g_strdup(filename_from_path(cd->path)); collection_path_changed(cd); } cd->changed = FALSE; return TRUE; }