mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
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
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:
@@ -2,6 +2,7 @@ package configfile
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -362,3 +363,39 @@ func TestConfigFileSaveSymlinkAbsolute(t *testing.T) {
|
|||||||
testSymlink(t, link, target, resolvedTarget)
|
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))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,8 +77,9 @@ func Decrypt(b io.ReadSeeker) (io.Reader, error) {
|
|||||||
if strings.HasPrefix(l, "RCLONE_ENCRYPT_V") {
|
if strings.HasPrefix(l, "RCLONE_ENCRYPT_V") {
|
||||||
return nil, errors.New("unsupported configuration encryption - update rclone for support")
|
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 {
|
if _, err := b.Seek(0, io.SeekStart); err != nil {
|
||||||
return nil, err
|
return io.MultiReader(strings.NewReader(l+"\n"), r), nil
|
||||||
}
|
}
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user