Commit d9d980a1 authored by Brian Gruber's avatar Brian Gruber

when importing, use id to make unique filename for each photo

parent 443dac0a
Pipeline #174711 passed with stage
in 5 minutes and 44 seconds
......@@ -246,10 +246,12 @@ parse_yield (const char *text,
}
static GPtrArray *
load_image (const char *data)
load_image (const char *id,
const char *data)
{
GPtrArray *images;
GrImage *ri;
g_autofree char *basename = NULL;
g_autofree char *dir = NULL;
g_autofree char *path = NULL;
g_autoptr(GError) error = NULL;
......@@ -258,10 +260,11 @@ load_image (const char *data)
decoded = (char *)g_base64_decode (data, &length);
basename = g_strconcat (id, ".jpg", NULL);
dir = g_build_filename (get_user_data_dir (), "images", NULL);
g_mkdir_with_parents (dir, 0755);
path = g_build_filename (dir, "importXXXXXX.jpg", NULL);
path = g_build_filename (dir, basename, NULL);
if (!g_file_set_contents (path, decoded, length, &error)) {
g_warning ("Failed to save image: %s", error->message);
return NULL;
......@@ -355,7 +358,7 @@ end_element (GMarkupParseContext *context,
id = generate_id ("R_", pd->title, "_by_", pd->source, NULL);
chef = ensure_chef (pd->store, pd->source);
images = load_image (pd->image_data);
images = load_image (id, pd->image_data);
recipe = g_object_new (GR_TYPE_RECIPE,
"id", id,
"author", gr_chef_get_id (chef),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment