build: update logging statements to make json log work - fixes #6038

This changes log statements from log to fs package, which is required for --use-json-log
to properly make log output in JSON format. The recently added custom linting rule,
handled by ruleguard via gocritic via golangci-lint, warns about these and suggests
the alternative. Fixing was therefore basically running "golangci-lint run --fix",
although some manual fixup of mainly imports are necessary following that.
This commit is contained in:
albertony 2024-08-18 16:58:35 +02:00 committed by Nick Craig-Wood
parent 88b0757288
commit bcdfad3c83
64 changed files with 333 additions and 357 deletions

View file

@ -10,7 +10,6 @@ import (
goflag "flag" goflag "flag"
"fmt" "fmt"
"io" "io"
"log"
"math/rand" "math/rand"
"os" "os"
"path" "path"
@ -93,7 +92,7 @@ func TestMain(m *testing.M) {
goflag.Parse() goflag.Parse()
var rc int var rc int
log.Printf("Running with the following params: \n remote: %v", remoteName) fs.Logf(nil, "Running with the following params: \n remote: %v", remoteName)
runInstance = newRun() runInstance = newRun()
rc = m.Run() rc = m.Run()
os.Exit(rc) os.Exit(rc)
@ -408,7 +407,7 @@ func TestInternalWrappedFsChangeNotSeen(t *testing.T) {
// update in the wrapped fs // update in the wrapped fs
originalSize, err := runInstance.size(t, rootFs, "data.bin") originalSize, err := runInstance.size(t, rootFs, "data.bin")
require.NoError(t, err) require.NoError(t, err)
log.Printf("original size: %v", originalSize) fs.Logf(nil, "original size: %v", originalSize)
o, err := cfs.UnWrap().NewObject(context.Background(), runInstance.encryptRemoteIfNeeded(t, "data.bin")) o, err := cfs.UnWrap().NewObject(context.Background(), runInstance.encryptRemoteIfNeeded(t, "data.bin"))
require.NoError(t, err) require.NoError(t, err)
@ -425,7 +424,7 @@ func TestInternalWrappedFsChangeNotSeen(t *testing.T) {
err = o.Update(context.Background(), bytes.NewReader(data2), objInfo) err = o.Update(context.Background(), bytes.NewReader(data2), objInfo)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, int64(len(data2)), o.Size()) require.Equal(t, int64(len(data2)), o.Size())
log.Printf("updated size: %v", len(data2)) fs.Logf(nil, "updated size: %v", len(data2))
// get a new instance from the cache // get a new instance from the cache
if runInstance.wrappedIsExternal { if runInstance.wrappedIsExternal {
@ -485,49 +484,49 @@ func TestInternalMoveWithNotify(t *testing.T) {
err = runInstance.retryBlock(func() error { err = runInstance.retryBlock(func() error {
li, err := runInstance.list(t, rootFs, "test") li, err := runInstance.list(t, rootFs, "test")
if err != nil { if err != nil {
log.Printf("err: %v", err) fs.Logf(nil, "err: %v", err)
return err return err
} }
if len(li) != 2 { if len(li) != 2 {
log.Printf("not expected listing /test: %v", li) fs.Logf(nil, "not expected listing /test: %v", li)
return fmt.Errorf("not expected listing /test: %v", li) return fmt.Errorf("not expected listing /test: %v", li)
} }
li, err = runInstance.list(t, rootFs, "test/one") li, err = runInstance.list(t, rootFs, "test/one")
if err != nil { if err != nil {
log.Printf("err: %v", err) fs.Logf(nil, "err: %v", err)
return err return err
} }
if len(li) != 0 { if len(li) != 0 {
log.Printf("not expected listing /test/one: %v", li) fs.Logf(nil, "not expected listing /test/one: %v", li)
return fmt.Errorf("not expected listing /test/one: %v", li) return fmt.Errorf("not expected listing /test/one: %v", li)
} }
li, err = runInstance.list(t, rootFs, "test/second") li, err = runInstance.list(t, rootFs, "test/second")
if err != nil { if err != nil {
log.Printf("err: %v", err) fs.Logf(nil, "err: %v", err)
return err return err
} }
if len(li) != 1 { if len(li) != 1 {
log.Printf("not expected listing /test/second: %v", li) fs.Logf(nil, "not expected listing /test/second: %v", li)
return fmt.Errorf("not expected listing /test/second: %v", li) return fmt.Errorf("not expected listing /test/second: %v", li)
} }
if fi, ok := li[0].(os.FileInfo); ok { if fi, ok := li[0].(os.FileInfo); ok {
if fi.Name() != "data.bin" { if fi.Name() != "data.bin" {
log.Printf("not expected name: %v", fi.Name()) fs.Logf(nil, "not expected name: %v", fi.Name())
return fmt.Errorf("not expected name: %v", fi.Name()) return fmt.Errorf("not expected name: %v", fi.Name())
} }
} else if di, ok := li[0].(fs.DirEntry); ok { } else if di, ok := li[0].(fs.DirEntry); ok {
if di.Remote() != "test/second/data.bin" { if di.Remote() != "test/second/data.bin" {
log.Printf("not expected remote: %v", di.Remote()) fs.Logf(nil, "not expected remote: %v", di.Remote())
return fmt.Errorf("not expected remote: %v", di.Remote()) return fmt.Errorf("not expected remote: %v", di.Remote())
} }
} else { } else {
log.Printf("unexpected listing: %v", li) fs.Logf(nil, "unexpected listing: %v", li)
return fmt.Errorf("unexpected listing: %v", li) return fmt.Errorf("unexpected listing: %v", li)
} }
log.Printf("complete listing: %v", li) fs.Logf(nil, "complete listing: %v", li)
return nil return nil
}, 12, time.Second*10) }, 12, time.Second*10)
require.NoError(t, err) require.NoError(t, err)
@ -577,43 +576,43 @@ func TestInternalNotifyCreatesEmptyParts(t *testing.T) {
err = runInstance.retryBlock(func() error { err = runInstance.retryBlock(func() error {
found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test"))) found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test")))
if !found { if !found {
log.Printf("not found /test") fs.Logf(nil, "not found /test")
return fmt.Errorf("not found /test") return fmt.Errorf("not found /test")
} }
found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test"), runInstance.encryptRemoteIfNeeded(t, "one"))) found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test"), runInstance.encryptRemoteIfNeeded(t, "one")))
if !found { if !found {
log.Printf("not found /test/one") fs.Logf(nil, "not found /test/one")
return fmt.Errorf("not found /test/one") return fmt.Errorf("not found /test/one")
} }
found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test"), runInstance.encryptRemoteIfNeeded(t, "one"), runInstance.encryptRemoteIfNeeded(t, "test2"))) found = boltDb.HasEntry(path.Join(cfs.Root(), runInstance.encryptRemoteIfNeeded(t, "test"), runInstance.encryptRemoteIfNeeded(t, "one"), runInstance.encryptRemoteIfNeeded(t, "test2")))
if !found { if !found {
log.Printf("not found /test/one/test2") fs.Logf(nil, "not found /test/one/test2")
return fmt.Errorf("not found /test/one/test2") return fmt.Errorf("not found /test/one/test2")
} }
li, err := runInstance.list(t, rootFs, "test/one") li, err := runInstance.list(t, rootFs, "test/one")
if err != nil { if err != nil {
log.Printf("err: %v", err) fs.Logf(nil, "err: %v", err)
return err return err
} }
if len(li) != 1 { if len(li) != 1 {
log.Printf("not expected listing /test/one: %v", li) fs.Logf(nil, "not expected listing /test/one: %v", li)
return fmt.Errorf("not expected listing /test/one: %v", li) return fmt.Errorf("not expected listing /test/one: %v", li)
} }
if fi, ok := li[0].(os.FileInfo); ok { if fi, ok := li[0].(os.FileInfo); ok {
if fi.Name() != "test2" { if fi.Name() != "test2" {
log.Printf("not expected name: %v", fi.Name()) fs.Logf(nil, "not expected name: %v", fi.Name())
return fmt.Errorf("not expected name: %v", fi.Name()) return fmt.Errorf("not expected name: %v", fi.Name())
} }
} else if di, ok := li[0].(fs.DirEntry); ok { } else if di, ok := li[0].(fs.DirEntry); ok {
if di.Remote() != "test/one/test2" { if di.Remote() != "test/one/test2" {
log.Printf("not expected remote: %v", di.Remote()) fs.Logf(nil, "not expected remote: %v", di.Remote())
return fmt.Errorf("not expected remote: %v", di.Remote()) return fmt.Errorf("not expected remote: %v", di.Remote())
} }
} else { } else {
log.Printf("unexpected listing: %v", li) fs.Logf(nil, "unexpected listing: %v", li)
return fmt.Errorf("unexpected listing: %v", li) return fmt.Errorf("unexpected listing: %v", li)
} }
log.Printf("complete listing /test/one/test2") fs.Logf(nil, "complete listing /test/one/test2")
return nil return nil
}, 12, time.Second*10) }, 12, time.Second*10)
require.NoError(t, err) require.NoError(t, err)
@ -771,24 +770,24 @@ func TestInternalBug2117(t *testing.T) {
di, err := runInstance.list(t, rootFs, "test/dir1/dir2") di, err := runInstance.list(t, rootFs, "test/dir1/dir2")
require.NoError(t, err) require.NoError(t, err)
log.Printf("len: %v", len(di)) fs.Logf(nil, "len: %v", len(di))
require.Len(t, di, 1) require.Len(t, di, 1)
time.Sleep(time.Second * 30) time.Sleep(time.Second * 30)
di, err = runInstance.list(t, rootFs, "test/dir1/dir2") di, err = runInstance.list(t, rootFs, "test/dir1/dir2")
require.NoError(t, err) require.NoError(t, err)
log.Printf("len: %v", len(di)) fs.Logf(nil, "len: %v", len(di))
require.Len(t, di, 1) require.Len(t, di, 1)
di, err = runInstance.list(t, rootFs, "test/dir1") di, err = runInstance.list(t, rootFs, "test/dir1")
require.NoError(t, err) require.NoError(t, err)
log.Printf("len: %v", len(di)) fs.Logf(nil, "len: %v", len(di))
require.Len(t, di, 4) require.Len(t, di, 4)
di, err = runInstance.list(t, rootFs, "test") di, err = runInstance.list(t, rootFs, "test")
require.NoError(t, err) require.NoError(t, err)
log.Printf("len: %v", len(di)) fs.Logf(nil, "len: %v", len(di))
require.Len(t, di, 4) require.Len(t, di, 4)
} }
@ -829,7 +828,7 @@ func newRun() *run {
} else { } else {
r.tmpUploadDir = uploadDir r.tmpUploadDir = uploadDir
} }
log.Printf("Temp Upload Dir: %v", r.tmpUploadDir) fs.Logf(nil, "Temp Upload Dir: %v", r.tmpUploadDir)
return r return r
} }

View file

