Blame src/builder-source-file.c

rpm-build c487f7
/* builder-source-file.c
rpm-build c487f7
 *
rpm-build c487f7
 * Copyright (C) 2015 Red Hat, Inc
rpm-build c487f7
 *
rpm-build c487f7
 * This file is free software; you can redistribute it and/or modify it
rpm-build c487f7
 * under the terms of the GNU Lesser General Public License as
rpm-build c487f7
 * published by the Free Software Foundation; either version 2 of the
rpm-build c487f7
 * License, or (at your option) any later version.
rpm-build c487f7
 *
rpm-build c487f7
 * This file is distributed in the hope that it will be useful, but
rpm-build c487f7
 * WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build c487f7
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build c487f7
 * Lesser General Public License for more details.
rpm-build c487f7
 *
rpm-build c487f7
 * You should have received a copy of the GNU Lesser General Public License
rpm-build c487f7
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
rpm-build c487f7
 *
rpm-build c487f7
 * Authors:
rpm-build c487f7
 *       Alexander Larsson <alexl@redhat.com>
rpm-build c487f7
 */
rpm-build c487f7
rpm-build c487f7
#include "config.h"
rpm-build c487f7
rpm-build c487f7
#include <string.h>
rpm-build c487f7
#include <fcntl.h>
rpm-build c487f7
#include <stdio.h>
rpm-build c487f7
#include <stdlib.h>
rpm-build c487f7
#include <sys/statfs.h>
rpm-build c487f7
rpm-build c487f7
#include "builder-flatpak-utils.h"
rpm-build c487f7
rpm-build c487f7
#include "builder-utils.h"
rpm-build c487f7
#include "builder-source-file.h"
rpm-build c487f7
rpm-build c487f7
struct BuilderSourceFile
rpm-build c487f7
{
rpm-build c487f7
  BuilderSource parent;
rpm-build c487f7
rpm-build c487f7
  char         *path;
rpm-build c487f7
  char         *url;
rpm-build c487f7
  char        **mirror_urls;
rpm-build c487f7
  char         *md5;
rpm-build c487f7
  char         *sha1;
rpm-build c487f7
  char         *sha256;
rpm-build c487f7
  char         *sha512;
rpm-build c487f7
  char         *dest_filename;
rpm-build c487f7
};
rpm-build c487f7
rpm-build c487f7
typedef struct
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceClass parent_class;
rpm-build c487f7
} BuilderSourceFileClass;
rpm-build c487f7
rpm-build c487f7
G_DEFINE_TYPE (BuilderSourceFile, builder_source_file, BUILDER_TYPE_SOURCE);
rpm-build c487f7
rpm-build c487f7
enum {
rpm-build c487f7
  PROP_0,
rpm-build c487f7
  PROP_PATH,
rpm-build c487f7
  PROP_URL,
rpm-build c487f7
  PROP_MD5,
rpm-build c487f7
  PROP_SHA1,
rpm-build c487f7
  PROP_SHA256,
rpm-build c487f7
  PROP_SHA512,
rpm-build c487f7
  PROP_DEST_FILENAME,
rpm-build c487f7
  PROP_MIRROR_URLS,
rpm-build c487f7
  LAST_PROP
rpm-build c487f7
};
rpm-build c487f7
rpm-build c487f7
static void
rpm-build c487f7
builder_source_file_finalize (GObject *object)
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceFile *self = (BuilderSourceFile *) object;
rpm-build c487f7
rpm-build c487f7
  g_free (self->path);
rpm-build c487f7
  g_free (self->url);
rpm-build c487f7
  g_free (self->md5);
rpm-build c487f7
  g_free (self->sha1);
rpm-build c487f7
  g_free (self->sha256);
rpm-build c487f7
  g_free (self->sha512);
rpm-build c487f7
  g_free (self->dest_filename);
rpm-build c487f7
  g_strfreev (self->mirror_urls);
