From 83320610b2a0be29bbb2fb715a1fccd9c578066d Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Mon, 19 Aug 2019 11:08:41 +0100 Subject: [PATCH] validate/ssim: Clean-up temporary directory When no output-dir is specified in the plugin config, a temporary directory is created, so it needs to be removed when no-longer needed. --- validate/plugins/ssim/gstvalidatessim.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/validate/plugins/ssim/gstvalidatessim.c b/validate/plugins/ssim/gstvalidatessim.c index 3784752..9db6a9b 100644 --- a/validate/plugins/ssim/gstvalidatessim.c +++ b/validate/plugins/ssim/gstvalidatessim.c @@ -352,6 +352,9 @@ static void _finalize (GObject * object) { ValidateSsimOverridePrivate *priv = VALIDATE_SSIM_OVERRIDE (object)->priv; + GDir *outdir_handle = NULL; + const gchar *filename = NULL; + GError *error = NULL; if (priv->converter) gst_video_converter_free (priv->converter); @@ -359,6 +362,25 @@ _finalize (GObject * object) if (priv->last_caps) gst_caps_unref (priv->last_caps); + if (priv->config && !gst_structure_has_field (priv->config, "output-dir")) { + /* Remove temporary directory contents (expected to be files, no sub-directories). */ + outdir_handle = g_dir_open (priv->outdir, 0, &error); + if (outdir_handle != NULL) { + while ((filename = g_dir_read_name (outdir_handle))) { + gchar *path = + g_build_path (G_DIR_SEPARATOR_S, priv->outdir, filename, NULL); + g_remove (path); + g_free (path); + } + g_dir_close (outdir_handle); + } else { + GST_ERROR ("Unable to cleanup temporary directory %s: %s", priv->outdir, + error->message); + g_error_free (error); + } + g_rmdir (priv->outdir); + } + g_free (priv->outdir); g_free (priv->result_outdir); g_array_unref (priv->frames); -- 2.7.4