@ -7,7 +7,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
@ -283,7 +282,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't save OAuth token: %w", err) return nil, fmt.Errorf("couldn't save OAuth token: %w", err)
} }
log.Printf("Automatically upgraded OAuth config.") fs.Logf(nil, "Automatically upgraded OAuth config.")
} }
oAuthClient, _, err := oauthutil.NewClient(ctx, name, m, oauthConfig) oAuthClient, _, err := oauthutil.NewClient(ctx, name, m, oauthConfig)
if err != nil { if err != nil {

View file

@ -29,7 +29,7 @@ func readCommits(from, to string) (logMap map[string]string, logs []string) {
cmd := exec.Command("git", "log", "--oneline", from+".."+to) cmd := exec.Command("git", "log", "--oneline", from+".."+to)
out, err := cmd.Output() out, err := cmd.Output()
if err != nil { if err != nil {
log.Fatalf("failed to run git log %s: %v", from+".."+to, err) log.Fatalf("failed to run git log %s: %v", from+".."+to, err) //nolint:gocritic // Don't include gocritic when running golangci-lint to avoid ruleguard suggesting fs. intead of log.
} }
logMap = map[string]string{} logMap = map[string]string{}
logs = []string{} logs = []string{}
@ -39,7 +39,7 @@ func readCommits(from, to string) (logMap map[string]string, logs []string) {
} }
match := logRe.FindSubmatch(line) match := logRe.FindSubmatch(line)
if match == nil { if match == nil {
log.Fatalf("failed to parse line: %q", line) log.Fatalf("failed to parse line: %q", line) //nolint:gocritic // Don't include gocritic when running golangci-lint to avoid ruleguard suggesting fs. intead of log.
} }
var hash, logMessage = string(match[1]), string(match[2]) var hash, logMessage = string(match[1]), string(match[2])
logMap[logMessage] = hash logMap[logMessage] = hash
@ -52,12 +52,12 @@ func main() {
flag.Parse() flag.Parse()
args := flag.Args() args := flag.Args()
if len(args) != 0 { if len(args) != 0 {
log.Fatalf("Syntax: %s", os.Args[0]) log.Fatalf("Syntax: %s", os.Args[0]) //nolint:gocritic // Don't include gocritic when running golangci-lint to avoid ruleguard suggesting fs. intead of log.
} }
// v1.54.0 // v1.54.0
versionBytes, err := os.ReadFile("VERSION") versionBytes, err := os.ReadFile("VERSION")
if err != nil { if err != nil {
log.Fatalf("Failed to read version: %v", err) log.Fatalf("Failed to read version: %v", err) //nolint:gocritic // Don't include gocritic when running golangci-lint to avoid ruleguard suggesting fs. intead of log.
} }
if versionBytes[0] == 'v' { if versionBytes[0] == 'v' {
versionBytes = versionBytes[1:] versionBytes = versionBytes[1:]
@ -65,7 +65,7 @@ func main() {
versionBytes = bytes.TrimSpace(versionBytes) versionBytes = bytes.TrimSpace(versionBytes)
semver := semver.New(string(versionBytes)) semver := semver.New(string(versionBytes))
stable := fmt.Sprintf("v%d.%d", semver.Major, semver.Minor-1) stable := fmt.Sprintf("v%d.%d", semver.Major, semver.Minor-1)
log.Printf("Finding commits in %v not in stable %s", semver, stable) log.Printf("Finding commits in %v not in stable %s", semver, stable) //nolint:gocritic // Don't include gocritic when running golangci-lint to avoid ruleguard suggesting fs. intead of log.
masterMap, masterLogs := readCommits(stable+".0", "master") masterMap, masterLogs := readCommits(stable+".0", "master")
stableMap, _ := readCommits(stable+".0", stable+"-stable") stableMap, _ := readCommits(stable+".0", stable+"-stable")
for _, logMessage := range masterLogs { for _, logMessage := range masterLogs {

View file

@ -10,7 +10,6 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
"log"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -232,7 +231,7 @@ func TestBisyncRemoteLocal(t *testing.T) {
t.Skip("path1 and path2 are the same remote") t.Skip("path1 and path2 are the same remote")
} }
_, remote, cleanup, err := fstest.RandomRemote() _, remote, cleanup, err := fstest.RandomRemote()
log.Printf("remote: %v", remote) fs.Logf(nil, "remote: %v", remote)
require.NoError(t, err) require.NoError(t, err)
defer cleanup() defer cleanup()
testBisync(t, remote, *argRemote2) testBisync(t, remote, *argRemote2)
@ -244,7 +243,7 @@ func TestBisyncLocalRemote(t *testing.T) {
t.Skip("path1 and path2 are the same remote") t.Skip("path1 and path2 are the same remote")
} }
_, remote, cleanup, err := fstest.RandomRemote() _, remote, cleanup, err := fstest.RandomRemote()
log.Printf("remote: %v", remote) fs.Logf(nil, "remote: %v", remote)
require.NoError(t, err) require.NoError(t, err)
defer cleanup() defer cleanup()
testBisync(t, *argRemote2, remote) testBisync(t, *argRemote2, remote)
@ -254,7 +253,7 @@ func TestBisyncLocalRemote(t *testing.T) {
// (useful for testing server-side copy/move) // (useful for testing server-side copy/move)
func TestBisyncRemoteRemote(t *testing.T) { func TestBisyncRemoteRemote(t *testing.T) {
_, remote, cleanup, err := fstest.RandomRemote() _, remote, cleanup, err := fstest.RandomRemote()
log.Printf("remote: %v", remote) fs.Logf(nil, "remote: %v", remote)
require.NoError(t, err) require.NoError(t, err)
defer cleanup() defer cleanup()
testBisync(t, remote, remote) testBisync(t, remote, remote)
@ -450,13 +449,13 @@ func (b *bisyncTest) runTestCase(ctx context.Context, t *testing.T, testCase str
for _, dir := range srcDirs { for _, dir := range srcDirs {
dirs = append(dirs, norm.NFC.String(dir.Remote())) dirs = append(dirs, norm.NFC.String(dir.Remote()))
} }
log.Printf("checking initFs %s", initFs) fs.Logf(nil, "checking initFs %s", initFs)
fstest.CheckListingWithPrecision(b.t, initFs, items, dirs, initFs.Precision()) fstest.CheckListingWithPrecision(b.t, initFs, items, dirs, initFs.Precision())
checkError(b.t, sync.CopyDir(ctxNoDsStore, b.fs1, initFs, true), "setting up path1") checkError(b.t, sync.CopyDir(ctxNoDsStore, b.fs1, initFs, true), "setting up path1")
log.Printf("checking Path1 %s", b.fs1) fs.Logf(nil, "checking Path1 %s", b.fs1)
fstest.CheckListingWithPrecision(b.t, b.fs1, items, dirs, b.fs1.Precision()) fstest.CheckListingWithPrecision(b.t, b.fs1, items, dirs, b.fs1.Precision())
checkError(b.t, sync.CopyDir(ctxNoDsStore, b.fs2, initFs, true), "setting up path2") checkError(b.t, sync.CopyDir(ctxNoDsStore, b.fs2, initFs, true), "setting up path2")
log.Printf("checking path2 %s", b.fs2) fs.Logf(nil, "checking path2 %s", b.fs2)
fstest.CheckListingWithPrecision(b.t, b.fs2, items, dirs, b.fs2.Precision()) fstest.CheckListingWithPrecision(b.t, b.fs2, items, dirs, b.fs2.Precision())
// Create log file // Create log file
@ -514,21 +513,21 @@ func (b *bisyncTest) runTestCase(ctx context.Context, t *testing.T, testCase str
require.NoError(b.t, err, "saving log file %s", savedLog) require.NoError(b.t, err, "saving log file %s", savedLog)
if b.golden && !b.stopped { if b.golden && !b.stopped {
log.Printf("Store results to golden directory") fs.Logf(nil, "Store results to golden directory")
b.storeGolden() b.storeGolden()
return return
} }
errorCount := 0 errorCount := 0
if b.noCompare { if b.noCompare {
log.Printf("Skip comparing results with golden directory") fs.Logf(nil, "Skip comparing results with golden directory")
errorCount = -2 errorCount = -2
} else { } else {
errorCount = b.compareResults() errorCount = b.compareResults()
} }
if b.noCleanup { if b.noCleanup {
log.Printf("Skip cleanup") fs.Logf(nil, "Skip cleanup")
} else { } else {
b.cleanupCase(ctx) b.cleanupCase(ctx)
} }
@ -1383,24 +1382,24 @@ func (b *bisyncTest) compareResults() int {
const divider = "----------------------------------------------------------" const divider = "----------------------------------------------------------"
if goldenNum != resultNum { if goldenNum != resultNum {
log.Print(divider) fs.Log(nil, divider)
log.Print(color(terminal.RedFg, "MISCOMPARE - Number of Golden and Results files do not match:")) fs.Log(nil, color(terminal.RedFg, "MISCOMPARE - Number of Golden and Results files do not match:"))
log.Printf(" Golden count: %d", goldenNum) fs.Logf(nil, " Golden count: %d", goldenNum)
log.Printf(" Result count: %d", resultNum) fs.Logf(nil, " Result count: %d", resultNum)
log.Printf(" Golden files: %s", strings.Join(goldenFiles, ", ")) fs.Logf(nil, " Golden files: %s", strings.Join(goldenFiles, ", "))
log.Printf(" Result files: %s", strings.Join(resultFiles, ", ")) fs.Logf(nil, " Result files: %s", strings.Join(resultFiles, ", "))
} }
for _, file := range goldenFiles { for _, file := range goldenFiles {
if !resultSet.Has(file) { if !resultSet.Has(file) {
errorCount++ errorCount++
log.Printf(" File found in Golden but not in Results: %s", file) fs.Logf(nil, " File found in Golden but not in Results: %s", file)
} }
} }
for _, file := range resultFiles { for _, file := range resultFiles {
if !goldenSet.Has(file) { if !goldenSet.Has(file) {
errorCount++ errorCount++
log.Printf(" File found in Results but not in Golden: %s", file) fs.Logf(nil, " File found in Results but not in Golden: %s", file)
} }
} }
@ -1433,15 +1432,15 @@ func (b *bisyncTest) compareResults() int {
text, err := difflib.GetUnifiedDiffString(diff) text, err := difflib.GetUnifiedDiffString(diff)
require.NoError(b.t, err, "diff failed") require.NoError(b.t, err, "diff failed")
log.Print(divider) fs.Log(nil, divider)
log.Printf(color(terminal.RedFg, "| MISCOMPARE -Golden vs +Results for %s"), file) fs.Logf(nil, color(terminal.RedFg, "| MISCOMPARE -Golden vs +Results for %s"), file)
for _, line := range strings.Split(strings.TrimSpace(text), "\n") { for _, line := range strings.Split(strings.TrimSpace(text), "\n") {
log.Printf("| %s", strings.TrimSpace(line)) fs.Logf(nil, "| %s", strings.TrimSpace(line))
} }
} }
if errorCount > 0 { if errorCount > 0 {
log.Print(divider) fs.Log(nil, divider)
} }
if errorCount == 0 && goldenNum != resultNum { if errorCount == 0 && goldenNum != resultNum {
return -1 return -1
@ -1464,7 +1463,7 @@ func (b *bisyncTest) storeGolden() {
continue continue
} }
if fileName == "backupdirs" { if fileName == "backupdirs" {
log.Printf("skipping: %v", fileName) fs.Logf(nil, "skipping: %v", fileName)
continue continue
} }
goldName := b.toGolden(fileName) goldName := b.toGolden(fileName)
@ -1489,7 +1488,7 @@ func (b *bisyncTest) storeGolden() {
continue continue
} }
if fileName == "backupdirs" { if fileName == "backupdirs" {
log.Printf("skipping: %v", fileName) fs.Logf(nil, "skipping: %v", fileName)
continue continue
} }
text := b.mangleResult(b.goldenDir, fileName, true) text := b.mangleResult(b.goldenDir, fileName, true)
@ -1849,7 +1848,7 @@ func fileType(fileName string) string {
// logPrintf prints a message to stdout and to the test log // logPrintf prints a message to stdout and to the test log
func (b *bisyncTest) logPrintf(text string, args ...interface{}) { func (b *bisyncTest) logPrintf(text string, args ...interface{}) {
line := fmt.Sprintf(text, args...) line := fmt.Sprintf(text, args...)
log.Print(line) fs.Log(nil, line)
if b.logFile != nil { if b.logFile != nil {
_, err := fmt.Fprintln(b.logFile, line) _, err := fmt.Fprintln(b.logFile, line)
require.NoError(b.t, err, "writing log file") require.NoError(b.t, err, "writing log file")

View file

@ -4,11 +4,11 @@ package cat
import ( import (
"context" "context"
"io" "io"
"log"
"os" "os"
"strings" "strings"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/config/flags"
"github.com/rclone/rclone/fs/operations" "github.com/rclone/rclone/fs/operations"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -79,7 +79,7 @@ files, use:
usedHead := head > 0 usedHead := head > 0
usedTail := tail > 0 usedTail := tail > 0
if usedHead && usedTail || usedHead && usedOffset || usedTail && usedOffset { if usedHead && usedTail || usedHead && usedOffset || usedTail && usedOffset {
log.Fatalf("Can only use one of --head, --tail or --offset with --count") fs.Fatalf(nil, "Can only use one of --head, --tail or --offset with --count")
} }
if head > 0 { if head > 0 {
offset = 0 offset = 0

View file

@ -10,7 +10,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"log"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -88,7 +87,7 @@ func NewFsFile(remote string) (fs.Fs, string) {
_, fsPath, err := fspath.SplitFs(remote) _, fsPath, err := fspath.SplitFs(remote)
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatalf("Failed to create file system for %q: %v", remote, err) fs.Fatalf(nil, "Failed to create file system for %q: %v", remote, err)
} }
f, err := cache.Get(context.Background(), remote) f, err := cache.Get(context.Background(), remote)
switch err { switch err {
@ -100,7 +99,7 @@ func NewFsFile(remote string) (fs.Fs, string) {
return f, "" return f, ""
default: default:
err = fs.CountError(err) err = fs.CountError(err)
log.Fatalf("Failed to create file system for %q: %v", remote, err) fs.Fatalf(nil, "Failed to create file system for %q: %v", remote, err)
} }
return nil, "" return nil, ""
} }
@ -116,13 +115,13 @@ func newFsFileAddFilter(remote string) (fs.Fs, string) {
if !fi.InActive() { if !fi.InActive() {
err := fmt.Errorf("can't limit to single files when using filters: %v", remote) err := fmt.Errorf("can't limit to single files when using filters: %v", remote)
err = fs.CountError(err) err = fs.CountError(err)
log.Fatal(err.Error()) fs.Fatal(nil, err.Error())
} }
// Limit transfers to this file // Limit transfers to this file
err := fi.AddFile(fileName) err := fi.AddFile(fileName)
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatalf("Failed to limit to single file %q: %v", remote, err) fs.Fatalf(nil, "Failed to limit to single file %q: %v", remote, err)
} }
} }
return f, fileName return f, fileName
@ -144,7 +143,7 @@ func newFsDir(remote string) fs.Fs {
f, err := cache.Get(context.Background(), remote) f, err := cache.Get(context.Background(), remote)
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatalf("Failed to create file system for %q: %v", remote, err) fs.Fatalf(nil, "Failed to create file system for %q: %v", remote, err)
} }
cache.Pin(f) // pin indefinitely since it was on the CLI cache.Pin(f) // pin indefinitely since it was on the CLI
return f return f
@ -186,24 +185,24 @@ func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs
var err error var err error
dstRemote, dstFileName, err = fspath.Split(dstRemote) dstRemote, dstFileName, err = fspath.Split(dstRemote)
if err != nil { if err != nil {
log.Fatalf("Parsing %q failed: %v", args[1], err) fs.Fatalf(nil, "Parsing %q failed: %v", args[1], err)
} }
if dstRemote == "" { if dstRemote == "" {
dstRemote = "." dstRemote = "."
} }
if dstFileName == "" { if dstFileName == "" {
log.Fatalf("%q is a directory", args[1]) fs.Fatalf(nil, "%q is a directory", args[1])
} }
} }
fdst, err := cache.Get(context.Background(), dstRemote) fdst, err := cache.Get(context.Background(), dstRemote)
switch err { switch err {
case fs.ErrorIsFile: case fs.ErrorIsFile:
_ = fs.CountError(err) _ = fs.CountError(err)
log.Fatalf("Source doesn't exist or is a directory and destination is a file") fs.Fatalf(nil, "Source doesn't exist or is a directory and destination is a file")
case nil: case nil:
default: default:
_ = fs.CountError(err) _ = fs.CountError(err)
log.Fatalf("Failed to create file system for destination %q: %v", dstRemote, err) fs.Fatalf(nil, "Failed to create file system for destination %q: %v", dstRemote, err)
} }
cache.Pin(fdst) // pin indefinitely since it was on the CLI cache.Pin(fdst) // pin indefinitely since it was on the CLI
return return
@ -213,13 +212,13 @@ func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs
func NewFsDstFile(args []string) (fdst fs.Fs, dstFileName string) { func NewFsDstFile(args []string) (fdst fs.Fs, dstFileName string) {
dstRemote, dstFileName, err := fspath.Split(args[0]) dstRemote, dstFileName, err := fspath.Split(args[0])
if err != nil { if err != nil {
log.Fatalf("Parsing %q failed: %v", args[0], err) fs.Fatalf(nil, "Parsing %q failed: %v", args[0], err)
} }
if dstRemote == "" { if dstRemote == "" {
dstRemote = "." dstRemote = "."
} }
if dstFileName == "" { if dstFileName == "" {
log.Fatalf("%q is a directory", args[0]) fs.Fatalf(nil, "%q is a directory", args[0])
} }
fdst = newFsDir(dstRemote) fdst = newFsDir(dstRemote)
return return
@ -328,9 +327,9 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
if cmdErr != nil { if cmdErr != nil {
nerrs := accounting.GlobalStats().GetErrors() nerrs := accounting.GlobalStats().GetErrors()
if nerrs <= 1 { if nerrs <= 1 {
log.Printf("Failed to %s: %v", cmd.Name(), cmdErr) fs.Logf(nil, "Failed to %s: %v", cmd.Name(), cmdErr)
} else { } else {
log.Printf("Failed to %s with %d errors: last error was: %v", cmd.Name(), nerrs, cmdErr) fs.Logf(nil, "Failed to %s with %d errors: last error was: %v", cmd.Name(), nerrs, cmdErr)
} }
} }
resolveExitCode(cmdErr) resolveExitCode(cmdErr)
@ -383,7 +382,7 @@ func initConfig() {
// Set the global options from the flags // Set the global options from the flags
err := fs.GlobalOptionsInit() err := fs.GlobalOptionsInit()
if err != nil { if err != nil {
log.Fatalf("Failed to initialise global options: %v", err) fs.Fatalf(nil, "Failed to initialise global options: %v", err)
} }
ctx := context.Background() ctx := context.Background()
@ -423,7 +422,7 @@ func initConfig() {
// Start the remote control server if configured // Start the remote control server if configured
_, err = rcserver.Start(ctx, &rc.Opt) _, err = rcserver.Start(ctx, &rc.Opt)
if err != nil { if err != nil {
log.Fatalf("Failed to start remote control: %v", err) fs.Fatalf(nil, "Failed to start remote control: %v", err)
} }
// Start the metrics server if configured // Start the metrics server if configured
@ -439,19 +438,19 @@ func initConfig() {
f, err := os.Create(*cpuProfile) f, err := os.Create(*cpuProfile)
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
err = pprof.StartCPUProfile(f) err = pprof.StartCPUProfile(f)
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
atexit.Register(func() { atexit.Register(func() {
pprof.StopCPUProfile() pprof.StopCPUProfile()
err := f.Close() err := f.Close()
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
}) })
} }
@ -463,17 +462,17 @@ func initConfig() {
f, err := os.Create(*memProfile) f, err := os.Create(*memProfile)
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
err = pprof.WriteHeapProfile(f) err = pprof.WriteHeapProfile(f)
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
err = f.Close() err = f.Close()
if err != nil { if err != nil {
err = fs.CountError(err) err = fs.CountError(err)
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
}) })
} }
@ -537,6 +536,6 @@ func Main() {
if strings.HasPrefix(err.Error(), "unknown command") && selfupdateEnabled { if strings.HasPrefix(err.Error(), "unknown command") && selfupdateEnabled {
Root.PrintErrf("You could use '%s selfupdate' to get latest features.\n\n", Root.CommandPath()) Root.PrintErrf("You could use '%s selfupdate' to get latest features.\n\n", Root.CommandPath())
} }
log.Fatalf("Fatal error: %v", err) fs.Fatalf(nil, "Fatal error: %v", err)
} }
} }

View file

@ -3,7 +3,7 @@ package dedupe
import ( import (
"context" "context"
"log" "fmt"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
@ -142,7 +142,7 @@ Or
if len(args) > 1 { if len(args) > 1 {
err := dedupeMode.Set(args[0]) err := dedupeMode.Set(args[0])
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
args = args[1:] args = args[1:]
} }

View file

@ -1,10 +1,11 @@
package genautocomplete package genautocomplete
import ( import (
"log" "fmt"
"os" "os"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -50,7 +51,7 @@ current shell.
if args[0] == "-" { if args[0] == "-" {
err := cmd.Root.GenBashCompletionV2(os.Stdout, false) err := cmd.Root.GenBashCompletionV2(os.Stdout, false)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
return return
} }
@ -58,7 +59,7 @@ current shell.
} }
err := cmd.Root.GenBashCompletionFileV2(out, false) err := cmd.Root.GenBashCompletionFileV2(out, false)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
}, },
} }

View file

@ -1,10 +1,11 @@
package genautocomplete package genautocomplete
import ( import (
"log" "fmt"
"os" "os"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -39,7 +40,7 @@ If output_file is "-", then the output will be written to stdout.
if args[0] == "-" { if args[0] == "-" {
err := cmd.Root.GenFishCompletion(os.Stdout, true) err := cmd.Root.GenFishCompletion(os.Stdout, true)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
return return
} }
@ -47,7 +48,7 @@ If output_file is "-", then the output will be written to stdout.
} }
err := cmd.Root.GenFishCompletionFile(out, true) err := cmd.Root.GenFishCompletionFile(out, true)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
}, },
} }

View file

@ -1,10 +1,11 @@
package genautocomplete package genautocomplete
import ( import (
"log" "fmt"
"os" "os"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -31,13 +32,13 @@ If output_file is "-" or missing, then the output will be written to stdout.
if len(args) == 0 || (len(args) > 0 && args[0] == "-") { if len(args) == 0 || (len(args) > 0 && args[0] == "-") {
err := cmd.Root.GenPowerShellCompletion(os.Stdout) err := cmd.Root.GenPowerShellCompletion(os.Stdout)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
return return
} }
err := cmd.Root.GenPowerShellCompletionFile(args[0]) err := cmd.Root.GenPowerShellCompletionFile(args[0])
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
}, },
} }

View file

@ -1,10 +1,11 @@
package genautocomplete package genautocomplete
import ( import (
"log" "fmt"
"os" "os"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -39,7 +40,7 @@ If output_file is "-", then the output will be written to stdout.
if args[0] == "-" { if args[0] == "-" {
err := cmd.Root.GenZshCompletion(os.Stdout) err := cmd.Root.GenZshCompletion(os.Stdout)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
return return
} }
@ -47,12 +48,12 @@ If output_file is "-", then the output will be written to stdout.
} }
outFile, err := os.Create(out) outFile, err := os.Create(out)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
defer func() { _ = outFile.Close() }() defer func() { _ = outFile.Close() }()
err = cmd.Root.GenZshCompletion(outFile) err = cmd.Root.GenZshCompletion(outFile)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
}, },
} }

