configfile: add piped config support - fixes #9012
Some checks failed
build / windows (push) Has been cancelled
build / other_os (push) Has been cancelled
build / mac_amd64 (push) Has been cancelled
build / mac_arm64 (push) Has been cancelled
build / linux (push) Has been cancelled
build / go1.24 (push) Has been cancelled
build / linux_386 (push) Has been cancelled
build / lint (push) Has been cancelled
build / android-all (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/386 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/amd64 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm/v6 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm/v7 (push) Has been cancelled
Build & Push Docker Images / Build Docker Image for linux/arm64 (push) Has been cancelled
Build & Push Docker Images / Merge & Push Final Docker Image (push) Has been cancelled

This commit is contained in:
Jonas Tingeborn
2025-12-06 07:31:20 +01:00
committed by dougal
parent b9586c3e03
commit 233fef5c4d
2 changed files with 39 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package configfile
import (
"fmt"
"io"
"os"
"path/filepath"
"runtime"
@@ -362,3 +363,39 @@ func TestConfigFileSaveSymlinkAbsolute(t *testing.T) {
testSymlink(t, link, target, resolvedTarget)
})
}
type pipedInput struct {
io.Reader
}
func (p *pipedInput) Read(b []byte) (int, error) {
return p.Reader.Read(b)
}
func (_ *pipedInput) Seek(_ int64, _ int) (int64, error) {
return 0, fmt.Errorf("Seek not supported")
}
func TestPipedConfig(t *testing.T) {
t.Run("DoesNotSupportSeeking", func(t *testing.T) {
r := &pipedInput{strings.NewReader("")}
_, err := r.Seek(0, io.SeekStart)
require.Error(t, err)
})
t.Run("IsSupported", func(t *testing.T) {
r := &pipedInput{strings.NewReader(configData)}
_, err := config.Decrypt(r)
require.NoError(t, err)
})
t.Run("PlainTextConfigIsNotConsumedByCryptCheck", func(t *testing.T) {
in := &pipedInput{strings.NewReader(configData)}
r, _ := config.Decrypt(in)
got, err := io.ReadAll(r)
require.NoError(t, err)
assert.Equal(t, configData, string(got))
})
}

View File

@@ -77,8 +77,9 @@ func Decrypt(b io.ReadSeeker) (io.Reader, error) {
if strings.HasPrefix(l, "RCLONE_ENCRYPT_V") {
return nil, errors.New("unsupported configuration encryption - update rclone for support")
}
// Restore non-seekable plain-text stream to its original state
if _, err := b.Seek(0, io.SeekStart); err != nil {
return nil, err
return io.MultiReader(strings.NewReader(l+"\n"), r), nil
}
return b, nil
}