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.
This commit is contained in:
Philippe Normand 2019-08-19 11:08:41 +01:00
parent 3351807107
commit 83320610b2

View file

@ -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);