View file

@ -4,7 +4,6 @@ package gendocs
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"log"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -14,6 +13,7 @@ import (
"time" "time"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/config/flags"
"github.com/rclone/rclone/lib/file" "github.com/rclone/rclone/lib/file"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -144,7 +144,7 @@ rclone.org website.`,
var buf bytes.Buffer var buf bytes.Buffer
err := frontmatterTemplate.Execute(&buf, data) err := frontmatterTemplate.Execute(&buf, data)
if err != nil { if err != nil {
log.Fatalf("Failed to render frontmatter template: %v", err) fs.Fatalf(nil, "Failed to render frontmatter template: %v", err)
} }
return buf.String() return buf.String()
} }

View file

@ -3,7 +3,6 @@ package cmd
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"os" "os"
"regexp" "regexp"
"sort" "sort"
@ -76,7 +75,7 @@ var helpFlags = &cobra.Command{
if len(args) > 0 { if len(args) > 0 {
re, err := filter.GlobStringToRegexp(args[0], false, true) re, err := filter.GlobStringToRegexp(args[0], false, true)
if err != nil { if err != nil {
log.Fatalf("Invalid flag filter: %v", err) fs.Fatalf(nil, "Invalid flag filter: %v", err)
} }
fs.Debugf(nil, "Flag filter: %s", re.String()) fs.Debugf(nil, "Flag filter: %s", re.String())
filterFlagsRe = re filterFlagsRe = re
@ -286,7 +285,7 @@ func quoteString(v interface{}) string {
func showBackend(name string) { func showBackend(name string) {
backend, err := fs.Find(name) backend, err := fs.Find(name)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
var standardOptions, advancedOptions fs.Options var standardOptions, advancedOptions fs.Options
done := map[string]struct{}{} done := map[string]struct{}{}

View file

@ -5,7 +5,6 @@ package mount2
import ( import (
"fmt" "fmt"
"log"
"runtime" "runtime"
"time" "time"
@ -150,7 +149,7 @@ func mountOptions(fsys *FS, f fs.Fs, opt *mountlib.Options) (mountOpts *fuse.Mou
opts = append(opts, "ro") opts = append(opts, "ro")
} }
if fsys.opt.WritebackCache { if fsys.opt.WritebackCache {
log.Printf("FIXME --write-back-cache not supported") fs.Printf(nil, "FIXME --write-back-cache not supported")
// FIXME opts = append(opts,fuse.WritebackCache()) // FIXME opts = append(opts,fuse.WritebackCache())
} }
// Some OS X only options // Some OS X only options

View file

@ -5,7 +5,6 @@ import (
"context" "context"
_ "embed" _ "embed"
"fmt" "fmt"
"log"
"os" "os"
"runtime" "runtime"
"strings" "strings"
@ -311,7 +310,7 @@ func NewMountCommand(commandName string, hidden bool, mount MountFn) *cobra.Comm
err = mnt.Wait() err = mnt.Wait()
} }
if err != nil { if err != nil {
log.Fatalf("Fatal error: %v", err) fs.Fatalf(nil, "Fatal error: %v", err)
} }
return return
} }
@ -339,7 +338,7 @@ func NewMountCommand(commandName string, hidden bool, mount MountFn) *cobra.Comm
atexit.Unregister(handle) atexit.Unregister(handle)
} }
if err != nil { if err != nil {
log.Fatalf("Fatal error: %v", err) fs.Fatalf(nil, "Fatal error: %v", err)
} }
}, },
} }

View file

@ -3,7 +3,6 @@ package mountlib
import ( import (
"context" "context"
"errors" "errors"
"log"
"sort" "sort"
"sync" "sync"
"time" "time"
@ -123,12 +122,12 @@ func mountRc(ctx context.Context, in rc.Params) (out rc.Params, err error) {
mnt := NewMountPoint(mountFn, mountPoint, fdst, &mountOpt, &vfsOpt) mnt := NewMountPoint(mountFn, mountPoint, fdst, &mountOpt, &vfsOpt)
_, err = mnt.Mount() _, err = mnt.Mount()
if err != nil { if err != nil {
log.Printf("mount FAILED: %v", err) fs.Logf(nil, "mount FAILED: %v", err)
return nil, err return nil, err
} }
go func() { go func() {
if err = mnt.Wait(); err != nil { if err = mnt.Wait(); err != nil {
log.Printf("unmount FAILED: %v", err) fs.Logf(nil, "unmount FAILED: %v", err)
return return
} }
mountMu.Lock() mountMu.Lock()

View file

@ -3,11 +3,11 @@ package rcat
import ( import (
"context" "context"
"log"
"os" "os"
"time" "time"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/config/flags"
"github.com/rclone/rclone/fs/operations" "github.com/rclone/rclone/fs/operations"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -64,7 +64,7 @@ destination which can use retries.`,
stat, _ := os.Stdin.Stat() stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) != 0 { if (stat.Mode() & os.ModeCharDevice) != 0 {
log.Fatalf("nothing to read from standard input (stdin).") fs.Fatalf(nil, "nothing to read from standard input (stdin).")
} }
fdst, dstFileName := cmd.NewFsDstFile(args) fdst, dstFileName := cmd.NewFsDstFile(args)

View file

@ -3,9 +3,9 @@ package rcd
import ( import (
"context" "context"
"log"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/rc" "github.com/rclone/rclone/fs/rc"
"github.com/rclone/rclone/fs/rc/rcflags" "github.com/rclone/rclone/fs/rc/rcflags"
"github.com/rclone/rclone/fs/rc/rcserver" "github.com/rclone/rclone/fs/rc/rcserver"
@ -39,7 +39,7 @@ See the [rc documentation](/rc/) for more info on the rc flags.
Run: func(command *cobra.Command, args []string) { Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(0, 1, command, args) cmd.CheckArgs(0, 1, command, args)
if rc.Opt.Enabled { if rc.Opt.Enabled {
log.Fatalf("Don't supply --rc flag when using rcd") fs.Fatalf(nil, "Don't supply --rc flag when using rcd")
} }
// Start the rc // Start the rc
@ -50,10 +50,10 @@ See the [rc documentation](/rc/) for more info on the rc flags.
s, err := rcserver.Start(context.Background(), &rc.Opt) s, err := rcserver.Start(context.Background(), &rc.Opt)
if err != nil { if err != nil {
log.Fatalf("Failed to start remote control: %v", err) fs.Fatalf(nil, "Failed to start remote control: %v", err)
} }
if s == nil { if s == nil {
log.Fatal("rc server not configured") fs.Fatal(nil, "rc server not configured")
} }
// Notify stopping on exit // Notify stopping on exit

View file

@ -14,7 +14,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"os" "os"
"os/exec" "os/exec"
@ -83,19 +82,19 @@ var cmdSelfUpdate = &cobra.Command{
} }
if Opt.Package != "zip" { if Opt.Package != "zip" {
if Opt.Package != "deb" && Opt.Package != "rpm" { if Opt.Package != "deb" && Opt.Package != "rpm" {
log.Fatalf("--package should be one of zip|deb|rpm") fs.Fatalf(nil, "--package should be one of zip|deb|rpm")
} }
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
log.Fatalf(".deb and .rpm packages are supported only on Linux") fs.Fatalf(nil, ".deb and .rpm packages are supported only on Linux")
} else if os.Geteuid() != 0 && !Opt.Check { } else if os.Geteuid() != 0 && !Opt.Check {
log.Fatalf(".deb and .rpm must be installed by root") fs.Fatalf(nil, ".deb and .rpm must be installed by root")
} }
if Opt.Output != "" && !Opt.Check { if Opt.Output != "" && !Opt.Check {
fmt.Println("Warning: --output is ignored with --package deb|rpm") fmt.Println("Warning: --output is ignored with --package deb|rpm")
} }
} }
if err := InstallUpdate(context.Background(), &Opt); err != nil { if err := InstallUpdate(context.Background(), &Opt); err != nil {
log.Fatalf("Error: %v", err) fs.Fatalf(nil, "Error: %v", err)
} }
}, },
} }

View file

