/* RecursiveDelete.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from RecursiveDelete.vala, do not modify */

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*-
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 * SPDX-FileCopyrightText: Michael Terry
 */

#include "deja.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	DEJA_DUP_RECURSIVE_DELETE_0_PROPERTY,
	DEJA_DUP_RECURSIVE_DELETE_SKIP_PROPERTY,
	DEJA_DUP_RECURSIVE_DELETE_ONLY_PROPERTY,
	DEJA_DUP_RECURSIVE_DELETE_LEAVE_TOP_PROPERTY,
	DEJA_DUP_RECURSIVE_DELETE_NUM_PROPERTIES
};
static GParamSpec* deja_dup_recursive_delete_properties[DEJA_DUP_RECURSIVE_DELETE_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _DejaDupRecursiveDeletePrivate {
	gchar* _skip;
	GRegex* _only;
	gboolean _leave_top;
};

static gint DejaDupRecursiveDelete_private_offset;
static gpointer deja_dup_recursive_delete_parent_class = NULL;

static GFileType deja_dup_recursive_delete_real_query_file_type (DejaDupRecursiveOp* base,
                                                          GFile* file);
static void deja_dup_recursive_delete_real_handle_file (DejaDupRecursiveOp* base);
static void deja_dup_recursive_delete_real_finish_dir (DejaDupRecursiveOp* base);
static DejaDupRecursiveOp* deja_dup_recursive_delete_real_clone_for_info (DejaDupRecursiveOp* base,
                                                                   GFileInfo* info);
static void deja_dup_recursive_delete_finalize (GObject * obj);
static GType deja_dup_recursive_delete_get_type_once (void);
static void _vala_deja_dup_recursive_delete_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_deja_dup_recursive_delete_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
deja_dup_recursive_delete_get_instance_private (DejaDupRecursiveDelete* self)
{
	return G_STRUCT_MEMBER_P (self, DejaDupRecursiveDelete_private_offset);
}

DejaDupRecursiveDelete*
deja_dup_recursive_delete_construct (GType object_type,
                                     GFile* source,
                                     const gchar* skip,
                                     GRegex* only,
                                     gboolean leave_top)
{
	DejaDupRecursiveDelete * self = NULL;
	g_return_val_if_fail (source != NULL, NULL);
	self = (DejaDupRecursiveDelete*) g_object_new (object_type, "src", source, "skip", skip, "only", only, "leave-top", leave_top, NULL);
	return self;
}

DejaDupRecursiveDelete*
deja_dup_recursive_delete_new (GFile* source,
                               const gchar* skip,
                               GRegex* only,
                               gboolean leave_top)
{
	return deja_dup_recursive_delete_construct (DEJA_DUP_TYPE_RECURSIVE_DELETE, source, skip, only, leave_top);
}

static GFileType
deja_dup_recursive_delete_real_query_file_type (DejaDupRecursiveOp* base,
                                                GFile* file)
{
	DejaDupRecursiveDelete * self;
	gboolean _tmp0_;
	GFileType result;
	self = (DejaDupRecursiveDelete*) base;
	g_return_val_if_fail (file != NULL, 0);
	_tmp0_ = self->priv->_leave_top;
	if (_tmp0_) {
		result = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL);
		return result;
	} else {
		result = DEJA_DUP_RECURSIVE_OP_CLASS (deja_dup_recursive_delete_parent_class)->query_file_type (G_TYPE_CHECK_INSTANCE_CAST (self, DEJA_DUP_TYPE_RECURSIVE_OP, DejaDupRecursiveOp), file);
		return result;
	}
}

