예제 #1
0
static void
gegl_tile_backend_file_ensure_exist (GeglTileBackendFile *self)
{
  if (!self->exist)
    {
      GeglTileBackend *backend;
      self->exist = TRUE;

      backend = GEGL_TILE_BACKEND (self);

      GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "creating swapfile  %s", self->path);

      self->o = g_open (self->path, O_RDWR|O_CREAT, 0770);
      if (self->o == -1)
        g_warning ("%s: Could not open '%s': %s", G_STRFUNC, self->path, g_strerror (errno));

      self->next_pre_alloc = 256;  /* reserved space for header */
      self->total          = 256;  /* reserved space for header */
      self->foffset        = 0;
      gegl_buffer_header_init (&self->header,
                               backend->priv->tile_width,
                               backend->priv->tile_height,
                               backend->priv->px_size,
                               backend->priv->format
                               );
      gegl_tile_backend_file_write_header (self);
      self->foffset       = 256;
      fsync (self->o);
      self->i = dup (self->o);

      /*self->i = G_INPUT_STREAM (g_file_read (self->file, NULL, NULL));*/
      self->next_pre_alloc = 256;  /* reserved space for header */
      self->total          = 256;  /* reserved space for header */
      g_assert (self->i != -1);
      g_assert (self->o != -1);
    }
}
예제 #2
0
static void
gegl_tile_backend_file_ensure_exist (GeglTileBackendFile *self)
{
  if (!self->exist)
    {
      GeglTileBackend *backend;
#if HAVE_GIO
      GError *error = NULL;

      if (self->io)
        {
          g_print ("we already existed\n");
          return;
        }
#endif
      self->exist = TRUE;

      backend = GEGL_TILE_BACKEND (self);

      GEGL_NOTE (GEGL_DEBUG_TILE_BACKEND, "creating swapfile  %s", self->path);

#if HAVE_GIO
      self->o = G_OUTPUT_STREAM (g_file_replace (self->file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
      g_output_stream_flush (self->o, NULL, NULL);
      g_output_stream_close (self->o, NULL, NULL);

      self->io = G_IO_STREAM (g_file_open_readwrite (self->file, NULL, &error));
      if (error)
        {
          g_warning ("%s: %s", G_STRLOC, error->message);
          g_error_free (error);
          error = NULL;
        }
      self->o = g_io_stream_get_output_stream (self->io);
      self->i = g_io_stream_get_input_stream (self->io);

#else
      self->o = open (self->path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
#endif

      self->next_pre_alloc = 256;  /* reserved space for header */
      self->total          = 256;  /* reserved space for header */
#if HAVE_GIO
      g_assert(g_seekable_seek (G_SEEKABLE (self->o), 256, G_SEEK_SET, NULL, NULL));
#endif
      gegl_buffer_header_init (&self->header,
                               backend->priv->tile_width,
                               backend->priv->tile_height,
                               backend->priv->px_size,
                               backend->priv->format
                               );
      gegl_tile_backend_file_write_header (self);
#if HAVE_GIO
      g_output_stream_flush (self->o, NULL, NULL);
#else
      fsync (self->o);
      self->i = dup (self->o);
#endif

      /*self->i = G_INPUT_STREAM (g_file_read (self->file, NULL, NULL));*/
      self->next_pre_alloc = 256;  /* reserved space for header */
      self->total          = 256;  /* reserved space for header */
#if HAVE_GIO
      g_assert (self->io);
      g_assert (self->i);
      g_assert (self->o);
#else
      g_assert (self->i != -1);
      g_assert (self->o != -1);
#endif
    }
}