/** * midgard_blob_remove_file: * @self: #MidgardBlob self instance. * * Deletes a file which is associated with blob and located at * attachment's location which is initialized for blob. * #midgard_blob_exists should be invoked if file may be already * deleted, for example when one file is shared among many attachments. * * Returns: %TRUE on success, %FALSE otherwise */ gboolean midgard_blob_remove_file(MidgardBlob *self) { g_assert(self != NULL); MidgardConnection *mgd = self->priv->mgd; MIDGARD_ERRNO_SET(mgd, MGD_ERR_OK); __get_filepath(self); if(!self->priv->filepath) { MIDGARD_ERRNO_SET(self->priv->mgd, MGD_ERR_INTERNAL); g_warning("Can not delete '%s'. No file location", self->priv->filepath); return FALSE; } if(!midgard_blob_exists(self)) { MIDGARD_ERRNO_SET(self->priv->mgd, MGD_ERR_INTERNAL); g_warning("Can not delete '%s'. File doesn't exists", self->priv->filepath); return FALSE; } guint deleted = g_remove(self->priv->filepath); if(deleted == 0) return TRUE; g_warning("Can not delete '%s'. Unknown reason", self->priv->filepath); MIDGARD_ERRNO_SET(self->priv->mgd, MGD_ERR_INTERNAL); return FALSE; }
gboolean midgard_core_object_parameters_purge_with_blob( MidgardConnection *mgd, const gchar *class_name, const gchar *guid, guint n_params, const GParameter *parameters) { g_assert(mgd != NULL); g_assert(class_name != NULL); g_assert(guid != NULL); GObject **objects = __fetch_parameter_objects( mgd, class_name, guid, n_params, parameters); /* nothing to purge */ if(!objects) return FALSE; gboolean rv = FALSE; guint i = 0; MidgardBlob *blob = NULL; while (objects[i] != NULL ) { /* ! IMPORTANT ! * Blob on filesystem must be deleted first. * In any other case, if something goes wrong, we won't be able * to check which file is orphaned. * If file is removed and record's deletion failed, on is able * to check file with blob's file_exists method */ blob = midgard_blob_new(MIDGARD_OBJECT(objects[i]), NULL); if(!blob) { g_warning("Can not handle blob for given attachment"); continue; } if(midgard_blob_exists(blob)) midgard_blob_remove_file(blob, NULL); midgard_object_purge(MIDGARD_OBJECT(objects[i]), FALSE); g_object_unref(blob); g_object_unref(objects[i]); i++; } g_free(objects); return rv; }