rpm-build c487f7
rpm-build c487f7
  G_OBJECT_CLASS (builder_source_file_parent_class)->finalize (object);
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static void
rpm-build c487f7
builder_source_file_get_property (GObject    *object,
rpm-build c487f7
                                  guint       prop_id,
rpm-build c487f7
                                  GValue     *value,
rpm-build c487f7
                                  GParamSpec *pspec)
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (object);
rpm-build c487f7
rpm-build c487f7
  switch (prop_id)
rpm-build c487f7
    {
rpm-build c487f7
    case PROP_PATH:
rpm-build c487f7
      g_value_set_string (value, self->path);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_URL:
rpm-build c487f7
      g_value_set_string (value, self->url);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_MD5:
rpm-build c487f7
      g_value_set_string (value, self->md5);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_SHA1:
rpm-build c487f7
      g_value_set_string (value, self->sha1);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_SHA256:
rpm-build c487f7
      g_value_set_string (value, self->sha256);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_SHA512:
rpm-build c487f7
      g_value_set_string (value, self->sha512);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_DEST_FILENAME:
rpm-build c487f7
      g_value_set_string (value, self->dest_filename);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_MIRROR_URLS:
rpm-build c487f7
      g_value_set_boxed (value, self->mirror_urls);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    default:
rpm-build c487f7
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
rpm-build c487f7
    }
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static void
rpm-build c487f7
builder_source_file_set_property (GObject      *object,
rpm-build c487f7
                                  guint         prop_id,
rpm-build c487f7
                                  const GValue *value,
rpm-build c487f7
                                  GParamSpec   *pspec)
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (object);
rpm-build c487f7
  gchar **tmp;
rpm-build c487f7
rpm-build c487f7
  switch (prop_id)
rpm-build c487f7
    {
rpm-build c487f7
    case PROP_PATH:
rpm-build c487f7
      g_free (self->path);
rpm-build c487f7
      self->path = g_value_dup_string (value);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_URL:
rpm-build c487f7
      g_free (self->url);
rpm-build c487f7
      self->url = g_value_dup_string (value);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_MD5:
rpm-build c487f7
      g_free (self->md5);
rpm-build c487f7
      self->md5 = g_value_dup_string (value);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_SHA1:
rpm-build c487f7
      g_free (self->sha1);
rpm-build c487f7
      self->sha1 = g_value_dup_string (value);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_SHA256:
rpm-build c487f7
      g_free (self->sha256);
rpm-build c487f7
      self->sha256 = g_value_dup_string (value);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_SHA512:
rpm-build c487f7
      g_free (self->sha512);
rpm-build c487f7
      self->sha512 = g_value_dup_string (value);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_DEST_FILENAME:
rpm-build c487f7
      g_free (self->dest_filename);
rpm-build c487f7
      self->dest_filename = g_value_dup_string (value);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    case PROP_MIRROR_URLS:
rpm-build c487f7
      tmp = self->mirror_urls;
rpm-build c487f7
      self->mirror_urls = g_strdupv (g_value_get_boxed (value));
rpm-build c487f7
      g_strfreev (tmp);
rpm-build c487f7
      break;
rpm-build c487f7
rpm-build c487f7
    default:
rpm-build c487f7
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
rpm-build c487f7
    }
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static SoupURI *
rpm-build c487f7
get_uri (BuilderSourceFile *self,
rpm-build c487f7
         GError           **error)