static void
deja_dup_recursive_delete_real_handle_file (DejaDupRecursiveOp* base)
{
	DejaDupRecursiveDelete * self;
	gboolean _tmp0_ = FALSE;
	GRegex* _tmp1_;
	gboolean _tmp7_;
	GError* _inner_error0_ = NULL;
	self = (DejaDupRecursiveDelete*) base;
	_tmp1_ = self->priv->_only;
	if (_tmp1_ != NULL) {
		GRegex* _tmp2_;
		GFile* _tmp3_;
		GFile* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp2_ = self->priv->_only;
		_tmp3_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_file_get_basename (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = !g_regex_match (_tmp2_, _tmp6_, 0, NULL);
		_g_free0 (_tmp6_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	_tmp7_ = self->priv->_leave_top;
	if (_tmp7_) {
		return;
	}
	{
		GFile* _tmp8_;
		GFile* _tmp9_;
		_tmp8_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self);
		_tmp9_ = _tmp8_;
		g_file_delete (_tmp9_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GFile* _tmp10_;
		GFile* _tmp11_;
		GFile* _tmp12_;
		GFile* _tmp13_;
		GError* _tmp14_;
		const gchar* _tmp15_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp10_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self);
		_tmp11_ = _tmp10_;
		_tmp12_ = deja_dup_recursive_op_get_dst ((DejaDupRecursiveOp*) self);
		_tmp13_ = _tmp12_;
		_tmp14_ = e;
		_tmp15_ = _tmp14_->message;
		g_signal_emit_by_name ((DejaDupRecursiveOp*) self, "raise-error", _tmp11_, _tmp13_, _tmp15_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static void
deja_dup_recursive_delete_real_finish_dir (DejaDupRecursiveOp* base)
{
	DejaDupRecursiveDelete * self;
	gboolean _tmp0_ = FALSE;
	GRegex* _tmp1_;
	gboolean _tmp7_;
	GError* _inner_error0_ = NULL;
	self = (DejaDupRecursiveDelete*) base;
	_tmp1_ = self->priv->_only;
	if (_tmp1_ != NULL) {
		GRegex* _tmp2_;
		GFile* _tmp3_;
		GFile* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp2_ = self->priv->_only;
		_tmp3_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self);
		_tmp4_ = _tmp3_;
		_tmp5_ = g_file_get_basename (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp0_ = !g_regex_match (_tmp2_, _tmp6_, 0, NULL);
		_g_free0 (_tmp6_);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		return;
	}
	_tmp7_ = self->priv->_leave_top;
	if (_tmp7_) {
		return;
	}
	{
		GFile* _tmp8_;
		GFile* _tmp9_;
		_tmp8_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self);
		_tmp9_ = _tmp8_;
		g_file_delete (_tmp9_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		g_clear_error (&_inner_error0_);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return;
	}
}

static DejaDupRecursiveOp*
deja_dup_recursive_delete_real_clone_for_info (DejaDupRecursiveOp* base,
                                               GFileInfo* info)
{
	DejaDupRecursiveDelete * self;
	gchar* child_name = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	GFile* src_child = NULL;
	GFile* _tmp4_;
	GFile* _tmp5_;
	const gchar* _tmp6_;
	GFile* _tmp7_;
	GFile* _tmp8_;
	GRegex* _tmp9_;
	DejaDupRecursiveDelete* _tmp10_;
	DejaDupRecursiveOp* result;
	self = (DejaDupRecursiveDelete*) base;
	g_return_val_if_fail (info != NULL, NULL);
	_tmp0_ = g_file_info_get_name (info);
	_tmp1_ = g_strdup (_tmp0_);
	child_name = _tmp1_;
	_tmp2_ = child_name;
	_tmp3_ = self->priv->_skip;
	if (g_strcmp0 (_tmp2_, _tmp3_) == 0) {
		result = NULL;
		_g_free0 (child_name);
		return result;
	}
	_tmp4_ = deja_dup_recursive_op_get_src ((DejaDupRecursiveOp*) self);
	_tmp5_ = _tmp4_;
	_tmp6_ = child_name;
	_tmp7_ = g_file_get_child (_tmp5_, _tmp6_);
	src_child = _tmp7_;
	_tmp8_ = src_child;
	_tmp9_ = self->priv->_only;
	_tmp10_ = deja_dup_recursive_delete_new (_tmp8_, NULL, _tmp9_, FALSE);
	result = (DejaDupRecursiveOp*) _tmp10_;
	_g_object_unref0 (src_child);
	_g_free0 (child_name);
	return result;
}

const gchar*
deja_dup_recursive_delete_get_skip (DejaDupRecursiveDelete* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_skip;
	result = _tmp0_;
	return result;
}

static void
deja_dup_recursive_delete_set_skip (DejaDupRecursiveDelete* self,
                                    const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = deja_dup_recursive_delete_get_skip (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_skip);
		self->priv->_skip = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, deja_dup_recursive_delete_properties[DEJA_DUP_RECURSIVE_DELETE_SKIP_PROPERTY]);
	}
}

GRegex*
deja_dup_recursive_delete_get_only (DejaDupRecursiveDelete* self)
{
	GRegex* result;
	GRegex* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_only;
	result = _tmp0_;
	return result;
}

static gpointer
_g_regex_ref0 (gpointer self)
{
	return self ? g_regex_ref (self) : NULL;
}

static void
deja_dup_recursive_delete_set_only (DejaDupRecursiveDelete* self,
                                    GRegex* value)
{
	GRegex* old_value;
	g_return_if_fail (self != NULL);
	old_value = deja_dup_recursive_delete_get_only (self);
	if (old_value != value) {
		GRegex* _tmp0_;
		_tmp0_ = _g_regex_ref0 (value);
		_g_regex_unref0 (self->priv->_only);
		self->priv->_only = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, deja_dup_recursive_delete_properties[DEJA_DUP_RECURSIVE_DELETE_ONLY_PROPERTY]);
	}
}

gboolean
deja_dup_recursive_delete_get_leave_top (DejaDupRecursiveDelete* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->_leave_top;
	return result;
}

static void
deja_dup_recursive_delete_set_leave_top (DejaDupRecursiveDelete* self,
                                         gboolean value)
{
	gboolean old_value;
	g_return_if_fail (self != NULL);
	old_value = deja_dup_recursive_delete_get_leave_top (self);
	if (old_value != value) {
		self->priv->_leave_top = value;
		g_object_notify_by_pspec ((GObject *) self, deja_dup_recursive_delete_properties[DEJA_DUP_RECURSIVE_DELETE_LEAVE_TOP_PROPERTY]);
	}
}

static void
deja_dup_recursive_delete_class_init (DejaDupRecursiveDeleteClass * klass,
                                      gpointer klass_data)
{
	deja_dup_recursive_delete_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DejaDupRecursiveDelete_private_offset);
	((DejaDupRecursiveOpClass *) klass)->query_file_type = (GFileType (*) (DejaDupRecursiveOp*, GFile*)) deja_dup_recursive_delete_real_query_file_type;
	((DejaDupRecursiveOpClass *) klass)->handle_file = (void (*) (DejaDupRecursiveOp*)) deja_dup_recursive_delete_real_handle_file;
	((DejaDupRecursiveOpClass *) klass)->finish_dir = (void (*) (DejaDupRecursiveOp*)) deja_dup_recursive_delete_real_finish_dir;
	((DejaDupRecursiveOpClass *) klass)->clone_for_info = (DejaDupRecursiveOp* (*) (DejaDupRecursiveOp*, GFileInfo*)) deja_dup_recursive_delete_real_clone_for_info;
	G_OBJECT_CLASS (klass)->get_property = _vala_deja_dup_recursive_delete_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_deja_dup_recursive_delete_set_property;
	G_OBJECT_CLASS (klass)->finalize = deja_dup_recursive_delete_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_RECURSIVE_DELETE_SKIP_PROPERTY, deja_dup_recursive_delete_properties[DEJA_DUP_RECURSIVE_DELETE_SKIP_PROPERTY] = g_param_spec_string ("skip", "skip", "skip", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_RECURSIVE_DELETE_ONLY_PROPERTY, deja_dup_recursive_delete_properties[DEJA_DUP_RECURSIVE_DELETE_ONLY_PROPERTY] = g_param_spec_boxed ("only", "only", "only", G_TYPE_REGEX, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DEJA_DUP_RECURSIVE_DELETE_LEAVE_TOP_PROPERTY, deja_dup_recursive_delete_properties[DEJA_DUP_RECURSIVE_DELETE_LEAVE_TOP_PROPERTY] = g_param_spec_boolean ("leave-top", "leave-top", "leave-top", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
}

static void
deja_dup_recursive_delete_instance_init (DejaDupRecursiveDelete * self,
                                         gpointer klass)
{
	self->priv = deja_dup_recursive_delete_get_instance_private (self);
}

static void
deja_dup_recursive_delete_finalize (GObject * obj)
{
	DejaDupRecursiveDelete * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DEJA_DUP_TYPE_RECURSIVE_DELETE, DejaDupRecursiveDelete);
	_g_free0 (self->priv->_skip);
	_g_regex_unref0 (self->priv->_only);
	G_OBJECT_CLASS (deja_dup_recursive_delete_parent_class)->finalize (obj);
}

 G_GNUC_NO_INLINE static GType
deja_dup_recursive_delete_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DejaDupRecursiveDeleteClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) deja_dup_recursive_delete_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DejaDupRecursiveDelete), 0, (GInstanceInitFunc) deja_dup_recursive_delete_instance_init, NULL };
	GType deja_dup_recursive_delete_type_id;
	deja_dup_recursive_delete_type_id = g_type_register_static (DEJA_DUP_TYPE_RECURSIVE_OP, "DejaDupRecursiveDelete", &g_define_type_info, 0);
	DejaDupRecursiveDelete_private_offset = g_type_add_instance_private (deja_dup_recursive_delete_type_id, sizeof (DejaDupRecursiveDeletePrivate));
	return deja_dup_recursive_delete_type_id;
}