@ -5,7 +5,6 @@ import (
"encoding/xml" "encoding/xml"
"errors" "errors"
"fmt" "fmt"
"log"
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
@ -360,7 +359,7 @@ func (o *object) FilePath() string {
// Returns the ObjectID for the object. This is used in various ContentDirectory actions. // Returns the ObjectID for the object. This is used in various ContentDirectory actions.
func (o object) ID() string { func (o object) ID() string {
if !path.IsAbs(o.Path) { if !path.IsAbs(o.Path) {
log.Panicf("Relative object path: %s", o.Path) fs.Panicf(nil, "Relative object path: %s", o.Path)
} }
if len(o.Path) == 1 { if len(o.Path) == 1 {
return "0" return "0"

View file

@ -5,7 +5,6 @@ import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"io" "io"
"log"
"net" "net"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -31,7 +30,7 @@ func makeDefaultFriendlyName() string {
func makeDeviceUUID(unique string) string { func makeDeviceUUID(unique string) string {
h := md5.New() h := md5.New()
if _, err := io.WriteString(h, unique); err != nil { if _, err := io.WriteString(h, unique); err != nil {
log.Panicf("makeDeviceUUID write failed: %s", err) fs.Panicf(nil, "makeDeviceUUID write failed: %s", err)
} }
buf := h.Sum(nil) buf := h.Sum(nil)
return upnp.FormatUUID(buf) return upnp.FormatUUID(buf)
@ -41,7 +40,7 @@ func makeDeviceUUID(unique string) string {
func listInterfaces() []net.Interface { func listInterfaces() []net.Interface {
ifs, err := net.Interfaces() ifs, err := net.Interfaces()
if err != nil { if err != nil {
log.Printf("list network interfaces: %v", err) fs.Logf(nil, "list network interfaces: %v", err)
return []net.Interface{} return []net.Interface{}
} }
@ -71,7 +70,7 @@ func didlLite(chardata string) string {
func mustMarshalXML(value interface{}) []byte { func mustMarshalXML(value interface{}) []byte {
ret, err := xml.MarshalIndent(value, "", " ") ret, err := xml.MarshalIndent(value, "", " ")
if err != nil { if err != nil {
log.Panicf("mustMarshalXML failed to marshal %v: %s", value, err) fs.Panicf(nil, "mustMarshalXML failed to marshal %v: %s", value, err)
} }
return ret return ret
} }

View file

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"os" "os"
"path" "path"
@ -92,7 +91,7 @@ control the stats printing.
cmd.Run(false, true, command, func() error { cmd.Run(false, true, command, func() error {
s, err := run(context.Background(), f, Opt) s, err := run(context.Background(), f, Opt)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
defer systemd.Notify()() defer systemd.Notify()()

View file

@ -6,11 +6,11 @@ import (
"crypto/rsa" "crypto/rsa"
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"log"
"strings" "strings"
"testing" "testing"
_ "github.com/rclone/rclone/backend/local" _ "github.com/rclone/rclone/backend/local"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config/configmap" "github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/obscure" "github.com/rclone/rclone/fs/config/obscure"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -149,11 +149,11 @@ func TestRun(t *testing.T) {
privateKey, privateKeyErr := rsa.GenerateKey(rand.Reader, 2048) privateKey, privateKeyErr := rsa.GenerateKey(rand.Reader, 2048)
if privateKeyErr != nil { if privateKeyErr != nil {
log.Fatal("error generating test private key " + privateKeyErr.Error()) fs.Fatal(nil, "error generating test private key "+privateKeyErr.Error())
} }
publicKey, publicKeyError := ssh.NewPublicKey(&privateKey.PublicKey) publicKey, publicKeyError := ssh.NewPublicKey(&privateKey.PublicKey)
if privateKeyErr != nil { if privateKeyErr != nil {
log.Fatal("error generating test public key " + publicKeyError.Error()) fs.Fatal(nil, "error generating test public key "+publicKeyError.Error())
} }
publicKeyString := base64.StdEncoding.EncodeToString(publicKey.Marshal()) publicKeyString := base64.StdEncoding.EncodeToString(publicKey.Marshal())

View file

@ -3,11 +3,11 @@
package cmd package cmd
import ( import (
"log"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/accounting" "github.com/rclone/rclone/fs/accounting"
) )
@ -17,7 +17,7 @@ func SigInfoHandler() {
signal.Notify(signals, syscall.SIGINFO) signal.Notify(signals, syscall.SIGINFO)
go func() { go func() {
for range signals { for range signals {
log.Printf("%v\n", accounting.GlobalStats()) fs.Printf(nil, "%v\n", accounting.GlobalStats())
} }
}() }()
} }

View file

@ -5,7 +5,6 @@ package info
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -25,7 +24,7 @@ func (r *results) checkBase32768() {
n := 0 n := 0
dir, err := os.MkdirTemp("", "rclone-base32768-files") dir, err := os.MkdirTemp("", "rclone-base32768-files")
if err != nil { if err != nil {
log.Printf("Failed to make temp dir: %v", err) fs.Logf(nil, "Failed to make temp dir: %v", err)
return return
} }
defer func() { defer func() {
@ -41,7 +40,7 @@ func (r *results) checkBase32768() {
fileName := filepath.Join(dir, fmt.Sprintf("%04d-%s.txt", n, out.String())) fileName := filepath.Join(dir, fmt.Sprintf("%04d-%s.txt", n, out.String()))
err = os.WriteFile(fileName, []byte(fileName), 0666) err = os.WriteFile(fileName, []byte(fileName), 0666)
if err != nil { if err != nil {
log.Printf("write %q failed: %v", fileName, err) fs.Logf(nil, "write %q failed: %v", fileName, err)
return return
} }
n++ n++
@ -50,7 +49,7 @@ func (r *results) checkBase32768() {
// Make a local fs // Make a local fs
fLocal, err := fs.NewFs(ctx, dir) fLocal, err := fs.NewFs(ctx, dir)
if err != nil { if err != nil {
log.Printf("Failed to make local fs: %v", err) fs.Logf(nil, "Failed to make local fs: %v", err)
return return
} }
@ -61,14 +60,14 @@ func (r *results) checkBase32768() {
s = fspath.JoinRootPath(s, testDir) s = fspath.JoinRootPath(s, testDir)
fRemote, err := fs.NewFs(ctx, s) fRemote, err := fs.NewFs(ctx, s)
if err != nil { if err != nil {
log.Printf("Failed to make remote fs: %v", err) fs.Logf(nil, "Failed to make remote fs: %v", err)
return return
} }
defer func() { defer func() {
err := operations.Purge(ctx, r.f, testDir) err := operations.Purge(ctx, r.f, testDir)
if err != nil { if err != nil {
log.Printf("Failed to purge test directory: %v", err) fs.Logf(nil, "Failed to purge test directory: %v", err)
return return
} }
}() }()
@ -76,7 +75,7 @@ func (r *results) checkBase32768() {
// Sync local to remote // Sync local to remote
err = sync.Sync(ctx, fRemote, fLocal, false) err = sync.Sync(ctx, fRemote, fLocal, false)
if err != nil { if err != nil {
log.Printf("Failed to sync remote fs: %v", err) fs.Logf(nil, "Failed to sync remote fs: %v", err)
return return
} }
@ -86,7 +85,7 @@ func (r *results) checkBase32768() {
Fsrc: fLocal, Fsrc: fLocal,
}) })
if err != nil { if err != nil {
log.Printf("Failed to check remote fs: %v", err) fs.Logf(nil, "Failed to check remote fs: %v", err)
return return
} }

View file

@ -10,7 +10,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"path" "path"
"regexp" "regexp"
@ -77,7 +76,7 @@ code for each one.
Run: func(command *cobra.Command, args []string) { Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1e6, command, args) cmd.CheckArgs(1, 1e6, command, args)
if !checkNormalization && !checkControl && !checkLength && !checkStreaming && !checkBase32768 && !all { if !checkNormalization && !checkControl && !checkLength && !checkStreaming && !checkBase32768 && !all {
log.Fatalf("no tests selected - select a test or use --all") fs.Fatalf(nil, "no tests selected - select a test or use --all")
} }
if all { if all {
checkNormalization = true checkNormalization = true
@ -93,7 +92,7 @@ code for each one.
fs.Infof(f, "Created temporary directory for test files: %s", tempDirPath) fs.Infof(f, "Created temporary directory for test files: %s", tempDirPath)
err := f.Mkdir(context.Background(), "") err := f.Mkdir(context.Background(), "")
if err != nil { if err != nil {
log.Fatalf("couldn't create temporary directory: %v", err) fs.Fatalf(nil, "couldn't create temporary directory: %v", err)
} }
cmd.Run(false, false, command, func() error { cmd.Run(false, false, command, func() error {

View file

@ -7,12 +7,12 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"sort" "sort"
"strconv" "strconv"
"github.com/rclone/rclone/cmd/test/info/internal" "github.com/rclone/rclone/cmd/test/info/internal"
"github.com/rclone/rclone/fs"
) )
func main() { func main() {
@ -24,21 +24,21 @@ func main() {
for _, fn := range args { for _, fn := range args {
f, err := os.Open(fn) f, err := os.Open(fn)
if err != nil { if err != nil {
log.Fatalf("Unable to open %q: %s", fn, err) fs.Fatalf(nil, "Unable to open %q: %s", fn, err)
} }
var remote internal.InfoReport var remote internal.InfoReport
dec := json.NewDecoder(f) dec := json.NewDecoder(f)
err = dec.Decode(&remote) err = dec.Decode(&remote)
if err != nil { if err != nil {
log.Fatalf("Unable to decode %q: %s", fn, err) fs.Fatalf(nil, "Unable to decode %q: %s", fn, err)
} }
if remote.ControlCharacters == nil { if remote.ControlCharacters == nil {
log.Printf("Skipping remote %s: no ControlCharacters", remote.Remote) fs.Logf(nil, "Skipping remote %s: no ControlCharacters", remote.Remote)
} else { } else {
remotes = append(remotes, remote) remotes = append(remotes, remote)
} }
if err := f.Close(); err != nil { if err := f.Close(); err != nil {
log.Fatalf("Closing %q failed: %s", fn, err) fs.Fatalf(nil, "Closing %q failed: %s", fn, err)
} }
} }
@ -117,11 +117,11 @@ func main() {
} else { } else {
f, err := os.Create(*fOut) f, err := os.Create(*fOut)
if err != nil { if err != nil {
log.Fatalf("Unable to create %q: %s", *fOut, err) fs.Fatalf(nil, "Unable to create %q: %s", *fOut, err)
} }
defer func() { defer func() {
if err := f.Close(); err != nil { if err := f.Close(); err != nil {
log.Fatalln("Error writing csv:", err) fs.Fatal(nil, fmt.Sprint("Error writing csv:", err))
} }
}() }()
writer = f writer = f
@ -130,9 +130,9 @@ func main() {
w := csv.NewWriter(writer) w := csv.NewWriter(writer)
err := w.WriteAll(records) err := w.WriteAll(records)
if err != nil { if err != nil {
log.Fatalln("Error writing csv:", err) fs.Fatal(nil, fmt.Sprint("Error writing csv:", err))
} else if err := w.Error(); err != nil { } else if err := w.Error(); err != nil {
log.Fatalln("Error writing csv:", err) fs.Fatal(nil, fmt.Sprint("Error writing csv:", err))
} }
} }

View file

@ -4,7 +4,6 @@ package makefiles
import ( import (
"io" "io"
"log"
"math" "math"
"math/rand" "math/rand"
"os" "os"
@ -117,7 +116,7 @@ var makefileCmd = &cobra.Command{
var size fs.SizeSuffix var size fs.SizeSuffix
err := size.Set(args[0]) err := size.Set(args[0])
if err != nil { if err != nil {
log.Fatalf("Failed to parse size %q: %v", args[0], err) fs.Fatalf(nil, "Failed to parse size %q: %v", args[0], err)
} }
start := time.Now() start := time.Now()
fs.Logf(nil, "Creating %d files of size %v.", len(args[1:]), size) fs.Logf(nil, "Creating %d files of size %v.", len(args[1:]), size)
@ -148,7 +147,7 @@ func commonInit() {
} }
randSource = rand.New(rand.NewSource(seed)) randSource = rand.New(rand.NewSource(seed))
if bool2int(zero)+bool2int(sparse)+bool2int(ascii)+bool2int(pattern)+bool2int(chargen) > 1 { if bool2int(zero)+bool2int(sparse)+bool2int(ascii)+bool2int(pattern)+bool2int(chargen) > 1 {
log.Fatal("Can only supply one of --zero, --sparse, --ascii, --pattern or --chargen") fs.Fatal(nil, "Can only supply one of --zero, --sparse, --ascii, --pattern or --chargen")
} }
switch { switch {
case zero, sparse: case zero, sparse:
@ -276,12 +275,12 @@ func (d *dir) list(path string, output []string) []string {
func writeFile(dir, name string, size int64) { func writeFile(dir, name string, size int64) {
err := file.MkdirAll(dir, 0777) err := file.MkdirAll(dir, 0777)
if err != nil { if err != nil {
log.Fatalf("Failed to make directory %q: %v", dir, err) fs.Fatalf(nil, "Failed to make directory %q: %v", dir, err)
} }
path := filepath.Join(dir, name) path := filepath.Join(dir, name)
fd, err := os.Create(path) fd, err := os.Create(path)
if err != nil { if err != nil {
log.Fatalf("Failed to open file %q: %v", path, err) fs.Fatalf(nil, "Failed to open file %q: %v", path, err)
} }
if sparse { if sparse {
err = fd.Truncate(size) err = fd.Truncate(size)
@ -289,11 +288,11 @@ func writeFile(dir, name string, size int64) {
_, err = io.CopyN(fd, source, size) _, err = io.CopyN(fd, source, size)
} }
if err != nil { if err != nil {
log.Fatalf("Failed to write %v bytes to file %q: %v", size, path, err) fs.Fatalf(nil, "Failed to write %v bytes to file %q: %v", size, path, err)
} }
err = fd.Close() err = fd.Close()
if err != nil { if err != nil {
log.Fatalf("Failed to close file %q: %v", path, err) fs.Fatalf(nil, "Failed to close file %q: %v", path, err)
} }
fs.Infof(path, "Written file size %v", fs.SizeSuffix(size)) fs.Infof(path, "Written file size %v", fs.SizeSuffix(size))
} }

View file

@ -6,7 +6,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"log"
"time" "time"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
@ -86,7 +85,7 @@ then add the ` + "`--localtime`" + ` flag.
func newFsDst(args []string) (f fs.Fs, remote string) { func newFsDst(args []string) (f fs.Fs, remote string) {
root, remote, err := fspath.Split(args[0]) root, remote, err := fspath.Split(args[0])
if err != nil { if err != nil {
log.Fatalf("Parsing %q failed: %v", args[0], err) fs.Fatalf(nil, "Parsing %q failed: %v", args[0], err)
} }
if root == "" { if root == "" {
root = "." root = "."

View file

@ -6,13 +6,13 @@
package cmdtest package cmdtest
import ( import (
"log"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
"github.com/rclone/rclone/fs"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -26,14 +26,14 @@ func TestMain(m *testing.M) {
// started by Go test => execute tests // started by Go test => execute tests
err := os.Setenv(rcloneTestMain, "true") err := os.Setenv(rcloneTestMain, "true")
if err != nil { if err != nil {
log.Fatalf("Unable to set %s: %s", rcloneTestMain, err.Error()) fs.Fatalf(nil, "Unable to set %s: %s", rcloneTestMain, err.Error())
} }
os.Exit(m.Run()) os.Exit(m.Run())
} else { } else {
// started by func rcloneExecMain => call rclone main in cmdtest.go // started by func rcloneExecMain => call rclone main in cmdtest.go
err := os.Unsetenv(rcloneTestMain) err := os.Unsetenv(rcloneTestMain)
if err != nil { if err != nil {
log.Fatalf("Unable to unset %s: %s", rcloneTestMain, err.Error()) fs.Fatalf(nil, "Unable to unset %s: %s", rcloneTestMain, err.Error())
} }
main() main()
} }
@ -47,7 +47,7 @@ const rcloneTestMain = "RCLONE_TEST_MAIN"
func rcloneExecMain(env string, args ...string) (string, error) { func rcloneExecMain(env string, args ...string) (string, error) {
_, found := os.LookupEnv(rcloneTestMain) _, found := os.LookupEnv(rcloneTestMain)
if !found { if !found {
log.Fatalf("Unexpected execution path: %s is missing.", rcloneTestMain) fs.Fatalf(nil, "Unexpected execution path: %s is missing.", rcloneTestMain)
} }
// make a call to self to execute rclone main in a predefined environment (enters TestMain above) // make a call to self to execute rclone main in a predefined environment (enters TestMain above)
command := exec.Command(os.Args[0], args...) command := exec.Command(os.Args[0], args...)

View file

@ -6,7 +6,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"log"
mathrand "math/rand" mathrand "math/rand"
"os" "os"
"path/filepath" "path/filepath"
@ -372,7 +371,7 @@ func LoadedData() Storage {
} }
dataLoaded = true dataLoaded = true
} else { } else {
log.Fatalf("Failed to load config file %q: %v", configPath, err) fs.Fatalf(nil, "Failed to load config file %q: %v", configPath, err)
} }
} }
return data return data

View file

@ -7,9 +7,9 @@ package config
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/lib/terminal" "github.com/rclone/rclone/lib/terminal"
) )
@ -22,7 +22,7 @@ func ReadPassword() string {
line, err := terminal.ReadPassword(stdin) line, err := terminal.ReadPassword(stdin)
_, _ = fmt.Fprintln(os.Stderr) _, _ = fmt.Fprintln(os.Stderr)
if err != nil { if err != nil {
log.Fatalf("Failed to read password: %v", err) fs.Fatalf(nil, "Failed to read password: %v", err)
} }
return string(line) return string(line)
} }

View file

@ -5,7 +5,6 @@ package configflags
// Options set by command line flags // Options set by command line flags
import ( import (
"context" "context"
"log"
"net" "net"
"os" "os"
"strconv" "strconv"
@ -68,7 +67,7 @@ func ParseHeaders(headers []string) []*fs.HTTPOption {
for _, header := range headers { for _, header := range headers {
parts := strings.SplitN(header, ":", 2) parts := strings.SplitN(header, ":", 2)
if len(parts) == 1 { if len(parts) == 1 {
log.Fatalf("Failed to parse '%s' as an HTTP header. Expecting a string like: 'Content-Encoding: gzip'", header) fs.Fatalf(nil, "Failed to parse '%s' as an HTTP header. Expecting a string like: 'Content-Encoding: gzip'", header)
} }
option := &fs.HTTPOption{ option := &fs.HTTPOption{
Key: strings.TrimSpace(parts[0]), Key: strings.TrimSpace(parts[0]),
@ -101,7 +100,7 @@ func SetFlags(ci *fs.ConfigInfo) {
// Process -q flag // Process -q flag
if quiet { if quiet {
if verbose > 0 { if verbose > 0 {
log.Fatalf("Can't set -v and -q") fs.Fatalf(nil, "Can't set -v and -q")
} }
ci.LogLevel = fs.LogLevelError ci.LogLevel = fs.LogLevelError
} }
@ -110,10 +109,10 @@ func SetFlags(ci *fs.ConfigInfo) {
logLevelFlag := pflag.Lookup("log-level") logLevelFlag := pflag.Lookup("log-level")
if logLevelFlag != nil && logLevelFlag.Changed { if logLevelFlag != nil && logLevelFlag.Changed {
if verbose > 0 { if verbose > 0 {
log.Fatalf("Can't set -v and --log-level") fs.Fatalf(nil, "Can't set -v and --log-level")
} }
if quiet { if quiet {
log.Fatalf("Can't set -q and --log-level") fs.Fatalf(nil, "Can't set -q and --log-level")
} }
} }
@ -121,7 +120,7 @@ func SetFlags(ci *fs.ConfigInfo) {
switch { switch {
case deleteBefore && (deleteDuring || deleteAfter), case deleteBefore && (deleteDuring || deleteAfter),
deleteDuring && deleteAfter: deleteDuring && deleteAfter:
log.Fatalf(`Only one of --delete-before, --delete-during or --delete-after can be used.`) fs.Fatalf(nil, `Only one of --delete-before, --delete-during or --delete-after can be used.`)
case deleteBefore: case deleteBefore:
ci.DeleteMode = fs.DeleteModeBefore ci.DeleteMode = fs.DeleteModeBefore
case deleteDuring: case deleteDuring:
@ -136,10 +135,10 @@ func SetFlags(ci *fs.ConfigInfo) {
if bindAddr != "" { if bindAddr != "" {
addrs, err := net.LookupIP(bindAddr) addrs, err := net.LookupIP(bindAddr)
if err != nil { if err != nil {
log.Fatalf("--bind: Failed to parse %q as IP address: %v", bindAddr, err) fs.Fatalf(nil, "--bind: Failed to parse %q as IP address: %v", bindAddr, err)
} }
if len(addrs) != 1 { if len(addrs) != 1 {
log.Fatalf("--bind: Expecting 1 IP address for %q but got %d", bindAddr, len(addrs)) fs.Fatalf(nil, "--bind: Expecting 1 IP address for %q but got %d", bindAddr, len(addrs))
} }
ci.BindAddr = addrs[0] ci.BindAddr = addrs[0]
} }
@ -147,7 +146,7 @@ func SetFlags(ci *fs.ConfigInfo) {
// Process --disable // Process --disable
if disableFeatures != "" { if disableFeatures != "" {
if disableFeatures == "help" { if disableFeatures == "help" {
log.Fatalf("Possible backend features are: %s\n", strings.Join(new(fs.Features).List(), ", ")) fs.Fatalf(nil, "Possible backend features are: %s\n", strings.Join(new(fs.Features).List(), ", "))
} }
ci.DisableFeatures = strings.Split(disableFeatures, ",") ci.DisableFeatures = strings.Split(disableFeatures, ",")
} }
@ -169,7 +168,7 @@ func SetFlags(ci *fs.ConfigInfo) {
for _, kv := range metadataSet { for _, kv := range metadataSet {
equal := strings.IndexRune(kv, '=') equal := strings.IndexRune(kv, '=')
if equal < 0 { if equal < 0 {
log.Fatalf("Failed to parse '%s' as metadata key=value.", kv) fs.Fatalf(nil, "Failed to parse '%s' as metadata key=value.", kv)
} }
ci.MetadataSet[strings.ToLower(kv[:equal])] = kv[equal+1:] ci.MetadataSet[strings.ToLower(kv[:equal])] = kv[equal+1:]
} }
@ -181,23 +180,23 @@ func SetFlags(ci *fs.ConfigInfo) {
if value, ok := parseDSCP(dscp); ok { if value, ok := parseDSCP(dscp); ok {
ci.TrafficClass = value << 2 ci.TrafficClass = value << 2
} else { } else {
log.Fatalf("--dscp: Invalid DSCP name: %v", dscp) fs.Fatalf(nil, "--dscp: Invalid DSCP name: %v", dscp)
} }
} }
// Process --config path // Process --config path
if err := config.SetConfigPath(configPath); err != nil { if err := config.SetConfigPath(configPath); err != nil {
log.Fatalf("--config: Failed to set %q as config path: %v", configPath, err) fs.Fatalf(nil, "--config: Failed to set %q as config path: %v", configPath, err)
} }
// Process --cache-dir path // Process --cache-dir path
if err := config.SetCacheDir(cacheDir); err != nil { if err := config.SetCacheDir(cacheDir); err != nil {
log.Fatalf("--cache-dir: Failed to set %q as cache dir: %v", cacheDir, err) fs.Fatalf(nil, "--cache-dir: Failed to set %q as cache dir: %v", cacheDir, err)
} }
// Process --temp-dir path // Process --temp-dir path
if err := config.SetTempDir(tempDir); err != nil { if err := config.SetTempDir(tempDir); err != nil {
log.Fatalf("--temp-dir: Failed to set %q as temp dir: %v", tempDir, err) fs.Fatalf(nil, "--temp-dir: Failed to set %q as temp dir: %v", tempDir, err)
} }
// Process --multi-thread-streams - set whether multi-thread-streams was set // Process --multi-thread-streams - set whether multi-thread-streams was set
@ -206,7 +205,7 @@ func SetFlags(ci *fs.ConfigInfo) {
// Reload any changes // Reload any changes
if err := ci.Reload(context.Background()); err != nil { if err := ci.Reload(context.Background()); err != nil {
log.Fatalf("Failed to reload config changes: %v", err) fs.Fatalf(nil, "Failed to reload config changes: %v", err)
} }
} }

View file

@ -3,7 +3,6 @@
package flags package flags
import ( import (
"log"
"os" "os"
"regexp" "regexp"
"strings" "strings"
@ -74,7 +73,7 @@ func (gs *Groups) Include(groupsString string) *Groups {
for _, groupName := range strings.Split(groupsString, ",") { for _, groupName := range strings.Split(groupsString, ",") {
_, ok := All.ByName[groupName] _, ok := All.ByName[groupName]
if !ok { if !ok {
log.Fatalf("Couldn't find group %q in command annotation", groupName) fs.Fatalf(nil, "Couldn't find group %q in command annotation", groupName)
} }
want[groupName] = true want[groupName] = true
} }
@ -138,7 +137,7 @@ func installFlag(flags *pflag.FlagSet, name string, groupsString string) {
// Find flag // Find flag
flag := flags.Lookup(name) flag := flags.Lookup(name)
if flag == nil { if flag == nil {
log.Fatalf("Couldn't find flag --%q", name) fs.Fatalf(nil, "Couldn't find flag --%q", name)
} }
// Read default from environment if possible // Read default from environment if possible
@ -146,7 +145,7 @@ func installFlag(flags *pflag.FlagSet, name string, groupsString string) {
if envValue, envFound := os.LookupEnv(envKey); envFound { if envValue, envFound := os.LookupEnv(envKey); envFound {
err := flags.Set(name, envValue) err := flags.Set(name, envValue)
if err != nil { if err != nil {
log.Fatalf("Invalid value when setting --%s from environment variable %s=%q: %v", name, envKey, envValue, err) fs.Fatalf(nil, "Invalid value when setting --%s from environment variable %s=%q: %v", name, envKey, envValue, err)
} }
fs.Debugf(nil, "Setting --%s %q from environment variable %s=%q", name, flag.Value, envKey, envValue) fs.Debugf(nil, "Setting --%s %q from environment variable %s=%q", name, flag.Value, envKey, envValue)
flag.DefValue = envValue flag.DefValue = envValue
@ -160,7 +159,7 @@ func installFlag(flags *pflag.FlagSet, name string, groupsString string) {
} }
group, ok := All.ByName[groupName] group, ok := All.ByName[groupName]
if !ok { if !ok {
log.Fatalf("Couldn't find group %q for flag --%s", groupName, name) fs.Fatalf(nil, "Couldn't find group %q for flag --%s", groupName, name)
} }
group.Add(flag) group.Add(flag)
} }

View file

@ -9,8 +9,9 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"math" "math"
"github.com/rclone/rclone/fs"
) )
// crypt internals // crypt internals
@ -66,7 +67,7 @@ func Obscure(x string) (string, error) {
func MustObscure(x string) string { func MustObscure(x string) string {
out, err := Obscure(x) out, err := Obscure(x)
if err != nil { if err != nil {
log.Fatalf("Obscure failed: %v", err) fs.Fatalf(nil, "Obscure failed: %v", err)
} }
return out return out
} }
@ -92,7 +93,7 @@ func Reveal(x string) (string, error) {
func MustReveal(x string) string { func MustReveal(x string) string {
out, err := Reveal(x) out, err := Reveal(x)
if err != nil { if err != nil {
log.Fatalf("Reveal failed: %v", err) fs.Fatalf(nil, "Reveal failed: %v", err)
} }
return out return out
} }

View file

@ -7,7 +7,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"log"
"os" "os"
"sort" "sort"
"strconv" "strconv"
@ -29,7 +28,7 @@ var ReadLine = func() string {
buf := bufio.NewReader(os.Stdin) buf := bufio.NewReader(os.Stdin)
line, err := buf.ReadString('\n') line, err := buf.ReadString('\n')
if err != nil { if err != nil {
log.Fatalf("Failed to read line: %v", err) fs.Fatalf(nil, "Failed to read line: %v", err)
} }
return strings.TrimSpace(line) return strings.TrimSpace(line)
} }
@ -233,7 +232,7 @@ func ChoosePassword(defaultValue string, required bool) string {
bits := ChooseNumber("Bits", 64, 1024) bits := ChooseNumber("Bits", 64, 1024)
password, err = Password(bits) password, err = Password(bits)
if err != nil { if err != nil {
log.Fatalf("Failed to make password: %v", err) fs.Fatalf(nil, "Failed to make password: %v", err)
} }
fmt.Printf("Your password is: %s\n", password) fmt.Printf("Your password is: %s\n", password)
fmt.Printf("Use this password? Please note that an obscured version of this \npassword (and not the " + fmt.Printf("Use this password? Please note that an obscured version of this \npassword (and not the " +
@ -297,7 +296,7 @@ func ChooseRemote() string {
func mustFindByName(name string) *fs.RegInfo { func mustFindByName(name string) *fs.RegInfo {
fsType := GetValue(name, "type") fsType := GetValue(name, "type")
if fsType == "" { if fsType == "" {
log.Fatalf("Couldn't find type of fs for %q", name) fs.Fatalf(nil, "Couldn't find type of fs for %q", name)
} }
return fs.MustFind(fsType) return fs.MustFind(fsType)
} }
@ -654,7 +653,7 @@ func ShowConfigLocation() {
func ShowConfig() { func ShowConfig() {
str, err := LoadedData().Serialize() str, err := LoadedData().Serialize()
if err != nil { if err != nil {
log.Fatalf("Failed to serialize config: %v", err) fs.Fatalf(nil, "Failed to serialize config: %v", err)
} }
if str == "" { if str == "" {
str = "; empty config\n" str = "; empty config\n"

View file

@ -5,7 +5,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"log"
"path" "path"
"strings" "strings"
"time" "time"
@ -190,7 +189,7 @@ func NewFilter(opt *Options) (f *Filter, err error) {
if f.Opt.MaxAge.IsSet() { if f.Opt.MaxAge.IsSet() {
f.ModTimeFrom = time.Now().Add(-time.Duration(f.Opt.MaxAge)) f.ModTimeFrom = time.Now().Add(-time.Duration(f.Opt.MaxAge))
if !f.ModTimeTo.IsZero() && f.ModTimeTo.Before(f.ModTimeFrom) { if !f.ModTimeTo.IsZero() && f.ModTimeTo.Before(f.ModTimeFrom) {
log.Fatalf("filter: --min-age %q can't be larger than --max-age %q", opt.MinAge, opt.MaxAge) fs.Fatalf(nil, "filter: --min-age %q can't be larger than --max-age %q", opt.MinAge, opt.MaxAge)
} }
fs.Debugf(nil, "--max-age %v to %v", f.Opt.MaxAge, f.ModTimeFrom) fs.Debugf(nil, "--max-age %v to %v", f.Opt.MaxAge, f.ModTimeFrom)
} }

View file

@ -6,7 +6,6 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
"log"
"net" "net"
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
@ -71,17 +70,17 @@ func NewTransportCustom(ctx context.Context, customize func(*http.Transport)) ht
// Load client certs // Load client certs
if ci.ClientCert != "" || ci.ClientKey != "" { if ci.ClientCert != "" || ci.ClientKey != "" {
if ci.ClientCert == "" || ci.ClientKey == "" { if ci.ClientCert == "" || ci.ClientKey == "" {
log.Fatalf("Both --client-cert and --client-key must be set") fs.Fatalf(nil, "Both --client-cert and --client-key must be set")
} }
cert, err := tls.LoadX509KeyPair(ci.ClientCert, ci.ClientKey) cert, err := tls.LoadX509KeyPair(ci.ClientCert, ci.ClientKey)
if err != nil { if err != nil {
log.Fatalf("Failed to load --client-cert/--client-key pair: %v", err) fs.Fatalf(nil, "Failed to load --client-cert/--client-key pair: %v", err)
} }
if cert.Leaf == nil { if cert.Leaf == nil {
// Leaf is always the first certificate // Leaf is always the first certificate
cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0]) cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0])
if err != nil { if err != nil {
log.Fatalf("Failed to parse the certificate") fs.Fatalf(nil, "Failed to parse the certificate")
} }
} }
t.TLSClientConfig.Certificates = []tls.Certificate{cert} t.TLSClientConfig.Certificates = []tls.Certificate{cert}
@ -95,11 +94,11 @@ func NewTransportCustom(ctx context.Context, customize func(*http.Transport)) ht
for _, cert := range ci.CaCert { for _, cert := range ci.CaCert {
caCert, err := os.ReadFile(cert) caCert, err := os.ReadFile(cert)
if err != nil { if err != nil {
log.Fatalf("Failed to read --ca-cert file %q : %v", cert, err) fs.Fatalf(nil, "Failed to read --ca-cert file %q : %v", cert, err)
} }
ok := caCertPool.AppendCertsFromPEM(caCert) ok := caCertPool.AppendCertsFromPEM(caCert)
if !ok { if !ok {
log.Fatalf("Failed to add certificates from --ca-cert file %q", cert) fs.Fatalf(nil, "Failed to add certificates from --ca-cert file %q", cert)
} }
} }
t.TLSClientConfig.RootCAs = caCertPool t.TLSClientConfig.RootCAs = caCertPool
@ -303,7 +302,7 @@ func (t *Transport) reloadCertificates() {
cert, err := tls.LoadX509KeyPair(t.clientCert, t.clientKey) cert, err := tls.LoadX509KeyPair(t.clientCert, t.clientKey)
if err != nil { if err != nil {
log.Fatalf("Failed to load --client-cert/--client-key pair: %v", err) fs.Fatalf(nil, "Failed to load --client-cert/--client-key pair: %v", err)
} }
// Check if we need to parse the certificate again, we need it // Check if we need to parse the certificate again, we need it
// for checking the expiration date // for checking the expiration date
@ -311,7 +310,7 @@ func (t *Transport) reloadCertificates() {
// Leaf is always the first certificate // Leaf is always the first certificate
cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0]) cert.Leaf, err = x509.ParseCertificate(cert.Certificate[0])
if err != nil { if err != nil {
log.Fatalf("Failed to parse the certificate") fs.Fatalf(nil, "Failed to parse the certificate")
} }
} }
t.TLSClientConfig.Certificates = []tls.Certificate{cert} t.TLSClientConfig.Certificates = []tls.Certificate{cert}

View file

@ -2,10 +2,11 @@ package hash_test
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"log"
"testing" "testing"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/hash" "github.com/rclone/rclone/fs/hash"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -24,7 +25,7 @@ func TestHashSet(t *testing.T) {
assert.Len(t, a, 0) assert.Len(t, a, 0)
h = h.Add(hash.MD5) h = h.Add(hash.MD5)
log.Println(h) fs.Log(nil, fmt.Sprint(h))
assert.Equal(t, 1, h.Count()) assert.Equal(t, 1, h.Count())
assert.Equal(t, hash.MD5, h.GetOne()) assert.Equal(t, hash.MD5, h.GetOne())
a = h.Array() a = h.Array()

View file

@ -144,7 +144,7 @@ func InitLogging() {
if Opt.File != "" { if Opt.File != "" {
f, err := os.OpenFile(Opt.File, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640) f, err := os.OpenFile(Opt.File, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
if err != nil { if err != nil {
log.Fatalf("Failed to open log file: %v", err) fs.Fatalf(nil, "Failed to open log file: %v", err)
} }
_, err = f.Seek(0, io.SeekEnd) _, err = f.Seek(0, io.SeekEnd)
if err != nil { if err != nil {
@ -158,7 +158,7 @@ func InitLogging() {
// Syslog output // Syslog output
if Opt.UseSyslog { if Opt.UseSyslog {
if Opt.File != "" { if Opt.File != "" {
log.Fatalf("Can't use --syslog and --log-file together") fs.Fatalf(nil, "Can't use --syslog and --log-file together")
} }
startSysLog() startSysLog()
} }

View file

@ -5,9 +5,9 @@
package log package log
import ( import (
"log"
"os" "os"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config" "github.com/rclone/rclone/fs/config"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -16,11 +16,11 @@ import (
func redirectStderr(f *os.File) { func redirectStderr(f *os.File) {
passPromptFd, err := unix.Dup(int(os.Stderr.Fd())) passPromptFd, err := unix.Dup(int(os.Stderr.Fd()))
if err != nil { if err != nil {
log.Fatalf("Failed to duplicate stderr: %v", err) fs.Fatalf(nil, "Failed to duplicate stderr: %v", err)
} }
config.PasswordPromptOutput = os.NewFile(uintptr(passPromptFd), "passPrompt") config.PasswordPromptOutput = os.NewFile(uintptr(passPromptFd), "passPrompt")
err = unix.Dup2(int(f.Fd()), int(os.Stderr.Fd())) err = unix.Dup2(int(f.Fd()), int(os.Stderr.Fd()))
if err != nil { if err != nil {
log.Fatalf("Failed to redirect stderr to file: %v", err) fs.Fatalf(nil, "Failed to redirect stderr to file: %v", err)
} }
} }

View file

@ -9,9 +9,10 @@
package log package log
import ( import (
"log"
"os" "os"
"syscall" "syscall"
"github.com/rclone/rclone/fs"
) )
var ( var (
@ -34,6 +35,6 @@ func setStdHandle(stdhandle int32, handle syscall.Handle) error {
func redirectStderr(f *os.File) { func redirectStderr(f *os.File) {
err := setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd())) err := setStdHandle(syscall.STD_ERROR_HANDLE, syscall.Handle(f.Fd()))
if err != nil { if err != nil {
log.Fatalf("Failed to redirect stderr to file: %v", err) fs.Fatalf(nil, "Failed to redirect stderr to file: %v", err)
} }
} }

View file

@ -5,12 +5,13 @@
package log package log
import ( import (
"log"
"runtime" "runtime"
"github.com/rclone/rclone/fs"
) )
// Starts syslog if configured, returns true if it was started // Starts syslog if configured, returns true if it was started
func startSysLog() bool { func startSysLog() bool {
log.Fatalf("--syslog not supported on %s platform", runtime.GOOS) fs.Fatalf(nil, "--syslog not supported on %s platform", runtime.GOOS)
return false return false
} }

View file

@ -42,12 +42,12 @@ var (
func startSysLog() bool { func startSysLog() bool {
facility, ok := syslogFacilityMap[Opt.SyslogFacility] facility, ok := syslogFacilityMap[Opt.SyslogFacility]
if !ok { if !ok {
log.Fatalf("Unknown syslog facility %q - man syslog for list", Opt.SyslogFacility) fs.Fatalf(nil, "Unknown syslog facility %q - man syslog for list", Opt.SyslogFacility)
} }
Me := path.Base(os.Args[0]) Me := path.Base(os.Args[0])
w, err := syslog.New(syslog.LOG_NOTICE|facility, Me) w, err := syslog.New(syslog.LOG_NOTICE|facility, Me)
if err != nil { if err != nil {
log.Fatalf("Failed to start syslog: %v", err) fs.Fatalf(nil, "Failed to start syslog: %v", err)
} }
log.SetFlags(0) log.SetFlags(0)
log.SetOutput(w) log.SetOutput(w)

View file

@ -5,13 +5,14 @@
package log package log
import ( import (
"log"
"runtime" "runtime"
"github.com/rclone/rclone/fs"
) )
// Enables systemd logs if configured or if auto-detected // Enables systemd logs if configured or if auto-detected
func startSystemdLog() bool { func startSystemdLog() bool {
log.Fatalf("--log-systemd not supported on %s platform", runtime.GOOS) fs.Fatalf(nil, "--log-systemd not supported on %s platform", runtime.GOOS)
return false return false
} }

View file

@ -3,7 +3,6 @@ package fs
import ( import (
"errors" "errors"
"fmt" "fmt"
"log"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -16,7 +15,7 @@ func init() {
if args, err := convertMountHelperArgs(os.Args); err == nil { if args, err := convertMountHelperArgs(os.Args); err == nil {
os.Args = args os.Args = args
} else { } else {
log.Fatalf("Failed to parse command line: %v", err) Fatalf(nil, "Failed to parse command line: %v", err)
} }
} }
} }

View file

@ -5,7 +5,6 @@ package operations
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"path" "path"
"sort" "sort"
"strings" "strings"
@ -21,7 +20,7 @@ import (
func dedupeRename(ctx context.Context, f fs.Fs, remote string, objs []fs.Object) { func dedupeRename(ctx context.Context, f fs.Fs, remote string, objs []fs.Object) {
doMove := f.Features().Move doMove := f.Features().Move
if doMove == nil { if doMove == nil {
log.Fatalf("Fs %v doesn't support Move", f) fs.Fatalf(nil, "Fs %v doesn't support Move", f)
} }
ext := path.Ext(remote) ext := path.Ext(remote)
base := remote[:len(remote)-len(ext)] base := remote[:len(remote)-len(ext)]

View file

@ -7,7 +7,6 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"log"
"mime" "mime"
"net/http" "net/http"
"net/url" "net/url"
@ -86,7 +85,7 @@ func newServer(ctx context.Context, opt *rc.Options, mux *http.ServeMux) (*Serve
if opt.Auth.BasicPass == "" && opt.Auth.HtPasswd == "" { if opt.Auth.BasicPass == "" && opt.Auth.HtPasswd == "" {
randomPass, err := random.Password(128) randomPass, err := random.Password(128)
if err != nil { if err != nil {
log.Fatalf("Failed to make password: %v", err) fs.Fatalf(nil, "Failed to make password: %v", err)
} }
opt.Auth.BasicPass = randomPass opt.Auth.BasicPass = randomPass
fs.Infof(nil, "No password specified. Using random password: %s \n", randomPass) fs.Infof(nil, "No password specified. Using random password: %s \n", randomPass)

View file

@ -6,7 +6,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"reflect" "reflect"
"regexp" "regexp"
"sort" "sort"
@ -408,7 +407,7 @@ func Find(name string) (*RegInfo, error) {
func MustFind(name string) *RegInfo { func MustFind(name string) *RegInfo {
fs, err := Find(name) fs, err := Find(name)
if err != nil { if err != nil {
log.Fatalf("Failed to find remote: %v", err) Fatalf(nil, "Failed to find remote: %v", err)
} }
return fs return fs
} }
@ -434,7 +433,7 @@ func RegisterGlobalOptions(oi OptionsInfo) {
if oi.Opt != nil && oi.Options != nil { if oi.Opt != nil && oi.Options != nil {
err := oi.Check() err := oi.Check()
if err != nil { if err != nil {
log.Fatalf("%v", err) Fatalf(nil, "%v", err)
} }
} }
// Load the default values into the options. // Load the default values into the options.
@ -446,7 +445,7 @@ func RegisterGlobalOptions(oi OptionsInfo) {
// again when the flags are ready. // again when the flags are ready.
err := oi.load() err := oi.load()
if err != nil { if err != nil {
log.Fatalf("Failed to load %q default values: %v", oi.Name, err) Fatalf(nil, "Failed to load %q default values: %v", oi.Name, err)
} }
} }

View file

@ -10,7 +10,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -99,7 +98,7 @@ func NewItem(Path, Content string, modTime time.Time) Item {
buf := bytes.NewBufferString(Content) buf := bytes.NewBufferString(Content)
_, err := io.Copy(hash, buf) _, err := io.Copy(hash, buf)
if err != nil { if err != nil {
log.Fatalf("Failed to create item: %v", err) fs.Fatalf(nil, "Failed to create item: %v", err)
} }
i.Hashes = hash.Sums() i.Hashes = hash.Sums()
return i return i
@ -398,7 +397,7 @@ func CompareItems(t *testing.T, entries fs.DirEntries, items []Item, expectedDir
func Time(timeString string) time.Time { func Time(timeString string) time.Time {
t, err := time.Parse(time.RFC3339Nano, timeString) t, err := time.Parse(time.RFC3339Nano, timeString)
if err != nil { if err != nil {
log.Fatalf("Failed to parse time %q: %v", timeString, err) fs.Fatalf(nil, "Failed to parse time %q: %v", timeString, err)
} }
return t return t
} }
@ -433,7 +432,7 @@ func RandomRemoteName(remoteName string) (string, string, error) {
} }
leafName = "rclone-test-" + random.String(12) leafName = "rclone-test-" + random.String(12)
if !MatchTestRemote.MatchString(leafName) { if !MatchTestRemote.MatchString(leafName) {
log.Fatalf("%q didn't match the test remote name regexp", leafName) fs.Fatalf(nil, "%q didn't match the test remote name regexp", leafName)
} }
remoteName += leafName remoteName += leafName
} }
@ -467,7 +466,7 @@ func RandomRemote() (fs.Fs, string, func(), error) {
if parentRemote != nil { if parentRemote != nil {
Purge(parentRemote) Purge(parentRemote)
if err != nil { if err != nil {
log.Printf("Failed to purge %v: %v", parentRemote, err) fs.Logf(nil, "Failed to purge %v: %v", parentRemote, err)
} }
} }
} }
@ -499,7 +498,7 @@ func Purge(f fs.Fs) {
fs.Debugf(f, "Purge object %q", obj.Remote()) fs.Debugf(f, "Purge object %q", obj.Remote())
err = obj.Remove(ctx) err = obj.Remove(ctx)
if err != nil { if err != nil {
log.Printf("purge failed to remove %q: %v", obj.Remote(), err) fs.Logf(nil, "purge failed to remove %q: %v", obj.Remote(), err)
} }
}) })
entries.ForDir(func(dir fs.Directory) { entries.ForDir(func(dir fs.Directory) {
@ -513,12 +512,12 @@ func Purge(f fs.Fs) {
fs.Debugf(f, "Purge dir %q", dir) fs.Debugf(f, "Purge dir %q", dir)
err := f.Rmdir(ctx, dir) err := f.Rmdir(ctx, dir)
if err != nil { if err != nil {
log.Printf("purge failed to rmdir %q: %v", dir, err) fs.Logf(nil, "purge failed to rmdir %q: %v", dir, err)
} }
} }
} }
if err != nil { if err != nil {
log.Printf("purge failed: %v", err) fs.Logf(nil, "purge failed: %v", err)
} }
} }

View file

@ -5,7 +5,6 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"regexp" "regexp"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
@ -27,7 +26,7 @@ func cleanFs(ctx context.Context, remote string, cleanup bool) error {
} }
var lastErr error var lastErr error
if cleanup { if cleanup {
log.Printf("%q - running cleanup", remote) fs.Logf(nil, "%q - running cleanup", remote)
err = operations.CleanUp(ctx, f) err = operations.CleanUp(ctx, f)
if err != nil { if err != nil {
lastErr = err lastErr = err
@ -43,10 +42,10 @@ func cleanFs(ctx context.Context, remote string, cleanup bool) error {
fullPath := fspath.JoinRootPath(remote, dirPath) fullPath := fspath.JoinRootPath(remote, dirPath)
if MatchTestRemote.MatchString(dirPath) { if MatchTestRemote.MatchString(dirPath) {
if *dryRun { if *dryRun {
log.Printf("Not Purging %s - -dry-run", fullPath) fs.Logf(nil, "Not Purging %s - -dry-run", fullPath)
return nil return nil
} }
log.Printf("Purging %s", fullPath) fs.Logf(nil, "Purging %s", fullPath)
dir, err := fs.NewFs(context.Background(), fullPath) dir, err := fs.NewFs(context.Background(), fullPath)
if err != nil { if err != nil {
err = fmt.Errorf("NewFs failed: %w", err) err = fmt.Errorf("NewFs failed: %w", err)
@ -75,11 +74,11 @@ func cleanRemotes(conf *Config) error {
var lastError error var lastError error
for _, backend := range conf.Backends { for _, backend := range conf.Backends {
remote := backend.Remote remote := backend.Remote
log.Printf("%q - Cleaning", remote) fs.Logf(nil, "%q - Cleaning", remote)
err := cleanFs(context.Background(), remote, backend.CleanUp) err := cleanFs(context.Background(), remote, backend.CleanUp)
if err != nil { if err != nil {
lastError = err lastError = err
log.Printf("Failed to purge %q: %v", remote, err) fs.Logf(nil, "Failed to purge %q: %v", remote, err)
} }
} }
return lastError return lastError

View file

@ -4,7 +4,6 @@ package main
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"path" "path"
@ -65,7 +64,7 @@ func (b *Backend) MakeRuns(t *Test) (runs []*Run) {
maxSize := fs.SizeSuffix(0) maxSize := fs.SizeSuffix(0)
if b.MaxFile != "" { if b.MaxFile != "" {
if err := maxSize.Set(b.MaxFile); err != nil { if err := maxSize.Set(b.MaxFile); err != nil {
log.Printf("Invalid maxfile value %q: %v", b.MaxFile, err) fs.Logf(nil, "Invalid maxfile value %q: %v", b.MaxFile, err)
} }
} }
fastlists := []bool{false} fastlists := []bool{false}
@ -152,11 +151,11 @@ func (c *Config) filterBackendsByRemotes(remotes []string) {
} }
} }
if !found { if !found {
log.Printf("Remote %q not found - inserting with default flags", name) fs.Logf(nil, "Remote %q not found - inserting with default flags", name)
// Lookup which backend // Lookup which backend
fsInfo, _, _, _, err := fs.ConfigFs(name) fsInfo, _, _, _, err := fs.ConfigFs(name)
if err != nil { if err != nil {
log.Fatalf("couldn't find remote %q: %v", name, err) fs.Fatalf(nil, "couldn't find remote %q: %v", name, err)
} }
newBackends = append(newBackends, Backend{Backend: fsInfo.FileName(), Remote: name}) newBackends = append(newBackends, Backend{Backend: fsInfo.FileName(), Remote: name})
} }

View file

@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"log"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -77,7 +76,7 @@ func NewReport() *Report {
r.LogDir = path.Join(*outputDir, r.DateTime) r.LogDir = path.Join(*outputDir, r.DateTime)
err = file.MkdirAll(r.LogDir, 0777) err = file.MkdirAll(r.LogDir, 0777)
if err != nil { if err != nil {
log.Fatalf("Failed to make log directory: %v", err) fs.Fatalf(nil, "Failed to make log directory: %v", err)
} }
// Online version // Online version
@ -132,15 +131,15 @@ func (r *Report) Title() string {
// LogSummary writes the summary to the log file // LogSummary writes the summary to the log file
func (r *Report) LogSummary() { func (r *Report) LogSummary() {
log.Printf("Logs in %q", r.LogDir) fs.Logf(nil, "Logs in %q", r.LogDir)
// Summarise results // Summarise results
log.Printf("SUMMARY") fs.Logf(nil, "SUMMARY")
log.Println(r.Title()) fs.Log(nil, r.Title())
if !r.AllPassed() { if !r.AllPassed() {
for _, t := range r.Failed { for _, t := range r.Failed {
log.Printf(" * %s", toShell(t.nextCmdLine())) fs.Logf(nil, " * %s", toShell(t.nextCmdLine()))
log.Printf(" * Failed tests: %v", t.FailedTests) fs.Logf(nil, " * Failed tests: %v", t.FailedTests)
} }
} }
} }
@ -149,11 +148,11 @@ func (r *Report) LogSummary() {
func (r *Report) LogJSON() { func (r *Report) LogJSON() {
out, err := json.MarshalIndent(r, "", "\t") out, err := json.MarshalIndent(r, "", "\t")
if err != nil { if err != nil {
log.Fatalf("Failed to marshal data for index.json: %v", err) fs.Fatalf(nil, "Failed to marshal data for index.json: %v", err)
} }
err = os.WriteFile(path.Join(r.LogDir, "index.json"), out, 0666) err = os.WriteFile(path.Join(r.LogDir, "index.json"), out, 0666)
if err != nil { if err != nil {
log.Fatalf("Failed to write index.json: %v", err) fs.Fatalf(nil, "Failed to write index.json: %v", err)
} }
} }
@ -162,17 +161,17 @@ func (r *Report) LogHTML() {
r.IndexHTML = path.Join(r.LogDir, "index.html") r.IndexHTML = path.Join(r.LogDir, "index.html")
out, err := os.Create(r.IndexHTML) out, err := os.Create(r.IndexHTML)
if err != nil { if err != nil {
log.Fatalf("Failed to open index.html: %v", err) fs.Fatalf(nil, "Failed to open index.html: %v", err)
} }
defer func() { defer func() {
err := out.Close() err := out.Close()
if err != nil { if err != nil {
log.Fatalf("Failed to close index.html: %v", err) fs.Fatalf(nil, "Failed to close index.html: %v", err)
} }
}() }()
err = reportTemplate.Execute(out, r) err = reportTemplate.Execute(out, r)
if err != nil { if err != nil {
log.Fatalf("Failed to execute template: %v", err) fs.Fatalf(nil, "Failed to execute template: %v", err)
} }
_ = open.Start("file://" + r.IndexHTML) _ = open.Start("file://" + r.IndexHTML)
} }
@ -282,19 +281,19 @@ func (r *Report) EmailHTML() {
if *emailReport == "" || r.IndexHTML == "" { if *emailReport == "" || r.IndexHTML == "" {
return return
} }
log.Printf("Sending email summary to %q", *emailReport) fs.Logf(nil, "Sending email summary to %q", *emailReport)
cmdLine := []string{"mail", "-a", "Content-Type: text/html", *emailReport, "-s", "rclone integration tests: " + r.Title()} cmdLine := []string{"mail", "-a", "Content-Type: text/html", *emailReport, "-s", "rclone integration tests: " + r.Title()}
cmd := exec.Command(cmdLine[0], cmdLine[1:]...) cmd := exec.Command(cmdLine[0], cmdLine[1:]...)
in, err := os.Open(r.IndexHTML) in, err := os.Open(r.IndexHTML)
if err != nil { if err != nil {
log.Fatalf("Failed to open index.html: %v", err) fs.Fatalf(nil, "Failed to open index.html: %v", err)
} }
cmd.Stdin = in cmd.Stdin = in
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
log.Fatalf("Failed to send email: %v", err) fs.Fatalf(nil, "Failed to send email: %v", err)
} }
_ = in.Close() _ = in.Close()
} }
@ -302,14 +301,14 @@ func (r *Report) EmailHTML() {
// uploadTo uploads a copy of the report online to the dir given // uploadTo uploads a copy of the report online to the dir given
func (r *Report) uploadTo(uploadDir string) { func (r *Report) uploadTo(uploadDir string) {
dst := path.Join(*uploadPath, uploadDir) dst := path.Join(*uploadPath, uploadDir)
log.Printf("Uploading results to %q", dst) fs.Logf(nil, "Uploading results to %q", dst)
cmdLine := []string{"rclone", "sync", "--stats-log-level", "NOTICE", r.LogDir, dst} cmdLine := []string{"rclone", "sync", "--stats-log-level", "NOTICE", r.LogDir, dst}
cmd := exec.Command(cmdLine[0], cmdLine[1:]...) cmd := exec.Command(cmdLine[0], cmdLine[1:]...)
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
log.Fatalf("Failed to upload results: %v", err) fs.Fatalf(nil, "Failed to upload results: %v", err)
} }
} }

View file

@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"go/build" "go/build"
"io" "io"
"log"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -94,10 +93,10 @@ func (rs Runs) Less(i, j int) bool {
// dumpOutput prints the error output // dumpOutput prints the error output
func (r *Run) dumpOutput() { func (r *Run) dumpOutput() {
log.Println("------------------------------------------------------------") fs.Log(nil, "------------------------------------------------------------")
log.Printf("---- %q ----", r.CmdString) fs.Logf(nil, "---- %q ----", r.CmdString)
log.Println(string(r.output)) fs.Log(nil, string(r.output))
log.Println("------------------------------------------------------------") fs.Log(nil, "------------------------------------------------------------")
} }
// trie for storing runs // trie for storing runs
@ -180,7 +179,7 @@ func (r *Run) findFailures() {
} }
r.FailedTests = newTests r.FailedTests = newTests
if len(r.FailedTests) == 0 && ignored > 0 { if len(r.FailedTests) == 0 && ignored > 0 {
log.Printf("%q - Found %d ignored errors only - marking as good", r.CmdString, ignored) fs.Logf(nil, "%q - Found %d ignored errors only - marking as good", r.CmdString, ignored)
r.err = nil r.err = nil
r.dumpOutput() r.dumpOutput()
return return
@ -191,10 +190,10 @@ func (r *Run) findFailures() {
r.RunFlag = "" r.RunFlag = ""
} }
if r.passed() && len(r.FailedTests) != 0 { if r.passed() && len(r.FailedTests) != 0 {
log.Printf("%q - Expecting no errors but got: %v", r.CmdString, r.FailedTests) fs.Logf(nil, "%q - Expecting no errors but got: %v", r.CmdString, r.FailedTests)
r.dumpOutput() r.dumpOutput()
} else if !r.passed() && len(r.FailedTests) == 0 { } else if !r.passed() && len(r.FailedTests) == 0 {
log.Printf("%q - Expecting errors but got none: %v", r.CmdString, r.FailedTests) fs.Logf(nil, "%q - Expecting errors but got none: %v", r.CmdString, r.FailedTests)
r.dumpOutput() r.dumpOutput()
r.FailedTests = oldFailedTests r.FailedTests = oldFailedTests
} }
@ -214,23 +213,23 @@ func (r *Run) trial() {
CmdLine := r.nextCmdLine() CmdLine := r.nextCmdLine()
CmdString := toShell(CmdLine) CmdString := toShell(CmdLine)
msg := fmt.Sprintf("%q - Starting (try %d/%d)", CmdString, r.Try, *maxTries) msg := fmt.Sprintf("%q - Starting (try %d/%d)", CmdString, r.Try, *maxTries)
log.Println(msg) fs.Log(nil, msg)
logName := path.Join(r.LogDir, r.TrialName) logName := path.Join(r.LogDir, r.TrialName)
out, err := os.Create(logName) out, err := os.Create(logName)
if err != nil { if err != nil {
log.Fatalf("Couldn't create log file: %v", err) fs.Fatalf(nil, "Couldn't create log file: %v", err)
} }
defer func() { defer func() {
err := out.Close() err := out.Close()
if err != nil { if err != nil {
log.Fatalf("Failed to close log file: %v", err) fs.Fatalf(nil, "Failed to close log file: %v", err)
} }
}() }()
_, _ = fmt.Fprintln(out, msg) _, _ = fmt.Fprintln(out, msg)
// Early exit if --try-run // Early exit if --try-run
if *dryRun { if *dryRun {
log.Printf("Not executing as --dry-run: %v", CmdLine) fs.Logf(nil, "Not executing as --dry-run: %v", CmdLine)
_, _ = fmt.Fprintln(out, "--dry-run is set - not running") _, _ = fmt.Fprintln(out, "--dry-run is set - not running")
return return
} }
@ -238,7 +237,7 @@ func (r *Run) trial() {
// Start the test server if required // Start the test server if required
finish, err := testserver.Start(r.Remote) finish, err := testserver.Start(r.Remote)
if err != nil { if err != nil {
log.Printf("%s: Failed to start test server: %v", r.Remote, err) fs.Logf(nil, "%s: Failed to start test server: %v", r.Remote, err)
_, _ = fmt.Fprintf(out, "%s: Failed to start test server: %v\n", r.Remote, err) _, _ = fmt.Fprintf(out, "%s: Failed to start test server: %v\n", r.Remote, err)
r.err = err r.err = err
return return
@ -263,7 +262,7 @@ func (r *Run) trial() {
} else { } else {
msg = fmt.Sprintf("%q - Finished ERROR in %v (try %d/%d): %v: Failed %v", CmdString, duration, r.Try, *maxTries, r.err, r.FailedTests) msg = fmt.Sprintf("%q - Finished ERROR in %v (try %d/%d): %v: Failed %v", CmdString, duration, r.Try, *maxTries, r.err, r.FailedTests)
} }
log.Println(msg) fs.Log(nil, msg)
_, _ = fmt.Fprintln(out, msg) _, _ = fmt.Fprintln(out, msg)
} }
@ -304,23 +303,23 @@ func (r *Run) PackagePath() string {
func (r *Run) MakeTestBinary() { func (r *Run) MakeTestBinary() {
binary := r.BinaryPath() binary := r.BinaryPath()
binaryName := r.BinaryName() binaryName := r.BinaryName()
log.Printf("%s: Making test binary %q", r.Path, binaryName) fs.Logf(nil, "%s: Making test binary %q", r.Path, binaryName)
CmdLine := []string{"go", "test", "-c"} CmdLine := []string{"go", "test", "-c"}
if *race { if *race {
CmdLine = append(CmdLine, "-race") CmdLine = append(CmdLine, "-race")
} }
if *dryRun { if *dryRun {
log.Printf("Not executing: %v", CmdLine) fs.Logf(nil, "Not executing: %v", CmdLine)
return return
} }
cmd := exec.Command(CmdLine[0], CmdLine[1:]...) cmd := exec.Command(CmdLine[0], CmdLine[1:]...)
cmd.Dir = r.Path cmd.Dir = r.Path
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
log.Fatalf("Failed to make test binary: %v", err) fs.Fatalf(nil, "Failed to make test binary: %v", err)
} }
if _, err := os.Stat(binary); err != nil { if _, err := os.Stat(binary); err != nil {
log.Fatalf("Couldn't find test binary %q", binary) fs.Fatalf(nil, "Couldn't find test binary %q", binary)
} }
} }
@ -332,7 +331,7 @@ func (r *Run) RemoveTestBinary() {
binary := r.BinaryPath() binary := r.BinaryPath()
err := os.Remove(binary) // Delete the binary when finished err := os.Remove(binary) // Delete the binary when finished
if err != nil { if err != nil {
log.Printf("Error removing test binary %q: %v", binary, err) fs.Logf(nil, "Error removing test binary %q: %v", binary, err)
} }
} }
@ -428,7 +427,7 @@ func (r *Run) Run(LogDir string, result chan<- *Run) {
for r.Try = 1; r.Try <= *maxTries; r.Try++ { for r.Try = 1; r.Try <= *maxTries; r.Try++ {
r.TrialName = r.Name() + ".txt" r.TrialName = r.Name() + ".txt"
r.TrialNames = append(r.TrialNames, r.TrialName) r.TrialNames = append(r.TrialNames, r.TrialName)
log.Printf("Starting run with log %q", r.TrialName) fs.Logf(nil, "Starting run with log %q", r.TrialName)
r.trial() r.trial()
if r.passed() || r.NoRetries { if r.passed() || r.NoRetries {
break break

View file

@ -12,7 +12,7 @@ Make TesTrun have a []string of flags to try - that then makes it generic
import ( import (
"flag" "flag"
"log" "fmt"
"math/rand" "math/rand"
"os" "os"
"path" "path"
@ -21,6 +21,7 @@ import (
"time" "time"
_ "github.com/rclone/rclone/backend/all" // import all fs _ "github.com/rclone/rclone/backend/all" // import all fs
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config/configfile" "github.com/rclone/rclone/fs/config/configfile"
"github.com/rclone/rclone/lib/pacer" "github.com/rclone/rclone/lib/pacer"
) )
@ -68,8 +69,8 @@ func main() {
flag.Parse() flag.Parse()
conf, err := NewConfig(*configFile) conf, err := NewConfig(*configFile)
if err != nil { if err != nil {
log.Println("test_all should be run from the root of the rclone source code") fs.Log(nil, "test_all should be run from the root of the rclone source code")
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
configfile.Install() configfile.Install()
@ -91,7 +92,7 @@ func main() {
if *clean { if *clean {
err := cleanRemotes(conf) err := cleanRemotes(conf)
if err != nil { if err != nil {
log.Fatalf("Failed to clean: %v", err) fs.Fatalf(nil, "Failed to clean: %v", err)
} }
return return
} }
@ -100,7 +101,7 @@ func main() {
for _, remote := range conf.Backends { for _, remote := range conf.Backends {
names = append(names, remote.Remote) names = append(names, remote.Remote)
} }
log.Printf("Testing remotes: %s", strings.Join(names, ", ")) fs.Logf(nil, "Testing remotes: %s", strings.Join(names, ", "))
// Runs we will do for this test in random order // Runs we will do for this test in random order
runs := conf.MakeRuns() runs := conf.MakeRuns()

View file

@ -4,12 +4,12 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"math/rand" "math/rand"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/lib/encoder" "github.com/rclone/rclone/lib/encoder"
) )
@ -434,13 +434,13 @@ var testCasesDoubleEdge = []testCase{
func fatal(err error, s ...interface{}) { func fatal(err error, s ...interface{}) {
if err != nil { if err != nil {
log.Fatalln(append(s, err)) fs.Fatal(nil, fmt.Sprint(append(s, err)))
} }
} }
func fatalW(_ int, err error) func(...interface{}) { func fatalW(_ int, err error) func(...interface{}) {
if err != nil { if err != nil {
return func(s ...interface{}) { return func(s ...interface{}) {
log.Fatalln(append(s, err)) fs.Fatal(nil, fmt.Sprint(append(s, err)))
} }
} }
return func(s ...interface{}) {} return func(s ...interface{}) {}

View file

@ -2,8 +2,8 @@ package http
import ( import (
"bytes" "bytes"
"fmt"
"html/template" "html/template"
"log"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/fs/config/flags"
@ -42,7 +42,7 @@ Use ` + "`--{{ .Prefix }}salt`" + ` to change the password hashing salt from the
` `
tmpl, err := template.New("auth help").Parse(help) tmpl, err := template.New("auth help").Parse(help)
if err != nil { if err != nil {
log.Fatal("Fatal error parsing template", err) fs.Fatal(nil, fmt.Sprint("Fatal error parsing template", err))
} }
data := struct { data := struct {
@ -53,7 +53,7 @@ Use ` + "`--{{ .Prefix }}salt`" + ` to change the password hashing salt from the
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
err = tmpl.Execute(buf, data) err = tmpl.Execute(buf, data)
if err != nil { if err != nil {
log.Fatal("Fatal error executing template", err) fs.Fatal(nil, fmt.Sprint("Fatal error executing template", err))
} }
return buf.String() return buf.String()
} }

View file

@ -9,7 +9,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"html/template" "html/template"
"log"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -78,7 +77,7 @@ certificate authority certificate.
` `
tmpl, err := template.New("server help").Parse(help) tmpl, err := template.New("server help").Parse(help)
if err != nil { if err != nil {
log.Fatal("Fatal error parsing template", err) fs.Fatal(nil, fmt.Sprint("Fatal error parsing template", err))
} }
data := struct { data := struct {
@ -89,7 +88,7 @@ certificate authority certificate.
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
err = tmpl.Execute(buf, data) err = tmpl.Execute(buf, data)
if err != nil { if err != nil {
log.Fatal("Fatal error executing template", err) fs.Fatal(nil, fmt.Sprint("Fatal error executing template", err))
} }
return buf.String() return buf.String()
} }
@ -199,7 +198,7 @@ func (s instance) serve(wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
err := s.httpServer.Serve(s.listener) err := s.httpServer.Serve(s.listener)
if err != http.ErrServerClosed && err != nil { if err != http.ErrServerClosed && err != nil {
log.Printf("%s: unexpected error: %s", s.listener.Addr(), err.Error()) fs.Logf(nil, "%s: unexpected error: %s", s.listener.Addr(), err.Error())
} }
} }
@ -497,7 +496,7 @@ func (s *Server) Shutdown() error {
expiry := time.Now().Add(gracefulShutdownTime) expiry := time.Now().Add(gracefulShutdownTime)
ctx, cancel := context.WithDeadline(context.Background(), expiry) ctx, cancel := context.WithDeadline(context.Background(), expiry)
if err := ii.httpServer.Shutdown(ctx); err != nil { if err := ii.httpServer.Shutdown(ctx); err != nil {
log.Printf("error shutting down server: %s", err) fs.Logf(nil, "error shutting down server: %s", err)
} }
cancel() cancel()
} }

View file

@ -3,8 +3,8 @@ package http
import ( import (
"bytes" "bytes"
"embed" "embed"
"fmt"
"html/template" "html/template"
"log"
"os" "os"
"strings" "strings"
"time" "time"
@ -57,7 +57,7 @@ be used to render HTML based on specific conditions.
tmpl, err := template.New("template help").Parse(help) tmpl, err := template.New("template help").Parse(help)
if err != nil { if err != nil {
log.Fatal("Fatal error parsing template", err) fs.Fatal(nil, fmt.Sprint("Fatal error parsing template", err))
} }
data := struct { data := struct {
@ -68,7 +68,7 @@ be used to render HTML based on specific conditions.
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
err = tmpl.Execute(buf, data) err = tmpl.Execute(buf, data)
if err != nil { if err != nil {
log.Fatal("Fatal error executing template", err) fs.Fatal(nil, fmt.Sprint("Fatal error executing template", err))
} }
return buf.String() return buf.String()
} }

View file

@ -4,10 +4,10 @@ package pool
import ( import (
"fmt" "fmt"
"log"
"sync" "sync"
"time" "time"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/lib/mmap" "github.com/rclone/rclone/lib/mmap"
) )
@ -161,7 +161,7 @@ func (bp *Pool) Get() []byte {
bp.alloced++ bp.alloced++
break break
} }
log.Printf("Failed to get memory for buffer, waiting for %v: %v", waitTime, err) fs.Logf(nil, "Failed to get memory for buffer, waiting for %v: %v", waitTime, err)
bp.mu.Unlock() bp.mu.Unlock()
time.Sleep(waitTime) time.Sleep(waitTime)
bp.mu.Lock() bp.mu.Lock()
@ -178,7 +178,7 @@ func (bp *Pool) Get() []byte {
func (bp *Pool) freeBuffer(mem []byte) { func (bp *Pool) freeBuffer(mem []byte) {
err := bp.free(mem) err := bp.free(mem)
if err != nil { if err != nil {
log.Printf("Failed to free memory: %v", err) fs.Logf(nil, "Failed to free memory: %v", err)
} }
bp.alloced-- bp.alloced--
} }

View file

@ -2,10 +2,10 @@ package systemd
import ( import (
"fmt" "fmt"
"log"
"sync" "sync"
"github.com/coreos/go-systemd/v22/daemon" "github.com/coreos/go-systemd/v22/daemon"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/lib/atexit" "github.com/rclone/rclone/lib/atexit"
) )
@ -18,13 +18,13 @@ import (
// It should not be called as a result of rc commands. See #7540. // It should not be called as a result of rc commands. See #7540.
func Notify() func() { func Notify() func() {
if _, err := daemon.SdNotify(false, daemon.SdNotifyReady); err != nil { if _, err := daemon.SdNotify(false, daemon.SdNotifyReady); err != nil {
log.Printf("failed to notify ready to systemd: %v", err) fs.Logf(nil, "failed to notify ready to systemd: %v", err)
} }
var finaliseOnce sync.Once var finaliseOnce sync.Once
finalise := func() { finalise := func() {
finaliseOnce.Do(func() { finaliseOnce.Do(func() {
if _, err := daemon.SdNotify(false, daemon.SdNotifyStopping); err != nil { if _, err := daemon.SdNotify(false, daemon.SdNotifyStopping); err != nil {
log.Printf("failed to notify stopping to systemd: %v", err) fs.Logf(nil, "failed to notify stopping to systemd: %v", err)
} }
}) })
} }

View file

@ -7,7 +7,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"log"
"math" "math"
"math/rand" "math/rand"
"os" "os"
@ -16,6 +15,7 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/lib/file" "github.com/rclone/rclone/lib/file"
"github.com/rclone/rclone/lib/random" "github.com/rclone/rclone/lib/random"
) )
@ -93,13 +93,13 @@ func (t *Test) randomTest() {
// logf logs things - not shown unless -v // logf logs things - not shown unless -v
func (t *Test) logf(format string, a ...interface{}) { func (t *Test) logf(format string, a ...interface{}) {
if *verbose { if *verbose {
log.Printf(t.prefix+format, a...) fs.Logf(nil, t.prefix+format, a)
} }
} }
// errorf logs errors // errorf logs errors
func (t *Test) errorf(format string, a ...interface{}) { func (t *Test) errorf(format string, a ...interface{}) {
log.Printf(t.prefix+"ERROR: "+format, a...) fs.Logf(nil, t.prefix+"ERROR: "+format, a)
} }
// list test // list test
@ -286,7 +286,7 @@ func main() {
flag.Parse() flag.Parse()
args := flag.Args() args := flag.Args()
if len(args) != 1 { if len(args) != 1 {
log.Fatalf("%s: Syntax [opts] <directory>", os.Args[0]) fs.Fatalf(nil, "%s: Syntax [opts] <directory>", os.Args[0])
} }
dir := args[0] dir := args[0]
_ = file.MkdirAll(dir, 0777) _ = file.MkdirAll(dir, 0777)

View file

@ -8,7 +8,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -69,7 +68,7 @@ func RunTests(t *testing.T, useVFS bool, minimumRequiredCacheMode vfscommon.Cach
if test.writeBack > 0 { if test.writeBack > 0 {
what += fmt.Sprintf(",WriteBack=%v", test.writeBack) what += fmt.Sprintf(",WriteBack=%v", test.writeBack)
} }
log.Printf("Starting test run with %s", what) fs.Logf(nil, "Starting test run with %s", what)
ok := t.Run(what, func(t *testing.T) { ok := t.Run(what, func(t *testing.T) {
t.Run("TestTouchAndDelete", TestTouchAndDelete) t.Run("TestTouchAndDelete", TestTouchAndDelete)
t.Run("TestRenameOpenHandle", TestRenameOpenHandle) t.Run("TestRenameOpenHandle", TestRenameOpenHandle)
@ -100,7 +99,7 @@ func RunTests(t *testing.T, useVFS bool, minimumRequiredCacheMode vfscommon.Cach
t.Run("TestWriteFileDup", TestWriteFileDup) t.Run("TestWriteFileDup", TestWriteFileDup)
t.Run("TestWriteFileAppend", TestWriteFileAppend) t.Run("TestWriteFileAppend", TestWriteFileAppend)
}) })
log.Printf("Finished test run with %s (ok=%v)", what, ok) fs.Logf(nil, "Finished test run with %s (ok=%v)", what, ok)
run.Finalise() run.Finalise()
if !ok { if !ok {
break break
@ -146,12 +145,12 @@ func newRun(useVFS bool, vfsOpt *vfscommon.Options, mountFn mountlib.MountFn) *R
var err error var err error
r.fremote, r.fremoteName, r.cleanRemote, err = fstest.RandomRemote() r.fremote, r.fremoteName, r.cleanRemote, err = fstest.RandomRemote()
if err != nil { if err != nil {
log.Fatalf("Failed to open remote %q: %v", *fstest.RemoteName, err) fs.Fatalf(nil, "Failed to open remote %q: %v", *fstest.RemoteName, err)
} }
err = r.fremote.Mkdir(context.Background(), "") err = r.fremote.Mkdir(context.Background(), "")
if err != nil { if err != nil {
log.Fatalf("Failed to open mkdir %q: %v", *fstest.RemoteName, err) fs.Fatalf(nil, "Failed to open mkdir %q: %v", *fstest.RemoteName, err)
} }
r.startMountSubProcess() r.startMountSubProcess()
@ -176,14 +175,14 @@ func (r *Run) Finalise() {
r.sendMountCommand("exit") r.sendMountCommand("exit")
_, err := r.cmd.Process.Wait() _, err := r.cmd.Process.Wait()
if err != nil { if err != nil {
log.Fatalf("mount sub process failed: %v", err) fs.Fatalf(nil, "mount sub process failed: %v", err)
} }
} }
r.cleanRemote() r.cleanRemote()
if !r.useVFS { if !r.useVFS {
err := os.RemoveAll(r.mountPath) err := os.RemoveAll(r.mountPath)
if err != nil { if err != nil {
log.Printf("Failed to clean mountPath %q: %v", r.mountPath, err) fs.Logf(nil, "Failed to clean mountPath %q: %v", r.mountPath, err)
} }
} }
} }

View file

@ -7,7 +7,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
@ -48,7 +47,7 @@ func (r *Run) startMountSubProcess() {
} }
r.os = realOs{} r.os = realOs{}
r.mountPath = findMountPath() r.mountPath = findMountPath()
log.Printf("startMountSubProcess %q (%q) %q", r.fremote, r.fremoteName, r.mountPath) fs.Logf(nil, "startMountSubProcess %q (%q) %q", r.fremote, r.fremoteName, r.mountPath)
opt := runMountOpt{ opt := runMountOpt{
MountPoint: r.mountPath, MountPoint: r.mountPath,
@ -59,7 +58,7 @@ func (r *Run) startMountSubProcess() {
opts, err := json.Marshal(&opt) opts, err := json.Marshal(&opt)
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
// Re-run this executable with a new option -run-mount // Re-run this executable with a new option -run-mount
@ -68,32 +67,32 @@ func (r *Run) startMountSubProcess() {
r.cmd.Stderr = os.Stderr r.cmd.Stderr = os.Stderr
r.out, err = r.cmd.StdinPipe() r.out, err = r.cmd.StdinPipe()
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
r.in, err = r.cmd.StdoutPipe() r.in, err = r.cmd.StdoutPipe()
if err != nil { if err != nil {
log.Fatal(err) fs.Fatal(nil, fmt.Sprint(err))
} }
err = r.cmd.Start() err = r.cmd.Start()
if err != nil { if err != nil {
log.Fatal("startMountSubProcess failed", err) fs.Fatal(nil, fmt.Sprint("startMountSubProcess failed", err))
} }
r.scanner = bufio.NewScanner(r.in) r.scanner = bufio.NewScanner(r.in)
// Wait it for startup // Wait it for startup
log.Print("Waiting for mount to start") fs.Log(nil, "Waiting for mount to start")
for r.scanner.Scan() { for r.scanner.Scan() {
rx := strings.TrimSpace(r.scanner.Text()) rx := strings.TrimSpace(r.scanner.Text())
if rx == "STARTED" { if rx == "STARTED" {
break break
} }
log.Printf("..Mount said: %s", rx) fs.Logf(nil, "..Mount said: %s", rx)
} }
if r.scanner.Err() != nil { if r.scanner.Err() != nil {
log.Printf("scanner err %v", r.scanner.Err()) fs.Logf(nil, "scanner err %v", r.scanner.Err())
} }
log.Printf("startMountSubProcess: end") fs.Logf(nil, "startMountSubProcess: end")
} }
// Find a free path to run the mount on // Find a free path to run the mount on
@ -101,7 +100,7 @@ func findMountPath() string {
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
mountPath, err := os.MkdirTemp("", "rclonefs-mount") mountPath, err := os.MkdirTemp("", "rclonefs-mount")
if err != nil { if err != nil {
log.Fatalf("Failed to create mount dir: %v", err) fs.Fatalf(nil, "Failed to create mount dir: %v", err)
} }
return mountPath return mountPath
} }
@ -110,7 +109,7 @@ func findMountPath() string {
letter := file.FindUnusedDriveLetter() letter := file.FindUnusedDriveLetter()
drive := "" drive := ""
if letter == 0 { if letter == 0 {
log.Fatalf("Couldn't find free drive letter for test") fs.Fatalf(nil, "Couldn't find free drive letter for test")
} else { } else {
drive = string(letter) + ":" drive = string(letter) + ":"
} }
@ -128,36 +127,36 @@ func isSubProcess() bool {
// It reads commands from standard input and writes results to // It reads commands from standard input and writes results to
// standard output. // standard output.
func startMount(mountFn mountlib.MountFn, useVFS bool, opts string) { func startMount(mountFn mountlib.MountFn, useVFS bool, opts string) {
log.Print("startMount") fs.Log(nil, "startMount")
ctx := context.Background() ctx := context.Background()
var opt runMountOpt var opt runMountOpt
err := json.Unmarshal([]byte(opts), &opt) err := json.Unmarshal([]byte(opts), &opt)
if err != nil { if err != nil {
log.Fatalf("Unmarshal failed: %v", err) fs.Fatalf(nil, "Unmarshal failed: %v", err)
} }
fstest.Initialise() fstest.Initialise()
f, err := cache.Get(ctx, opt.Remote) f, err := cache.Get(ctx, opt.Remote)
if err != nil { if err != nil {
log.Fatalf("Failed to open remote %q: %v", opt.Remote, err) fs.Fatalf(nil, "Failed to open remote %q: %v", opt.Remote, err)
} }
err = f.Mkdir(ctx, "") err = f.Mkdir(ctx, "")
if err != nil { if err != nil {
log.Fatalf("Failed to mkdir %q: %v", opt.Remote, err) fs.Fatalf(nil, "Failed to mkdir %q: %v", opt.Remote, err)
} }
log.Printf("startMount: Mounting %q on %q with %q", opt.Remote, opt.MountPoint, opt.VFSOpt.CacheMode) fs.Logf(nil, "startMount: Mounting %q on %q with %q", opt.Remote, opt.MountPoint, opt.VFSOpt.CacheMode)
mnt := mountlib.NewMountPoint(mountFn, opt.MountPoint, f, &opt.MountOpt, &opt.VFSOpt) mnt := mountlib.NewMountPoint(mountFn, opt.MountPoint, f, &opt.MountOpt, &opt.VFSOpt)
_, err = mnt.Mount() _, err = mnt.Mount()
if err != nil { if err != nil {
log.Fatalf("mount FAILED %q: %v", opt.Remote, err) fs.Fatalf(nil, "mount FAILED %q: %v", opt.Remote, err)
} }
defer umount(mnt) defer umount(mnt)
log.Printf("startMount: mount OK") fs.Logf(nil, "startMount: mount OK")
fmt.Println("STARTED") // signal to parent all is good fmt.Println("STARTED") // signal to parent all is good
// Read commands from stdin // Read commands from stdin
@ -172,7 +171,7 @@ func startMount(mountFn mountlib.MountFn, useVFS bool, opts string) {
err = scanner.Err() err = scanner.Err()
if err != nil { if err != nil {
log.Fatalf("scanner failed %q: %v", opt.Remote, err) fs.Fatalf(nil, "scanner failed %q: %v", opt.Remote, err)
} }
} }
@ -221,17 +220,17 @@ func (r *Run) sendMountCommand(args ...string) {
} else { } else {
_, err := io.WriteString(r.out, tx+"\n") _, err := io.WriteString(r.out, tx+"\n")
if err != nil { if err != nil {
log.Fatalf("WriteString err %v", err) fs.Fatalf(nil, "WriteString err %v", err)
} }
if !r.scanner.Scan() { if !r.scanner.Scan() {
log.Fatalf("Mount has gone away") fs.Fatalf(nil, "Mount has gone away")
} }
rx = strings.Trim(r.scanner.Text(), "\r\n") rx = strings.Trim(r.scanner.Text(), "\r\n")
} }
in := strings.Split(rx, "\t") in := strings.Split(rx, "\t")
// log.Printf("Answer is %q", in) // log.Printf("Answer is %q", in)
if in[0] != "OK" { if in[0] != "OK" {
log.Fatalf("Error from mount: %q", in[1:]) fs.Fatalf(nil, "Error from mount: %q", in[1:])
} }
} }
@ -254,25 +253,25 @@ func umount(mnt *mountlib.MountPoint) {
log.Printf("fusermount failed: %v", err) log.Printf("fusermount failed: %v", err)
} }
*/ */
log.Printf("Unmounting %q", mnt.MountPoint) fs.Logf(nil, "Unmounting %q", mnt.MountPoint)
err := mnt.Unmount() err := mnt.Unmount()
if err != nil { if err != nil {
log.Printf("signal to umount failed - retrying: %v", err) fs.Logf(nil, "signal to umount failed - retrying: %v", err)
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
err = mnt.Unmount() err = mnt.Unmount()
} }
if err != nil { if err != nil {
log.Fatalf("signal to umount failed: %v", err) fs.Fatalf(nil, "signal to umount failed: %v", err)
} }
log.Printf("Waiting for umount") fs.Logf(nil, "Waiting for umount")
err = <-mnt.ErrChan err = <-mnt.ErrChan
if err != nil { if err != nil {
log.Fatalf("umount failed: %v", err) fs.Fatalf(nil, "umount failed: %v", err)
} }
// Cleanup the VFS cache - umount has called Shutdown // Cleanup the VFS cache - umount has called Shutdown
err = mnt.VFS.CleanUp() err = mnt.VFS.CleanUp()
if err != nil { if err != nil {
log.Printf("Failed to cleanup the VFS cache: %v", err) fs.Logf(nil, "Failed to cleanup the VFS cache: %v", err)
} }
} }