From f32bbbf6a370a399303e9e35248d889a0aa31daa Mon Sep 17 00:00:00 2001
From: Travis Ralston <travpc@gmail.com>
Date: Sun, 5 Mar 2023 19:11:24 -0700
Subject: [PATCH] Replace deprecated ioutil usage

---
 api/custom/federation.go                             |  4 ++--
 api/custom/media_attributes.go                       |  4 ++--
 api/r0/upload.go                                     | 11 +++++------
 api/unstable/info.go                                 |  4 ++--
 cluster/idgen.go                                     |  4 ++--
 cmd/compile_assets/main.go                           | 11 +++++++----
 cmd/export_synapse_for_import/main.go                |  3 +--
 cmd/gdpr_import/main.go                              |  6 ++++--
 cmd/plugin_antispam_ocr/main.go                      |  5 ++---
 common/assets/process.go                             | 12 ++++++------
 common/config/access.go                              |  9 ++++++---
 .../download_controller/download_controller.go       |  3 +--
 .../download_controller/download_resource_handler.go |  3 +--
 controllers/preview_controller/previewers/http.go    |  3 +--
 .../previewers/oembed_previewer.go                   |  7 ++++---
 .../thumbnail_controller/thumbnail_controller.go     |  4 ++--
 .../thumbnail_resource_handler.go                    |  9 +++++----
 controllers/upload_controller/upload_controller.go   |  9 ++++-----
 internal_cache/redis.go                              |  5 ++---
 matrix/client_server.go                              |  4 ++--
 matrix/federation.go                                 |  4 ++--
 pipline/upload_pipeline/pipeline.go                  |  3 +--
 pipline/upload_pipeline/step_buffer.go               |  3 +--
 pipline/upload_pipeline/step_limited.go              |  3 +--
 redis_cache/redis.go                                 |  3 +--
 storage/datastore/ds_file/file_store.go              |  3 +--
 storage/datastore/ds_s3/s3_store.go                  |  7 +++----
 thumbnailing/i/apng.go                               |  4 ++--
 thumbnailing/i/gif.go                                |  8 ++++----
 thumbnailing/i/jpegxl.go                             |  3 +--
 thumbnailing/i/jpg.go                                |  4 ++--
 thumbnailing/i/mp3.go                                |  7 ++++---
 thumbnailing/i/mp4.go                                |  3 +--
 thumbnailing/i/png.go                                |  4 ++--
 thumbnailing/i/svg.go                                |  3 +--
 thumbnailing/thumbnail.go                            |  5 ++---
 thumbnailing/u/framing.go                            |  6 +++---
 util/encoding.go                                     |  4 ++--
 util/stream_util/streams.go                          |  5 ++---
 39 files changed, 97 insertions(+), 105 deletions(-)

