Esempio n. 1
0
gboolean
_ostree_repo_write_ref (OstreeRepo    *self,
                        const char    *remote,
                        const char    *ref,
                        const char    *rev,
                        GCancellable  *cancellable,
                        GError       **error)
{
    gboolean ret = FALSE;
    glnx_fd_close int dfd = -1;

    if (remote == NULL)
    {
        if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE,
                             &dfd, error))
            goto out;
    }
    else
    {
        glnx_fd_close int refs_remotes_dfd = -1;

        if (!glnx_opendirat (self->repo_dir_fd, "refs/remotes", TRUE,
                             &refs_remotes_dfd, error))
            goto out;

        if (rev != NULL)
        {
            /* Ensure we have a dir for the remote */
            if (!glnx_shutil_mkdir_p_at (refs_remotes_dfd, remote, 0777, cancellable, error))
                goto out;
        }

        if (!glnx_opendirat (refs_remotes_dfd, remote, TRUE, &dfd, error))
            goto out;
    }

    if (rev == NULL)
    {
        if (unlinkat (dfd, ref, 0) != 0)
        {
            if (errno != ENOENT)
            {
                glnx_set_error_from_errno (error);
                goto out;
            }
        }
    }
    else
    {
        if (!write_checksum_file_at (self, dfd, ref, rev, cancellable, error))
            goto out;
    }

    if (!_ostree_repo_update_mtime (self, error))
        goto out;

    ret = TRUE;
out:
    return ret;
}
Esempio n. 2
0
gboolean
_ostree_repo_write_ref (OstreeRepo    *self,
                        const char    *remote,
                        const char    *ref,
                        const char    *rev,
                        GCancellable  *cancellable,
                        GError       **error)
{
  glnx_fd_close int dfd = -1;

  if (remote == NULL)
    {
      if (!glnx_opendirat (self->repo_dir_fd, "refs/heads", TRUE,
                           &dfd, error))
        {
          g_prefix_error (error, "Opening %s: ", "refs/heads");
          return FALSE;
        }
    }
  else
    {
      glnx_fd_close int refs_remotes_dfd = -1;

      if (!glnx_opendirat (self->repo_dir_fd, "refs/remotes", TRUE,
                           &refs_remotes_dfd, error))
        {
          g_prefix_error (error, "Opening %s: ", "refs/remotes");
          return FALSE;
        }

      if (rev != NULL)
        {
          /* Ensure we have a dir for the remote */
          if (!glnx_shutil_mkdir_p_at (refs_remotes_dfd, remote, 0777, cancellable, error))
            return FALSE;
        }

      dfd = glnx_opendirat_with_errno (refs_remotes_dfd, remote, TRUE);
      if (dfd < 0 && (errno != ENOENT || rev != NULL))
        return glnx_throw_errno_prefix (error, "Opening remotes/ dir %s", remote);
    }

  if (rev == NULL)
    {
      if (dfd >= 0)
        {
          if (unlinkat (dfd, ref, 0) != 0)
            {
              if (errno != ENOENT)
                return glnx_throw_errno (error);
            }
        }
    }
  else
    {
      if (!write_checksum_file_at (self, dfd, ref, rev, cancellable, error))
        return FALSE;
    }

  if (!_ostree_repo_update_mtime (self, error))
    return FALSE;

  return TRUE;
}