GType
deja_dup_recursive_delete_get_type (void)
{
	static gsize deja_dup_recursive_delete_type_id__once = 0;
	if (g_once_init_enter (&deja_dup_recursive_delete_type_id__once)) {
		GType deja_dup_recursive_delete_type_id;
		deja_dup_recursive_delete_type_id = deja_dup_recursive_delete_get_type_once ();
		g_once_init_leave (&deja_dup_recursive_delete_type_id__once, deja_dup_recursive_delete_type_id);
	}
	return deja_dup_recursive_delete_type_id__once;
}

static void
_vala_deja_dup_recursive_delete_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	DejaDupRecursiveDelete * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DEJA_DUP_TYPE_RECURSIVE_DELETE, DejaDupRecursiveDelete);
	switch (property_id) {
		case DEJA_DUP_RECURSIVE_DELETE_SKIP_PROPERTY:
		g_value_set_string (value, deja_dup_recursive_delete_get_skip (self));
		break;
		case DEJA_DUP_RECURSIVE_DELETE_ONLY_PROPERTY:
		g_value_set_boxed (value, deja_dup_recursive_delete_get_only (self));
		break;
		case DEJA_DUP_RECURSIVE_DELETE_LEAVE_TOP_PROPERTY:
		g_value_set_boolean (value, deja_dup_recursive_delete_get_leave_top (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_deja_dup_recursive_delete_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	DejaDupRecursiveDelete * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DEJA_DUP_TYPE_RECURSIVE_DELETE, DejaDupRecursiveDelete);
	switch (property_id) {
		case DEJA_DUP_RECURSIVE_DELETE_SKIP_PROPERTY:
		deja_dup_recursive_delete_set_skip (self, g_value_get_string (value));
		break;
		case DEJA_DUP_RECURSIVE_DELETE_ONLY_PROPERTY:
		deja_dup_recursive_delete_set_only (self, g_value_get_boxed (value));
		break;
		case DEJA_DUP_RECURSIVE_DELETE_LEAVE_TOP_PROPERTY:
		deja_dup_recursive_delete_set_leave_top (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