rpm-build c487f7
{
rpm-build c487f7
  SoupURI *uri;
rpm-build c487f7
rpm-build c487f7
  if (self->url == NULL)
rpm-build c487f7
    {
rpm-build c487f7
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "URL not specified");
rpm-build c487f7
      return NULL;
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  uri = soup_uri_new (self->url);
rpm-build c487f7
  if (uri == NULL)
rpm-build c487f7
    {
rpm-build c487f7
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid URL '%s'", self->url);
rpm-build c487f7
      return NULL;
rpm-build c487f7
    }
rpm-build c487f7
  return uri;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static GFile *
rpm-build c487f7
get_download_location (BuilderSourceFile *self,
rpm-build c487f7
                       gboolean          *is_inline,
rpm-build c487f7
                       BuilderContext    *context,
rpm-build c487f7
                       GError           **error)
rpm-build c487f7
{
rpm-build c487f7
  g_autoptr(SoupURI) uri = NULL;
rpm-build c487f7
  const char *path;
rpm-build c487f7
  g_autofree char *base_name = NULL;
rpm-build c487f7
  g_autoptr(GFile) file = NULL;
rpm-build c487f7
  const char *checksums[BUILDER_CHECKSUMS_LEN];
rpm-build c487f7
  GChecksumType checksums_type[BUILDER_CHECKSUMS_LEN];
rpm-build c487f7
rpm-build c487f7
  uri = get_uri (self, error);
rpm-build c487f7
  if (uri == NULL)
rpm-build c487f7
    return FALSE;
rpm-build c487f7
rpm-build c487f7
  path = soup_uri_get_path (uri);
rpm-build c487f7
rpm-build c487f7
  if (g_str_has_prefix (self->url, "data:"))
rpm-build c487f7
    {
rpm-build c487f7
      *is_inline = TRUE;
rpm-build c487f7
      return g_file_new_for_path ("inline data");
rpm-build c487f7
    }
rpm-build c487f7
  *is_inline = FALSE;
rpm-build c487f7
rpm-build c487f7
  base_name = g_path_get_basename (path);
rpm-build c487f7
rpm-build c487f7
  builder_get_all_checksums (checksums, checksums_type,
rpm-build c487f7
                             self->md5,
rpm-build c487f7
                             self->sha1,
rpm-build c487f7
                             self->sha256,
rpm-build c487f7
                             self->sha512);
rpm-build c487f7
rpm-build c487f7
  if (checksums[0] == NULL)
rpm-build c487f7
    {
rpm-build c487f7
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No checksum specified for file source %s", base_name);
rpm-build c487f7
      return FALSE;
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  file = builder_context_find_in_sources_dirs (context,
rpm-build c487f7
                                               "downloads",
rpm-build c487f7
                                               checksums[0],
rpm-build c487f7
                                               base_name,
rpm-build c487f7
                                               NULL);
rpm-build c487f7
  if (file != NULL)
rpm-build c487f7
    return g_steal_pointer (&file;;
rpm-build c487f7
rpm-build c487f7
  file = flatpak_build_file (builder_context_get_download_dir (context),
rpm-build c487f7
                             checksums[0],
rpm-build c487f7
                             base_name,
rpm-build c487f7
                             NULL);
rpm-build c487f7
  return g_steal_pointer (&file;;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static GFile *
rpm-build c487f7
get_source_file (BuilderSourceFile *self,
rpm-build c487f7
                 BuilderContext    *context,
rpm-build c487f7
                 gboolean          *is_local,
rpm-build c487f7
                 gboolean          *is_inline,
rpm-build c487f7
                 GError           **error)
rpm-build c487f7
{
rpm-build c487f7
  GFile *base_dir = BUILDER_SOURCE (self)->base_dir;
rpm-build c487f7
rpm-build c487f7
  if (self->url != NULL && self->url[0] != 0)
rpm-build c487f7
    {
rpm-build c487f7
      *is_local = FALSE;
rpm-build c487f7
      return get_download_location (self, is_inline, context, error);
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  if (self->path != NULL && self->path[0] != 0)
rpm-build c487f7
    {
rpm-build c487f7
      *is_local = TRUE;
rpm-build c487f7
      *is_inline = FALSE;
rpm-build c487f7
      return g_file_resolve_relative_path (base_dir, self->path);
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "source file path or url not specified");
rpm-build c487f7
  return NULL;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static GBytes *
rpm-build c487f7
download_data_uri (const char     *url,
rpm-build c487f7
                   BuilderContext *context,
rpm-build c487f7
                   GError        **error)
rpm-build c487f7
{
rpm-build c487f7
  SoupSession *session;
rpm-build c487f7
rpm-build c487f7
  g_autoptr(SoupRequest) req = NULL;
rpm-build c487f7
  g_autoptr(GInputStream) input = NULL;
rpm-build c487f7
  g_autoptr(GOutputStream) out = NULL;
rpm-build c487f7
rpm-build c487f7
  session = builder_context_get_soup_session (context);
rpm-build c487f7
rpm-build c487f7
  req = soup_session_request (session, url, error);
rpm-build c487f7
  if (req == NULL)
rpm-build c487f7
    return NULL;
rpm-build c487f7
rpm-build c487f7
  input = soup_request_send (req, NULL, error);
rpm-build c487f7
  if (input == NULL)
rpm-build c487f7
    return NULL;
rpm-build c487f7
rpm-build c487f7
  out = g_memory_output_stream_new_resizable ();
rpm-build c487f7
  if (!g_output_stream_splice (out,
rpm-build c487f7
                               input,
rpm-build c487f7
                               G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET | G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE,
rpm-build c487f7
                               NULL,
rpm-build c487f7
                               error))
rpm-build c487f7
    return NULL;
rpm-build c487f7
rpm-build c487f7
  return g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (out));
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static gboolean
rpm-build c487f7
builder_source_file_show_deps (BuilderSource  *source,
rpm-build c487f7
                               GError        **error)
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (source);
rpm-build c487f7
rpm-build c487f7
  if (self->path && self->path[0] != 0)
rpm-build c487f7
    g_print ("%s\n", self->path);
rpm-build c487f7
rpm-build c487f7
  return TRUE;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static gboolean
rpm-build c487f7
builder_source_file_download (BuilderSource  *source,
rpm-build c487f7
                              gboolean        update_vcs,
rpm-build c487f7
                              BuilderContext *context,
rpm-build c487f7
                              GError        **error)
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (source);
rpm-build c487f7
rpm-build c487f7
  g_autoptr(GFile) file = NULL;
rpm-build c487f7
  gboolean is_local, is_inline;
rpm-build c487f7
  g_autofree char *base_name = NULL;
rpm-build c487f7
  const char *checksums[BUILDER_CHECKSUMS_LEN];
rpm-build c487f7
  GChecksumType checksums_type[BUILDER_CHECKSUMS_LEN];
rpm-build c487f7
rpm-build c487f7
  file = get_source_file (self, context, &is_local, &is_inline, error);
rpm-build c487f7
  if (file == NULL)
rpm-build c487f7
    return FALSE;
rpm-build c487f7
rpm-build c487f7
  base_name = g_file_get_basename (file);
rpm-build c487f7
rpm-build c487f7
  builder_get_all_checksums (checksums, checksums_type,
rpm-build c487f7
                             self->md5,
rpm-build c487f7
                             self->sha1,
rpm-build c487f7
                             self->sha256,
rpm-build c487f7
                             self->sha512);
rpm-build c487f7
rpm-build c487f7
  if (g_file_query_exists (file, NULL))
rpm-build c487f7
    {
rpm-build c487f7
      return !is_local || checksums[0] == NULL ||
rpm-build c487f7
             builder_verify_checksums (base_name, file,
rpm-build c487f7
                                       checksums, checksums_type,
rpm-build c487f7
                                       error);
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  if (is_inline)
rpm-build c487f7
    return TRUE;
rpm-build c487f7
rpm-build c487f7
  if (is_local)
rpm-build c487f7
    {
rpm-build c487f7
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Can't find file at %s", self->path);
rpm-build c487f7
      return FALSE;
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  if (checksums[0] == NULL)
rpm-build c487f7
    {
rpm-build c487f7
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No checksum specified for file source %s", base_name);
rpm-build c487f7
      return FALSE;
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  if (!builder_context_download_uri (context,
rpm-build c487f7
                                     self->url,
rpm-build c487f7
                                     (const char **)self->mirror_urls,
rpm-build c487f7
                                     file,
rpm-build c487f7
                                     checksums,
rpm-build c487f7
                                     checksums_type,
rpm-build c487f7
                                     error))
rpm-build c487f7
    return FALSE;
rpm-build c487f7
rpm-build c487f7
  return TRUE;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static gboolean
rpm-build c487f7
builder_source_file_extract (BuilderSource  *source,
rpm-build c487f7
                             GFile          *dest,
rpm-build c487f7
                             BuilderOptions *build_options,
rpm-build c487f7
                             BuilderContext *context,
rpm-build c487f7
                             GError        **error)
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (source);
rpm-build c487f7
rpm-build c487f7
  g_autoptr(GFile) src = NULL;
rpm-build c487f7
  g_autoptr(GFile) dest_file = NULL;
rpm-build c487f7
  g_autofree char *dest_filename = NULL;
rpm-build c487f7
  gboolean is_local, is_inline;
rpm-build c487f7
rpm-build c487f7
  src = get_source_file (self, context, &is_local, &is_inline, error);
rpm-build c487f7
  if (src == NULL)
rpm-build c487f7
    return FALSE;
rpm-build c487f7
rpm-build c487f7
  if (self->dest_filename)
rpm-build c487f7
    {
rpm-build c487f7
      dest_filename = g_strdup (self->dest_filename);
rpm-build c487f7
    }
rpm-build c487f7
  else
rpm-build c487f7
    {
rpm-build c487f7
      if (is_inline)
rpm-build c487f7
        {
rpm-build c487f7
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
rpm-build c487f7
                       "No dest-filename set for inline file data");
rpm-build c487f7
          return FALSE;
rpm-build c487f7
        }
rpm-build c487f7
      dest_filename = g_file_get_basename (src);
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  dest_file = g_file_get_child (dest, dest_filename);
rpm-build c487f7
rpm-build c487f7
  /* If the destination file exists, just delete it. We can encounter errors when
rpm-build c487f7
   * trying to overwrite files that are not writable.
rpm-build c487f7
   */
rpm-build c487f7
  if (g_file_query_exists (dest_file, NULL) && !g_file_delete (dest_file, NULL, error))
rpm-build c487f7
    return FALSE;
rpm-build c487f7
rpm-build c487f7
  if (is_inline)
rpm-build c487f7
    {
rpm-build c487f7
      g_autoptr(GBytes) content = NULL;
rpm-build c487f7
rpm-build c487f7
      content = download_data_uri (self->url,
rpm-build c487f7
                                   context,
rpm-build c487f7
                                   error);
rpm-build c487f7
      if (content == NULL)
rpm-build c487f7
        return FALSE;
rpm-build c487f7
rpm-build c487f7
      if (!g_file_set_contents (flatpak_file_get_path_cached (dest_file),
rpm-build c487f7
                                g_bytes_get_data (content, NULL),
rpm-build c487f7
                                g_bytes_get_size (content), error))
rpm-build c487f7
        return FALSE;
rpm-build c487f7
    }
rpm-build c487f7
  else
rpm-build c487f7
    {
rpm-build c487f7
      /* Make sure the target is gone, because g_file_copy does
rpm-build c487f7
         truncation on hardlinked destinations */
rpm-build c487f7
      (void)g_file_delete (dest_file, NULL, NULL);
rpm-build c487f7
rpm-build c487f7
      if (!g_file_copy (src, dest_file,
rpm-build c487f7
                        G_FILE_COPY_OVERWRITE,
rpm-build c487f7
                        NULL,
rpm-build c487f7
                        NULL, NULL,
rpm-build c487f7
                        error))
rpm-build c487f7
        return FALSE;
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  return TRUE;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static gboolean
rpm-build c487f7
builder_source_file_bundle (BuilderSource  *source,
rpm-build c487f7
                            BuilderContext *context,
rpm-build c487f7
                            GError        **error)
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (source);
rpm-build c487f7
rpm-build c487f7
  g_autoptr(GFile) file = NULL;
rpm-build c487f7
  g_autoptr(GFile) destination_file = NULL;
rpm-build c487f7
  g_autoptr(GFile) destination_dir = NULL;
rpm-build c487f7
  g_autofree char *file_name = NULL;
rpm-build c487f7
  gboolean is_local, is_inline;
rpm-build c487f7
  const char *checksums[BUILDER_CHECKSUMS_LEN];
rpm-build c487f7
  GChecksumType checksums_type[BUILDER_CHECKSUMS_LEN];
rpm-build c487f7
rpm-build c487f7
  file = get_source_file (self, context, &is_local, &is_inline, error);
rpm-build c487f7
  if (file == NULL)
rpm-build c487f7
    return FALSE;
rpm-build c487f7
rpm-build c487f7
  /* Inline URIs (data://) need not be bundled */
rpm-build c487f7
  if (is_inline)
rpm-build c487f7
    return TRUE;
rpm-build c487f7
rpm-build c487f7
  builder_get_all_checksums (checksums, checksums_type,
rpm-build c487f7
                             self->md5,
rpm-build c487f7
                             self->sha1,
rpm-build c487f7
                             self->sha256,
rpm-build c487f7
                             self->sha512);
rpm-build c487f7
rpm-build c487f7
  if (is_local)
rpm-build c487f7
    {
rpm-build c487f7
      GFile *manifest_base_dir = builder_context_get_base_dir (context);
rpm-build c487f7
      g_autofree char *rel_path = g_file_get_relative_path (manifest_base_dir, file);
rpm-build c487f7
rpm-build c487f7
      if (rel_path == NULL)
rpm-build c487f7
        {
rpm-build c487f7
          g_warning ("Local file %s is outside manifest tree, not bundling", flatpak_file_get_path_cached (file));
rpm-build c487f7
          return TRUE;
rpm-build c487f7
        }
rpm-build c487f7
rpm-build c487f7
      destination_file = flatpak_build_file (builder_context_get_app_dir (context),
rpm-build c487f7
                                             "sources/manifest", rel_path, NULL);
rpm-build c487f7
    }
rpm-build c487f7
  else
rpm-build c487f7
    {
rpm-build c487f7
      file_name = g_file_get_basename (file);
rpm-build c487f7
      destination_file = flatpak_build_file (builder_context_get_app_dir (context),
rpm-build c487f7
                                             "sources/downloads",
rpm-build c487f7
                                             checksums[0],
rpm-build c487f7
                                             file_name,
rpm-build c487f7
                                             NULL);
rpm-build c487f7
    }
rpm-build c487f7
rpm-build c487f7
  destination_dir = g_file_get_parent (destination_file);
rpm-build c487f7
  if (!flatpak_mkdir_p (destination_dir, NULL, error))
rpm-build c487f7
    return FALSE;
rpm-build c487f7
rpm-build c487f7
  if (!g_file_copy (file, destination_file,
rpm-build c487f7
                    G_FILE_COPY_OVERWRITE,
rpm-build c487f7
                    NULL,
rpm-build c487f7
                    NULL, NULL,
rpm-build c487f7
                    error))
rpm-build c487f7
    return FALSE;
rpm-build c487f7
rpm-build c487f7
  return TRUE;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static gboolean
rpm-build c487f7
builder_source_file_update (BuilderSource  *source,
rpm-build c487f7
                            BuilderContext *context,
rpm-build c487f7
                            GError        **error)
rpm-build c487f7
{
rpm-build c487f7
  return TRUE;
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static void
rpm-build c487f7
builder_source_file_checksum (BuilderSource  *source,
rpm-build c487f7
                              BuilderCache   *cache,
rpm-build c487f7
                              BuilderContext *context)
rpm-build c487f7
{
rpm-build c487f7
  BuilderSourceFile *self = BUILDER_SOURCE_FILE (source);
rpm-build c487f7
rpm-build c487f7
  g_autoptr(GFile) src = NULL;
rpm-build c487f7
  g_autofree char *data = NULL;
rpm-build c487f7
  gsize len;
rpm-build c487f7
  gboolean is_local, is_inline;
rpm-build c487f7
rpm-build c487f7
  src = get_source_file (self, context, &is_local, &is_inline, NULL);
rpm-build c487f7
  if (src == NULL)
rpm-build c487f7
    return;
rpm-build c487f7
rpm-build c487f7
  if (is_local &&
rpm-build c487f7
      g_file_load_contents (src, NULL, &data, &len, NULL, NULL))
rpm-build c487f7
    builder_cache_checksum_data (cache, (guchar *) data, len);
rpm-build c487f7
rpm-build c487f7
  builder_cache_checksum_str (cache, self->path);
rpm-build c487f7
  builder_cache_checksum_str (cache, self->url);
rpm-build c487f7
  builder_cache_checksum_str (cache, self->sha256);
rpm-build c487f7
  builder_cache_checksum_compat_str (cache, self->md5);
rpm-build c487f7
  builder_cache_checksum_compat_str (cache, self->sha1);
rpm-build c487f7
  builder_cache_checksum_compat_str (cache, self->sha512);
rpm-build c487f7
  builder_cache_checksum_str (cache, self->dest_filename);
rpm-build c487f7
  builder_cache_checksum_compat_strv (cache, self->mirror_urls);
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static void
rpm-build c487f7
builder_source_file_class_init (BuilderSourceFileClass *klass)
rpm-build c487f7
{
rpm-build c487f7
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
rpm-build c487f7
  BuilderSourceClass *source_class = BUILDER_SOURCE_CLASS (klass);
rpm-build c487f7
rpm-build c487f7
  object_class->finalize = builder_source_file_finalize;
rpm-build c487f7
  object_class->get_property = builder_source_file_get_property;
rpm-build c487f7
  object_class->set_property = builder_source_file_set_property;
rpm-build c487f7
rpm-build c487f7
  source_class->show_deps = builder_source_file_show_deps;
rpm-build c487f7
  source_class->download = builder_source_file_download;
rpm-build c487f7
  source_class->extract = builder_source_file_extract;
rpm-build c487f7
  source_class->bundle = builder_source_file_bundle;
rpm-build c487f7
  source_class->update = builder_source_file_update;
rpm-build c487f7
  source_class->checksum = builder_source_file_checksum;
rpm-build c487f7
rpm-build c487f7
  g_object_class_install_property (object_class,
rpm-build c487f7
                                   PROP_PATH,
rpm-build c487f7
                                   g_param_spec_string ("path",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        NULL,
rpm-build c487f7
                                                        G_PARAM_READWRITE));
rpm-build c487f7
  g_object_class_install_property (object_class,
rpm-build c487f7
                                   PROP_URL,
rpm-build c487f7
                                   g_param_spec_string ("url",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        NULL,
rpm-build c487f7
                                                        G_PARAM_READWRITE));
rpm-build c487f7
  g_object_class_install_property (object_class,
rpm-build c487f7
                                   PROP_MD5,
rpm-build c487f7
                                   g_param_spec_string ("md5",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        NULL,
rpm-build c487f7
                                                        G_PARAM_READWRITE));
rpm-build c487f7
  g_object_class_install_property (object_class,
rpm-build c487f7
                                   PROP_SHA1,
rpm-build c487f7
                                   g_param_spec_string ("sha1",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        NULL,
rpm-build c487f7
                                                        G_PARAM_READWRITE));
rpm-build c487f7
  g_object_class_install_property (object_class,
rpm-build c487f7
                                   PROP_SHA256,
rpm-build c487f7
                                   g_param_spec_string ("sha256",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        NULL,
rpm-build c487f7
                                                        G_PARAM_READWRITE));
rpm-build c487f7
  g_object_class_install_property (object_class,
rpm-build c487f7
                                   PROP_SHA512,
rpm-build c487f7
                                   g_param_spec_string ("sha512",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        NULL,
rpm-build c487f7
                                                        G_PARAM_READWRITE));
rpm-build c487f7
  g_object_class_install_property (object_class,
rpm-build c487f7
                                   PROP_DEST_FILENAME,
rpm-build c487f7
                                   g_param_spec_string ("dest-filename",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        "",
rpm-build c487f7
                                                        NULL,
rpm-build c487f7
                                                        G_PARAM_READWRITE));
rpm-build c487f7
  g_object_class_install_property (object_class,
rpm-build c487f7
                                   PROP_MIRROR_URLS,
rpm-build c487f7
                                   g_param_spec_boxed ("mirror-urls",
rpm-build c487f7
                                                       "",
rpm-build c487f7
                                                       "",
rpm-build c487f7
                                                       G_TYPE_STRV,
rpm-build c487f7
                                                       G_PARAM_READWRITE));
rpm-build c487f7
}
rpm-build c487f7
rpm-build c487f7
static void
rpm-build c487f7
builder_source_file_init (BuilderSourceFile *self)
rpm-build c487f7
{
rpm-build c487f7
}