<commit_before>package s3

import (
	"bytes"
	"errors"
	"io"
	"strings"

	"github.com/minio/minio-go"

	"restic/backend"
	"restic/debug"
)

const connLimit = 10

// s3 is a backend which stores the data on an S3 endpoint.
type s3 struct {
	client     minio.CloudStorageClient
	connChan   chan struct{}
	bucketname string
	prefix     string
}

// Open opens the S3 backend at bucket and region. The bucket is created if it
// does not exist yet.
func Open(cfg Config) (backend.Backend, error) {
	debug.Log("s3.Open", "open, config %#v", cfg)

	client, err := minio.New(cfg.Endpoint, cfg.KeyID, cfg.Secret, cfg.UseHTTP)
	if err != nil {
		return nil, err
	}

	be := &s3{client: client, bucketname: cfg.Bucket, prefix: cfg.Prefix}
	be.createConnections()

	if err := client.BucketExists(cfg.Bucket); err != nil {
		debug.Log("s3.Open", "BucketExists(%v) returned err %v, trying to create the bucket", cfg.Bucket, err)

		// create new bucket with default ACL in default region
		err = client.MakeBucket(cfg.Bucket, "", "")

		if err != nil {
			return nil, err
		}
	}

	return be, nil
}

func (be *s3) s3path(t backend.Type, name string) string {
	var path string

	if be.prefix != "" {
		path = be.prefix + "/"
	}
	path += string(t)

	if t == backend.Config {
		return path
	}
	return path + "/" + name
}
<commit_msg>Fix restic s3 backend for new minio-go version<commit_after>package s3

import (
	"bytes"
	"errors"
	"io"
	"strings"

	"github.com/minio/minio-go"

	"restic/backend"
	"restic/debug"
)

const connLimit = 10

// s3 is a backend which stores the data on an S3 endpoint.
type s3 struct {
	client     *minio.Client
	connChan   chan struct{}
	bucketname string
	prefix     string
}

// Open opens the S3 backend at bucket and region. The bucket is created if it
// does not exist yet.
func Open(cfg Config) (backend.Backend, error) {
	debug.Log("s3.Open", "open, config %#v", cfg)

	client, err := minio.New(cfg.Endpoint, cfg.KeyID, cfg.Secret, cfg.UseHTTP)
	if err != nil {
		return nil, err
	}

	be := &s3{client: client, bucketname: cfg.Bucket, prefix: cfg.Prefix}
	be.createConnections()

	if err := client.BucketExists(cfg.Bucket); err != nil {
		debug.Log("s3.Open", "BucketExists(%v) returned err %v, trying to create the bucket", cfg.Bucket, err)

		// create new bucket with default ACL in default region
		err = client.MakeBucket(cfg.Bucket, "")

		if err != nil {
			return nil, err
		}
	}

	return be, nil
}

func (be *s3) s3path(t backend.Type, name string) string {
	var path string

	if be.prefix != "" {
		path = be.prefix + "/"
	}
	path += string(t)

	if t == backend.Config {
		return path
	}
	return path + "/" + name
}

{'fraction_non_alphanumeric': 0.13330815709969787, 'fraction_numerical': 0.00944108761329305, 'mean_word_length': 3.314332247557003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1977012', 'n_tokens_mistral': 985, 'n_tokens_neox': 936, 'n_words': 303}