diff --git a/api/custom/federation.go b/api/custom/federation.go
index 84051d13..78458c61 100644
--- a/api/custom/federation.go
+++ b/api/custom/federation.go
@@ -2,7 +2,7 @@ package custom
 
 import (
 	"encoding/json"
-	"io/ioutil"
+	"io"
 	"net/http"
 
 	"github.com/getsentry/sentry-go"
@@ -41,7 +41,7 @@ func GetFederationInfo(r *http.Request, rctx rcontext.RequestContext, user _apim
 		return _responses.InternalServerError(err.Error())
 	}
 
-	c, err := ioutil.ReadAll(versionResponse.Body)
+	c, err := io.ReadAll(versionResponse.Body)
 	if err != nil {
 		rctx.Log.Error(err)
 		sentry.CaptureException(err)
diff --git a/api/custom/media_attributes.go b/api/custom/media_attributes.go
index b820ad16..5ed12724 100644
--- a/api/custom/media_attributes.go
+++ b/api/custom/media_attributes.go
@@ -3,7 +3,7 @@ package custom
 import (
 	"database/sql"
 	"encoding/json"
-	"io/ioutil"
+	"io"
 	"net/http"
 
 	"github.com/getsentry/sentry-go"
@@ -98,7 +98,7 @@ func SetAttributes(r *http.Request, rctx rcontext.RequestContext, user _apimeta.
 	}
 
 	defer stream_util.DumpAndCloseStream(r.Body)
-	b, err := ioutil.ReadAll(r.Body)
+	b, err := io.ReadAll(r.Body)
 	if err != nil {
 		rctx.Log.Error(err)
 		sentry.CaptureException(err)
diff --git a/api/r0/upload.go b/api/r0/upload.go
index 1db12249..245b15ee 100644
--- a/api/r0/upload.go
+++ b/api/r0/upload.go
@@ -7,7 +7,6 @@ import (
 	"github.com/turt2live/matrix-media-repo/util/stream_util"
 
 	"io"
-	"io/ioutil"
 	"net/http"
 	"path/filepath"
 
@@ -38,24 +37,24 @@ func UploadMedia(r *http.Request, rctx rcontext.RequestContext, user _apimeta.Us
 	}
 
 	if upload_controller.IsRequestTooLarge(r.ContentLength, r.Header.Get("Content-Length"), rctx) {
-		io.Copy(ioutil.Discard, r.Body) // Ditch the entire request
+		io.Copy(io.Discard, r.Body) // Ditch the entire request
 		return _responses.RequestTooLarge()
 	}
 
 	if upload_controller.IsRequestTooSmall(r.ContentLength, r.Header.Get("Content-Length"), rctx) {
-		io.Copy(ioutil.Discard, r.Body) // Ditch the entire request
+		io.Copy(io.Discard, r.Body) // Ditch the entire request
 		return _responses.RequestTooSmall()
 	}
 
 	inQuota, err := quota.IsUserWithinQuota(rctx, user.UserId)
 	if err != nil {
-		io.Copy(ioutil.Discard, r.Body) // Ditch the entire request
+		io.Copy(io.Discard, r.Body) // Ditch the entire request
 		rctx.Log.Error("Unexpected error checking quota: " + err.Error())
 		sentry.CaptureException(err)
 		return _responses.InternalServerError("Unexpected Error")
 	}
 	if !inQuota {
-		io.Copy(ioutil.Discard, r.Body) // Ditch the entire request
+		io.Copy(io.Discard, r.Body) // Ditch the entire request
 		return _responses.QuotaExceeded()
 	}
 
@@ -63,7 +62,7 @@ func UploadMedia(r *http.Request, rctx rcontext.RequestContext, user _apimeta.Us
 
 	media, err := upload_controller.UploadMedia(r.Body, contentLength, contentType, filename, user.UserId, r.Host, rctx)
 	if err != nil {
-		io.Copy(ioutil.Discard, r.Body) // Ditch the entire request
+		io.Copy(io.Discard, r.Body) // Ditch the entire request
 
 		if err == common.ErrMediaQuarantined {
 			return _responses.BadRequest("This file is not permitted on this server")
diff --git a/api/unstable/info.go b/api/unstable/info.go
index 3bdafb24..8ea40d51 100644
--- a/api/unstable/info.go
+++ b/api/unstable/info.go
@@ -3,7 +3,7 @@ package unstable
 import (
 	"bytes"
 	"database/sql"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"strconv"
 	"strings"
@@ -94,7 +94,7 @@ func MediaInfo(r *http.Request, rctx rcontext.RequestContext, user _apimeta.User
 	}
 	defer stream_util.DumpAndCloseStream(streamedMedia.Stream)
 
-	b, err := ioutil.ReadAll(streamedMedia.Stream)
+	b, err := io.ReadAll(streamedMedia.Stream)
 	if err != nil {
 		rctx.Log.Error("Unexpected error processing media: " + err.Error())
 		sentry.CaptureException(err)
diff --git a/cluster/idgen.go b/cluster/idgen.go
index e74c2e84..89050c44 100644
--- a/cluster/idgen.go
+++ b/cluster/idgen.go
@@ -3,7 +3,7 @@ package cluster
 import (
 	"errors"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"time"
 
@@ -29,7 +29,7 @@ func GetId() (string, error) {
 	}
 	defer stream_util.DumpAndCloseStream(res.Body)
 
-	contents, err := ioutil.ReadAll(res.Body)
+	contents, err := io.ReadAll(res.Body)
 	if err != nil {
 		return "", err
 	}
diff --git a/cmd/compile_assets/main.go b/cmd/compile_assets/main.go
index fb35d670..4cf8761c 100644
--- a/cmd/compile_assets/main.go
+++ b/cmd/compile_assets/main.go
@@ -6,7 +6,7 @@ import (
 	"encoding/hex"
 	"flag"
 	"fmt"
-	"io/ioutil"
+	"os"
 	"path"
 
 	"github.com/turt2live/matrix-media-repo/common/config"
@@ -44,7 +44,7 @@ func main() {
 		str += fmt.Sprintf("\t\"%s\": \"%s\",\n", f, b64)
 	}
 	str += "}\n"
-	err := ioutil.WriteFile(*outputFile, []byte(str), 0644)
+	err := os.WriteFile(*outputFile, []byte(str), 0644)
 	if err != nil {
 		panic(err)
 	}
@@ -54,15 +54,18 @@ func main() {
 
 func readDir(dir string, pathName string) map[string][]byte {
 	fileMap := make(map[string][]byte)
-	files, err := ioutil.ReadDir(dir)
+	files, err := os.ReadDir(dir)
 	if err != nil {
 		panic(err)
 	}
 	for _, f := range files {
+		if f.IsDir() {
+			continue
+		}
 		fname := path.Join(dir, f.Name())
 		fmt.Println("Reading ", fname)
 
-		b, err := ioutil.ReadFile(fname)
+		b, err := os.ReadFile(fname)
 		if err != nil {
 			panic(err)
 		}
diff --git a/cmd/export_synapse_for_import/main.go b/cmd/export_synapse_for_import/main.go
index 8b5e6546..c71b071b 100644
--- a/cmd/export_synapse_for_import/main.go
+++ b/cmd/export_synapse_for_import/main.go
@@ -5,7 +5,6 @@ import (
 	"flag"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"path"
 	"strconv"
@@ -127,7 +126,7 @@ func main() {
 		_ = f.Close()
 
 		temp := bytes.NewBuffer(d.Bytes())
-		sha256, err := stream_util.GetSha256HashOfStream(ioutil.NopCloser(temp))
+		sha256, err := stream_util.GetSha256HashOfStream(io.NopCloser(temp))
 		if err != nil {
 			logrus.Fatal(err)
 		}
diff --git a/cmd/gdpr_import/main.go b/cmd/gdpr_import/main.go
index d2685251..95cf08bd 100644
--- a/cmd/gdpr_import/main.go
+++ b/cmd/gdpr_import/main.go
@@ -2,7 +2,6 @@ package main
 
 import (
 	"flag"
-	"io/ioutil"
 	"os"
 	"path"
 	"time"
@@ -49,12 +48,15 @@ func main() {
 	runtime.RunStartupSequence()
 
 	logrus.Info("Discovering files...")
-	fileInfos, err := ioutil.ReadDir(*filesDir)
+	fileInfos, err := os.ReadDir(*filesDir)
 	if err != nil {
 		panic(err)
 	}
 	files := make([]string, 0)
 	for _, f := range fileInfos {
+		if f.IsDir() {
+			continue
+		}
 		files = append(files, path.Join(*filesDir, f.Name()))
 	}
 
diff --git a/cmd/plugin_antispam_ocr/main.go b/cmd/plugin_antispam_ocr/main.go
index 2edbb78c..5b073564 100644
--- a/cmd/plugin_antispam_ocr/main.go
+++ b/cmd/plugin_antispam_ocr/main.go
@@ -7,7 +7,6 @@ import (
 	"errors"
 	"fmt"
 	"image"
-	"io/ioutil"
 	"math"
 	"net/http"
 	"os"
@@ -103,7 +102,7 @@ func (a *AntispamOCR) CheckForSpam(b64 string, filename string, contentType stri
 	// 4. Adjust contrast to make text more obvious on the background.
 	// 5. Convert to grayscale, thus avoiding any colour issues with the OCR.
 	img = imaging.Fit(img, 512, 512, imaging.Lanczos)
-	img = imaging.Fill(img, img.Bounds().Max.X * 2, img.Bounds().Max.Y * 2, imaging.Top, imaging.Lanczos)
+	img = imaging.Fill(img, img.Bounds().Max.X*2, img.Bounds().Max.Y*2, imaging.Top, imaging.Lanczos)
 	img = imaging.Sharpen(img, 50)
 	img = imaging.AdjustContrast(img, 2)
 	img = imaging.Grayscale(img)
@@ -137,7 +136,7 @@ func (a *AntispamOCR) CheckForSpam(b64 string, filename string, contentType stri
 		a.logger.Error("non-fatal error checking spam: ", err)
 		return false, nil
 	}
-	contents, err := ioutil.ReadAll(res.Body)
+	contents, err := io.ReadAll(res.Body)
 	if err != nil {
 		return false, err
 	}
diff --git a/common/assets/process.go b/common/assets/process.go
index 29b06632..b154e59d 100644
--- a/common/assets/process.go
+++ b/common/assets/process.go
@@ -4,7 +4,7 @@ import (
 	"bytes"
 	"compress/gzip"
 	"encoding/hex"
-	"io/ioutil"
+	"io"
 	"os"
 	"path"
 	"path/filepath"
@@ -21,7 +21,7 @@ func SetupMigrations(givenMigrationsPath string) {
 	_, err := os.Stat(givenMigrationsPath)
 	exists := err == nil || !os.IsNotExist(err)
 	if !exists {
-		tempMigrations, err = ioutil.TempDir(os.TempDir(), "media-repo-migrations")
+		tempMigrations, err = os.MkdirTemp(os.TempDir(), "media-repo-migrations")
 		if err != nil {
 			panic(err)
 		}
@@ -38,7 +38,7 @@ func SetupTemplates(givenTemplatesPath string) {
 		_, err := os.Stat(givenTemplatesPath)
 		exists := err == nil || !os.IsNotExist(err)
 		if !exists {
-			tempTemplates, err = ioutil.TempDir(os.TempDir(), "media-repo-templates")
+			tempTemplates, err = os.MkdirTemp(os.TempDir(), "media-repo-templates")
 			if err != nil {
 				panic(err)
 			}
@@ -55,7 +55,7 @@ func SetupAssets(givenAssetsPath string) {
 	_, err := os.Stat(givenAssetsPath)
 	exists := err == nil || !os.IsNotExist(err)
 	if !exists {
-		tempAssets, err := ioutil.TempDir(os.TempDir(), "media-repo-assets")
+		tempAssets, err := os.MkdirTemp(os.TempDir(), "media-repo-assets")
 		if err != nil {
 			panic(err)
 		}
@@ -97,14 +97,14 @@ func extractPrefixTo(pathName string, destination string) {
 		}
 		//noinspection GoDeferInLoop,GoUnhandledErrorResult
 		defer gr.Close()
-		uncompressedBytes, err := ioutil.ReadAll(gr)
+		uncompressedBytes, err := io.ReadAll(gr)
 		if err != nil {
 			panic(err)
 		}
 
 		dest := path.Join(destination, filepath.Base(f))
 		logrus.Infof("Writing %s to %s", f, dest)
-		err = ioutil.WriteFile(dest, uncompressedBytes, 0644)
+		err = os.WriteFile(dest, uncompressedBytes, 0644)
 		if err != nil {
 			panic(err)
 		}
diff --git a/common/config/access.go b/common/config/access.go
index 06f0e656..047a766d 100644
--- a/common/config/access.go
+++ b/common/config/access.go
@@ -2,7 +2,7 @@ package config
 
 import (
 	"fmt"
-	"io/ioutil"
+	"io"
 	"os"
 	"path"
 	"sort"
@@ -69,12 +69,15 @@ func reloadConfig() (*MainRepoConfig, map[string]*DomainRepoConfig, error) {
 	if info.IsDir() {
 		logrus.Info("Config is a directory - loading all files over top of each other")
 
-		files, err := ioutil.ReadDir(Path)
+		files, err := os.ReadDir(Path)
 		if err != nil {
 			return nil, nil, err
 		}
 
 		for _, f := range files {
+			if f.IsDir() {
+				continue
+			}
 			pathsOrdered = append(pathsOrdered, path.Join(Path, f.Name()))
 		}
 
@@ -107,7 +110,7 @@ func reloadConfig() (*MainRepoConfig, map[string]*DomainRepoConfig, error) {
 		}
 		defer stream_util.DumpAndCloseStream(f)
 
-		buffer, err := ioutil.ReadAll(f)
+		buffer, err := io.ReadAll(f)
 		if err != nil {
 			return nil, nil, err
 		}
diff --git a/controllers/download_controller/download_controller.go b/controllers/download_controller/download_controller.go
index 3c70c715..5519d36d 100644
--- a/controllers/download_controller/download_controller.go
+++ b/controllers/download_controller/download_controller.go
@@ -6,7 +6,6 @@ import (
 	"errors"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"time"
 
 	"github.com/getsentry/sentry-go"
@@ -234,7 +233,7 @@ func FindMinimalMediaRecord(origin string, mediaId string, downloadRemote bool,
 		return nil, err
 	}
 	if cached != nil && cached.Contents != nil {
-		mediaStream = ioutil.NopCloser(cached.Contents)
+		mediaStream = io.NopCloser(cached.Contents)
 	} else {
 		mediaStream, err = datastore.DownloadStream(ctx, media.DatastoreId, media.Location)
 		if err != nil {
diff --git a/controllers/download_controller/download_resource_handler.go b/controllers/download_controller/download_resource_handler.go
index cb592c1c..b985f19a 100644
--- a/controllers/download_controller/download_resource_handler.go
+++ b/controllers/download_controller/download_resource_handler.go
@@ -3,7 +3,6 @@ package download_controller
 import (
 	"errors"
 	"io"
-	"io/ioutil"
 	"mime"
 	"strconv"
 	"sync"
@@ -194,7 +193,7 @@ func downloadResourceWorkFn(request *resource_handler.WorkRequest) (resp *worker
 	reader, writer := io.Pipe()
 	tr := io.TeeReader(downloaded.Contents, writer)
 
-	go persistFile(ioutil.NopCloser(tr), &workerDownloadResponse{})
+	go persistFile(io.NopCloser(tr), &workerDownloadResponse{})
 
 	ms := stream.NewMemStream()
 	defer ms.Close()
diff --git a/controllers/preview_controller/previewers/http.go b/controllers/preview_controller/previewers/http.go
index d20ae455..a7aed30e 100644
--- a/controllers/preview_controller/previewers/http.go
+++ b/controllers/preview_controller/previewers/http.go
@@ -5,7 +5,6 @@ import (
 	"crypto/tls"
 	"errors"
 	"io"
-	"io/ioutil"
 	"mime"
 	"net"
 	"net/http"
@@ -144,7 +143,7 @@ func downloadRawContent(urlPayload *preview_types.UrlPayload, supportedTypes []s
 		reader = io.LimitReader(resp.Body, ctx.Config.UrlPreviews.MaxPageSizeBytes)
 	}
 
-	bytes, err := ioutil.ReadAll(reader)
+	bytes, err := io.ReadAll(reader)
 	if err != nil {
 		return nil, "", "", "", err
 	}
diff --git a/controllers/preview_controller/previewers/oembed_previewer.go b/controllers/preview_controller/previewers/oembed_previewer.go
index 1093b33c..a5f13c6c 100644
--- a/controllers/preview_controller/previewers/oembed_previewer.go
+++ b/controllers/preview_controller/previewers/oembed_previewer.go
@@ -2,11 +2,12 @@ package previewers
 
 import (
 	"bytes"
-	"github.com/getsentry/sentry-go"
-	"io/ioutil"
 	"net/url"
+	"os"
 	"path"
 
+	"github.com/getsentry/sentry-go"
+
 	"github.com/dyatlov/go-oembed/oembed"
 	"github.com/k3a/html2text"
 	"github.com/prometheus/client_golang/prometheus"
@@ -26,7 +27,7 @@ func getOembed() *oembed.Oembed {
 
 	oembedInstance = oembed.NewOembed()
 
-	data, err := ioutil.ReadFile(path.Join(config.Runtime.AssetsPath, "providers.json"))
+	data, err := os.ReadFile(path.Join(config.Runtime.AssetsPath, "providers.json"))
 	if err != nil {
 		sentry.CaptureException(err)
 		logrus.Fatal(err)
diff --git a/controllers/thumbnail_controller/thumbnail_controller.go b/controllers/thumbnail_controller/thumbnail_controller.go
index 1898b994..12d9cf93 100644
--- a/controllers/thumbnail_controller/thumbnail_controller.go
+++ b/controllers/thumbnail_controller/thumbnail_controller.go
@@ -4,7 +4,7 @@ import (
 	"bytes"
 	"database/sql"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"time"
 
 	"github.com/getsentry/sentry-go"
@@ -148,7 +148,7 @@ func GetThumbnail(origin string, mediaId string, desiredWidth int, desiredHeight
 		if cached != nil && cached.Contents != nil {
 			return &types.StreamedThumbnail{
 				Thumbnail: thumbnail,
-				Stream:    ioutil.NopCloser(cached.Contents),
+				Stream:    io.NopCloser(cached.Contents),
 			}, nil
 		}
 
diff --git a/controllers/thumbnail_controller/thumbnail_resource_handler.go b/controllers/thumbnail_controller/thumbnail_resource_handler.go
index 029b8ea1..d7afe9f0 100644
--- a/controllers/thumbnail_controller/thumbnail_resource_handler.go
+++ b/controllers/thumbnail_controller/thumbnail_resource_handler.go
@@ -3,11 +3,12 @@ package thumbnail_controller
 import (
 	"bytes"
 	"fmt"
-	"github.com/getsentry/sentry-go"
-	"io/ioutil"
+	"io"
 	"strconv"
 	"sync"
 
+	"github.com/getsentry/sentry-go"
+
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/sirupsen/logrus"
 	"github.com/turt2live/matrix-media-repo/common"
@@ -192,7 +193,7 @@ func GenerateThumbnail(media *types.Media, width int, height int, method string,
 	}
 
 	defer thumbImg.Reader.Close()
-	b, err := ioutil.ReadAll(thumbImg.Reader)
+	b, err := io.ReadAll(thumbImg.Reader)
 	if err != nil {
 		return nil, err
 	}
@@ -201,7 +202,7 @@ func GenerateThumbnail(media *types.Media, width int, height int, method string,
 	if err != nil {
 		return nil, err
 	}
-	info, err := ds.UploadFile(ioutil.NopCloser(bytes.NewBuffer(b)), int64(len(b)), ctx)
+	info, err := ds.UploadFile(io.NopCloser(bytes.NewBuffer(b)), int64(len(b)), ctx)
 	if err != nil {
 		ctx.Log.Error("Unexpected error saving thumbnail: " + err.Error())
 		return nil, err
diff --git a/controllers/upload_controller/upload_controller.go b/controllers/upload_controller/upload_controller.go
index b4fb52dc..99c8c58e 100644
--- a/controllers/upload_controller/upload_controller.go
+++ b/controllers/upload_controller/upload_controller.go
@@ -2,7 +2,6 @@ package upload_controller
 
 import (
 	"io"
-	"io/ioutil"
 	"strconv"
 	"time"
 
@@ -98,12 +97,12 @@ func UploadMedia(contents io.ReadCloser, contentLength int64, contentType string
 
 	var data io.ReadCloser
 	if ctx.Config.Uploads.MaxSizeBytes > 0 {
-		data = ioutil.NopCloser(io.LimitReader(contents, ctx.Config.Uploads.MaxSizeBytes))
+		data = io.NopCloser(io.LimitReader(contents, ctx.Config.Uploads.MaxSizeBytes))
 	} else {
 		data = contents
 	}
 
-	dataBytes, err := ioutil.ReadAll(data)
+	dataBytes, err := io.ReadAll(data)
 	if err != nil {
 		return nil, err
 	}
@@ -184,7 +183,7 @@ func StoreDirect(f *AlreadyUploadedFile, contents io.ReadCloser, expectedSize in
 		}
 		ds = dsPicked
 
-		contentBytes, err = ioutil.ReadAll(contents)
+		contentBytes, err = io.ReadAll(contents)
 		if err != nil {
 			return nil, err
 		}
@@ -203,7 +202,7 @@ func StoreDirect(f *AlreadyUploadedFile, contents io.ReadCloser, expectedSize in
 		if err != nil {
 			return nil, err
 		}
-		contentBytes, err = ioutil.ReadAll(contents)
+		contentBytes, err = io.ReadAll(contents)
 		if err != nil {
 			return nil, err
 		}
diff --git a/internal_cache/redis.go b/internal_cache/redis.go
index aeb4c2c2..c83a8638 100644
--- a/internal_cache/redis.go
+++ b/internal_cache/redis.go
@@ -2,11 +2,10 @@ package internal_cache
 
 import (
 	"bytes"
-	"github.com/turt2live/matrix-media-repo/common/config"
 	"io"
-	"io/ioutil"
 
 	"github.com/prometheus/client_golang/prometheus"
+	"github.com/turt2live/matrix-media-repo/common/config"
 	"github.com/turt2live/matrix-media-repo/common/rcontext"
 	"github.com/turt2live/matrix-media-repo/metrics"
 	"github.com/turt2live/matrix-media-repo/redis_cache"
@@ -46,7 +45,7 @@ func (c *RedisCache) updateItemInCache(sha256hash string, fetchFn FetchFunction,
 			return nil, err
 		}
 		defer s.Close()
-		fb, err := ioutil.ReadAll(s)
+		fb, err := io.ReadAll(s)
 		if err != nil {
 			return nil, err
 		}
diff --git a/matrix/client_server.go b/matrix/client_server.go
index cf70d451..66a0d5d4 100644
--- a/matrix/client_server.go
+++ b/matrix/client_server.go
@@ -3,7 +3,7 @@ package matrix
 import (
 	"bytes"
 	"encoding/json"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"time"
 
@@ -50,7 +50,7 @@ func doRequest(ctx rcontext.RequestContext, method string, urlStr string, body i
 	}
 	defer stream_util.DumpAndCloseStream(res.Body)
 
-	contents, err := ioutil.ReadAll(res.Body)
+	contents, err := io.ReadAll(res.Body)
 	if err != nil {
 		return err
 	}
diff --git a/matrix/federation.go b/matrix/federation.go
index ed192faf..2810f642 100644
--- a/matrix/federation.go
+++ b/matrix/federation.go
@@ -5,7 +5,7 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"net"
 	"net/http"
 	"os"
@@ -104,7 +104,7 @@ func GetServerApiUrl(hostname string) (string, string, error) {
 	r, err := http.Get(fmt.Sprintf("https://%s/.well-known/matrix/server", h))
 	if err == nil && r.StatusCode == http.StatusOK {
 		// Try parsing .well-known
-		c, err2 := ioutil.ReadAll(r.Body)
+		c, err2 := io.ReadAll(r.Body)
 		if err2 == nil {
 			wk := &wellknownServerResponse{}
 			err3 := json.Unmarshal(c, wk)
diff --git a/pipline/upload_pipeline/pipeline.go b/pipline/upload_pipeline/pipeline.go
index 0d10ad02..6bd4e240 100644
--- a/pipline/upload_pipeline/pipeline.go
+++ b/pipline/upload_pipeline/pipeline.go
@@ -4,7 +4,6 @@ import (
 	"bytes"
 	"errors"
 	"io"
-	"io/ioutil"
 
 	"github.com/turt2live/matrix-media-repo/common/rcontext"
 	"github.com/turt2live/matrix-media-repo/types"
@@ -25,7 +24,7 @@ func UploadMedia(ctx rcontext.RequestContext, origin string, mediaId string, r i
 
 	// Create a utility function for getting at the buffer easily
 	stream := func() io.ReadCloser {
-		return ioutil.NopCloser(bytes.NewBuffer(b))
+		return io.NopCloser(bytes.NewBuffer(b))
 	}
 
 	// Step 3: Get a hash of the file
diff --git a/pipline/upload_pipeline/step_buffer.go b/pipline/upload_pipeline/step_buffer.go
index 5af2ea3c..858b9933 100644
--- a/pipline/upload_pipeline/step_buffer.go
+++ b/pipline/upload_pipeline/step_buffer.go
@@ -2,11 +2,10 @@ package upload_pipeline
 
 import (
 	"io"
-	"io/ioutil"
 
 	"github.com/turt2live/matrix-media-repo/common/rcontext"
 )
 
 func bufferStream(ctx rcontext.RequestContext, r io.ReadCloser) ([]byte, error) {
-	return ioutil.ReadAll(r)
+	return io.ReadAll(r)
 }
diff --git a/pipline/upload_pipeline/step_limited.go b/pipline/upload_pipeline/step_limited.go
index 4c0be6c9..a110e7a6 100644
--- a/pipline/upload_pipeline/step_limited.go
+++ b/pipline/upload_pipeline/step_limited.go
@@ -2,14 +2,13 @@ package upload_pipeline
 
 import (
 	"io"
-	"io/ioutil"
 
 	"github.com/turt2live/matrix-media-repo/common/rcontext"
 )
 
 func limitStreamLength(ctx rcontext.RequestContext, r io.ReadCloser) io.ReadCloser {
 	if ctx.Config.Uploads.MaxSizeBytes > 0 {
-		return ioutil.NopCloser(io.LimitReader(r, ctx.Config.Uploads.MaxSizeBytes))
+		return io.NopCloser(io.LimitReader(r, ctx.Config.Uploads.MaxSizeBytes))
 	} else {
 		return r
 	}
diff --git a/redis_cache/redis.go b/redis_cache/redis.go
index 93602181..dadbb879 100644
--- a/redis_cache/redis.go
+++ b/redis_cache/redis.go
@@ -5,7 +5,6 @@ import (
 	"context"
 	"errors"
 	"io"
-	"io/ioutil"
 	"time"
 
 	"github.com/go-redis/redis/v9"
@@ -51,7 +50,7 @@ func (c *RedisCache) Close() error {
 }
 
 func (c *RedisCache) SetStream(ctx rcontext.RequestContext, key string, s io.Reader) error {
-	b, err := ioutil.ReadAll(s)
+	b, err := io.ReadAll(s)
 	if err != nil {
 		return err
 	}
diff --git a/storage/datastore/ds_file/file_store.go b/storage/datastore/ds_file/file_store.go
index 74a5df07..fa587010 100644
--- a/storage/datastore/ds_file/file_store.go
+++ b/storage/datastore/ds_file/file_store.go
@@ -3,7 +3,6 @@ package ds_file
 import (
 	"errors"
 	"io"
-	"io/ioutil"
 	"os"
 	"path"
 
@@ -93,7 +92,7 @@ func PersistFileAtLocation(targetFile string, file io.ReadCloser, ctx rcontext.R
 	go func() {
 		defer wfile.Close()
 		ctx.Log.Info("Calculating hash of stream...")
-		hash, hashErr = stream_util.GetSha256HashOfStream(ioutil.NopCloser(tr))
+		hash, hashErr = stream_util.GetSha256HashOfStream(io.NopCloser(tr))
 		ctx.Log.Info("Hash of file is ", hash)
 		done <- true
 	}()
diff --git a/storage/datastore/ds_s3/s3_store.go b/storage/datastore/ds_s3/s3_store.go
index 511374ab..2bf84179 100644
--- a/storage/datastore/ds_s3/s3_store.go
+++ b/storage/datastore/ds_s3/s3_store.go
@@ -3,7 +3,6 @@ package ds_s3
 import (
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"strconv"
 	"strings"
@@ -154,7 +153,7 @@ func (s *s3Datastore) UploadFile(file io.ReadCloser, expectedLength int64, ctx r
 	go func() {
 		defer ws3.Close()
 		ctx.Log.Info("Calculating hash of stream...")
-		hash, hashErr = stream_util.GetSha256HashOfStream(ioutil.NopCloser(tr))
+		hash, hashErr = stream_util.GetSha256HashOfStream(io.NopCloser(tr))
 		ctx.Log.Info("Hash of file is ", hash)
 		done <- true
 	}()
@@ -164,9 +163,9 @@ func (s *s3Datastore) UploadFile(file io.ReadCloser, expectedLength int64, ctx r
 			if s.tempPath != "" {
 				ctx.Log.Info("Buffering file to temp path due to unknown file size")
 				var f *os.File
-				f, uploadErr = ioutil.TempFile(s.tempPath, "mr*")
+				f, uploadErr = os.CreateTemp(s.tempPath, "mr*")
 				if uploadErr != nil {
-					io.Copy(ioutil.Discard, rs3)
+					io.Copy(io.Discard, rs3)
 					done <- true
 					return
 				}
diff --git a/thumbnailing/i/apng.go b/thumbnailing/i/apng.go
index 8dcd1967..e2387325 100644
--- a/thumbnailing/i/apng.go
+++ b/thumbnailing/i/apng.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"image"
 	"image/draw"
-	"io/ioutil"
+	"io"
 
 	"github.com/kettek/apng"
 	"github.com/turt2live/matrix-media-repo/common/rcontext"
@@ -99,7 +99,7 @@ func (d apngGenerator) GenerateThumbnail(b []byte, contentType string, width int
 	return &m.Thumbnail{
 		ContentType: "image/png",
 		Animated:    true,
-		Reader:      ioutil.NopCloser(buf),
+		Reader:      io.NopCloser(buf),
 	}, nil
 }
 
diff --git a/thumbnailing/i/gif.go b/thumbnailing/i/gif.go
index f8638245..8b4d51fc 100644
--- a/thumbnailing/i/gif.go
+++ b/thumbnailing/i/gif.go
@@ -6,7 +6,7 @@ import (
 	"image"
 	"image/draw"
 	"image/gif"
-	"io/ioutil"
+	"io"
 	"math"
 
 	"github.com/disintegration/imaging"
@@ -83,9 +83,9 @@ func (d gifGenerator) GenerateThumbnail(b []byte, contentType string, width int,
 				return nil, errors.New("gif: error encoding still frame thumbnail: " + err.Error())
 			}
 			return &m.Thumbnail{
-				Animated: false,
+				Animated:    false,
 				ContentType: "image/png",
-				Reader: ioutil.NopCloser(buf),
+				Reader:      io.NopCloser(buf),
 			}, nil
 		}
 
@@ -116,7 +116,7 @@ func (d gifGenerator) GenerateThumbnail(b []byte, contentType string, width int,
 	return &m.Thumbnail{
 		ContentType: "image/gif",
 		Animated:    true,
-		Reader:      ioutil.NopCloser(buf),
+		Reader:      io.NopCloser(buf),
 	}, nil
 }
 
diff --git a/thumbnailing/i/jpegxl.go b/thumbnailing/i/jpegxl.go
index 9294cc58..412defcf 100644
--- a/thumbnailing/i/jpegxl.go
+++ b/thumbnailing/i/jpegxl.go
@@ -2,7 +2,6 @@ package i
 
 import (
 	"errors"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"path"
@@ -57,7 +56,7 @@ func (d jpegxlGenerator) GenerateThumbnail(b []byte, contentType string, width i
 		return nil, errors.New("jpegxl: error converting jpegxl file: " + err.Error())
 	}
 
-	b, err = ioutil.ReadFile(tempFile2)
+	b, err = os.ReadFile(tempFile2)
 	if err != nil {
 		return nil, errors.New("jpegxl: error reading temp png file: " + err.Error())
 	}
diff --git a/thumbnailing/i/jpg.go b/thumbnailing/i/jpg.go
index 2a022669..e1441817 100644
--- a/thumbnailing/i/jpg.go
+++ b/thumbnailing/i/jpg.go
@@ -4,7 +4,7 @@ import (
 	"bytes"
 	"errors"
 	_ "image/jpeg"
-	"io/ioutil"
+	"io"
 
 	"github.com/disintegration/imaging"
 	"github.com/turt2live/matrix-media-repo/common/rcontext"
@@ -62,7 +62,7 @@ func (d jpgGenerator) GenerateThumbnail(b []byte, contentType string, width int,
 	return &m.Thumbnail{
 		Animated:    false,
 		ContentType: "image/jpeg",
-		Reader:      ioutil.NopCloser(imgData),
+		Reader:      io.NopCloser(imgData),
 	}, nil
 }
 
diff --git a/thumbnailing/i/mp3.go b/thumbnailing/i/mp3.go
index 70f91204..616d0936 100644
--- a/thumbnailing/i/mp3.go
+++ b/thumbnailing/i/mp3.go
@@ -6,8 +6,9 @@ import (
 	"image"
 	"image/color"
 	"image/draw"
-	"io/ioutil"
+	"io"
 	"math"
+	"os"
 	"path"
 
 	"github.com/dhowden/tag"
@@ -116,7 +117,7 @@ func (d mp3Generator) GenerateFromStream(audio beep.StreamSeekCloser, format bee
 	r := image.Rect(dx, dy, ddx, ddy)
 
 	if artworkImg == nil {
-		i, _ := ioutil.ReadFile(path.Join(config.Runtime.AssetsPath, "default-artwork.png"))
+		i, _ := os.ReadFile(path.Join(config.Runtime.AssetsPath, "default-artwork.png"))
 		if i != nil {
 			tmp, _, _ := image.Decode(bytes.NewBuffer(i))
 			if tmp != nil {
@@ -196,7 +197,7 @@ func (d mp3Generator) GenerateFromStream(audio beep.StreamSeekCloser, format bee
 	return &m.Thumbnail{
 		Animated:    false,
 		ContentType: "image/png",
-		Reader:      ioutil.NopCloser(imgData),
+		Reader:      io.NopCloser(imgData),
 	}, nil
 }
 
diff --git a/thumbnailing/i/mp4.go b/thumbnailing/i/mp4.go
index e6cceb52..7f38541f 100644
--- a/thumbnailing/i/mp4.go
+++ b/thumbnailing/i/mp4.go
@@ -2,7 +2,6 @@ package i
 
 import (
 	"errors"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"path"
@@ -58,7 +57,7 @@ func (d mp4Generator) GenerateThumbnail(b []byte, contentType string, width int,
 		return nil, errors.New("mp4: error converting video file: " + err.Error())
 	}
 
-	b, err = ioutil.ReadFile(tempFile2)
+	b, err = os.ReadFile(tempFile2)
 	if err != nil {
 		return nil, errors.New("mp4: error reading temp png file: " + err.Error())
 	}
diff --git a/thumbnailing/i/png.go b/thumbnailing/i/png.go
index bb923068..1110baae 100644
--- a/thumbnailing/i/png.go
+++ b/thumbnailing/i/png.go
@@ -5,7 +5,7 @@ import (
 	"errors"
 	"image"
 	_ "image/png"
-	"io/ioutil"
+	"io"
 
 	"github.com/disintegration/imaging"
 	"github.com/turt2live/matrix-media-repo/common/rcontext"
@@ -59,7 +59,7 @@ func (d pngGenerator) GenerateThumbnailOf(src image.Image, width int, height int
 	return &m.Thumbnail{
 		Animated:    false,
 		ContentType: "image/png",
-		Reader:      ioutil.NopCloser(imgData),
+		Reader:      io.NopCloser(imgData),
 	}, nil
 }
 
diff --git a/thumbnailing/i/svg.go b/thumbnailing/i/svg.go
index 98b622ac..9cabb3e5 100644
--- a/thumbnailing/i/svg.go
+++ b/thumbnailing/i/svg.go
@@ -2,7 +2,6 @@ package i
 
 import (
 	"errors"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"path"
@@ -57,7 +56,7 @@ func (d svgGenerator) GenerateThumbnail(b []byte, contentType string, width int,
 		return nil, errors.New("svg: error converting svg file: " + err.Error())
 	}
 
-	b, err = ioutil.ReadFile(tempFile2)
+	b, err = os.ReadFile(tempFile2)
 	if err != nil {
 		return nil, errors.New("svg: error reading temp png file: " + err.Error())
 	}
diff --git a/thumbnailing/thumbnail.go b/thumbnailing/thumbnail.go
index 0897a209..a5686111 100644
--- a/thumbnailing/thumbnail.go
+++ b/thumbnailing/thumbnail.go
@@ -3,7 +3,6 @@ package thumbnailing
 import (
 	"errors"
 	"io"
-	"io/ioutil"
 	"reflect"
 
 	"github.com/turt2live/matrix-media-repo/common"
@@ -31,7 +30,7 @@ func GenerateThumbnail(imgStream io.ReadCloser, contentType string, width int, h
 	}
 
 	defer stream_util.DumpAndCloseStream(imgStream)
-	b, err := ioutil.ReadAll(imgStream)
+	b, err := io.ReadAll(imgStream)
 	if err != nil {
 		return nil, err
 	}
@@ -58,7 +57,7 @@ func GenerateThumbnail(imgStream io.ReadCloser, contentType string, width int, h
 
 func GetGenerator(imgStream io.ReadCloser, contentType string, animated bool) (i.Generator, error) {
 	defer stream_util.DumpAndCloseStream(imgStream)
-	b, err := ioutil.ReadAll(imgStream)
+	b, err := io.ReadAll(imgStream)
 	if err != nil {
 		return nil, err
 	}
diff --git a/thumbnailing/u/framing.go b/thumbnailing/u/framing.go
index c5102aa3..b69eef79 100644
--- a/thumbnailing/u/framing.go
+++ b/thumbnailing/u/framing.go
@@ -3,11 +3,11 @@ package u
 import (
 	"bytes"
 	"errors"
-	"github.com/getsentry/sentry-go"
 	"image"
-	"io/ioutil"
+	"io"
 
 	"github.com/disintegration/imaging"
+	"github.com/getsentry/sentry-go"
 	"github.com/sirupsen/logrus"
 	"github.com/turt2live/matrix-media-repo/util/util_exif"
 )
@@ -25,7 +25,7 @@ func MakeThumbnail(src image.Image, method string, width int, height int) (image
 }
 
 func IdentifyAndApplyOrientation(origBytes []byte, src image.Image) (image.Image, error) {
-	orientation, err := util_exif.GetExifOrientation(ioutil.NopCloser(bytes.NewBuffer(origBytes)))
+	orientation, err := util_exif.GetExifOrientation(io.NopCloser(bytes.NewBuffer(origBytes)))
 	if err != nil {
 		// assume no orientation if there was an error reading the exif header
 		logrus.Warn("Non-fatal error reading exif headers:", err.Error())
diff --git a/util/encoding.go b/util/encoding.go
index c841f295..81e346ba 100644
--- a/util/encoding.go
+++ b/util/encoding.go
@@ -1,7 +1,7 @@
 package util
 
 import (
-	"io/ioutil"
+	"io"
 	"strings"
 	"unicode/utf8"
 
@@ -37,7 +37,7 @@ func ToUtf8(text string, possibleContentType string) string {
 		return text // best we can do
 	}
 
-	converted, err := ioutil.ReadAll(r)
+	converted, err := io.ReadAll(r)
 	if err != nil {
 		return text // best we can do
 	}
diff --git a/util/stream_util/streams.go b/util/stream_util/streams.go
index 0717f8bb..d92b4600 100644
--- a/util/stream_util/streams.go
+++ b/util/stream_util/streams.go
@@ -7,7 +7,6 @@ import (
 	"errors"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"math"
 
 	"github.com/turt2live/matrix-media-repo/util/util_byte_seeker"
@@ -15,11 +14,11 @@ import (
 
 func BufferToStream(buf *bytes.Buffer) io.ReadCloser {
 	newBuf := bytes.NewReader(buf.Bytes())
-	return ioutil.NopCloser(newBuf)
+	return io.NopCloser(newBuf)
 }
 
 func BytesToStream(b []byte) io.ReadCloser {
-	return ioutil.NopCloser(bytes.NewBuffer(b))
+	return io.NopCloser(bytes.NewBuffer(b))
 }
 
 func CloneReader(input io.ReadCloser, numReaders int) []io.ReadCloser {
-- 
GitLab