Skip to content

Commit

Permalink
migrate to zerolog
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Jan 18, 2019
1 parent 3c78777 commit 664bfeb
Show file tree
Hide file tree
Showing 83 changed files with 5,805 additions and 4,248 deletions.
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ module github.com/sapk/docker-volume-rclone
require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/Microsoft/go-winio v0.4.11 // indirect
github.com/coreos/etcd v3.3.11+incompatible // indirect
github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-plugins-helpers v0.0.0-20181025120712-1e6269c305b8
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/pty v1.1.3 // indirect
github.com/sirupsen/logrus v1.3.0
github.com/rs/zerolog v1.11.0
github.com/spf13/afero v1.2.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.1
github.com/stretchr/testify v1.3.0 // indirect
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2 // indirect
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc // indirect
golang.org/x/net v0.0.0-20190110200230-915654e7eabc // indirect
golang.org/x/sys v0.0.0-20190116161447-11f53e031339 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
Expand Down
35 changes: 3 additions & 32 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.11+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20181031085051-9002847aa142 h1:3jFq2xL4ZajGK4aZY8jz+DAF0FHjI51BXjjSwCzS1Dk=
Expand All @@ -22,71 +21,45 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/mapstructure v1.0.0 h1:vVpGvMXJPqSDh2VYHF7gsfQj8Ncx+Xw5Y1KHeTRY+7I=
github.com/mitchellh/mapstructure v1.0.0/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/rs/zerolog v1.11.0 h1:DRuq/S+4k52uJzBQciUcofXx45GrMC6yrEbb/CoK6+M=
github.com/rs/zerolog v1.11.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.0 h1:O9FblXGxoTc51M+cqr74Bm2Tmt4PvkA5iu/j8HrkNuY=
github.com/spf13/afero v1.2.0/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg=
github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.2.1 h1:bIcUwXqLseLF3BDAZduuNfekWG87ibtFxi59Bq+oI9M=
github.com/spf13/viper v1.2.1/go.mod h1:P4AexN0a+C9tGAnUFNwDMYYZv3pjFuvmeiMyKRaNVlI=
github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38=
github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181126163421-e657309f52e7 h1:70UTJTdHsz+jRjphEW+is2SdxjhZL1AdKsewqjYzcQU=
golang.org/x/crypto v0.0.0-20181126163421-e657309f52e7/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc h1:F5tKCVGp+MUAHhKp5MZtGqAlGX3+oCsiL1Q629FL90M=
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190110200230-915654e7eabc h1:Yx9JGxI1SBhVLFjpAkWMaO1TF+xyqtHLjZpvQboJGiM=
golang.org/x/net v0.0.0-20190110200230-915654e7eabc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180906133057-8cf3aee42992/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b h1:MQE+LT/ABUuuvEZ+YQAMSXindAdUh7slEmAkup74op4=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190116161447-11f53e031339 h1:g/Jesu8+QLnA0CPzF3E1pURg0Byr7i6jLoX5sqjcAh0=
golang.org/x/sys v0.0.0-20190116161447-11f53e031339/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand All @@ -95,7 +68,5 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
53 changes: 27 additions & 26 deletions rclone/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/docker/go-plugins-helpers/volume"
"github.com/spf13/viper"
Expand All @@ -35,7 +36,7 @@ func (m *rcloneMountpoint) isMounted() (bool, error) {
if err != nil {
return false, err
}
log.Debugf("isMounted Path: path: %s %v", m.Path, strings.Contains(string(buf), " "+m.Path+" fuse.rclone"))
log.Debug().Msgf("isMounted Path: path: %s %v", m.Path, strings.Contains(string(buf), " "+m.Path+" fuse.rclone"))
return strings.Contains(string(buf), " "+m.Path+" fuse.rclone"), nil
}

Expand Down Expand Up @@ -71,25 +72,25 @@ func Init(root string) *RcloneDriver {
d.persitence.SetConfigType("json")
d.persitence.AddConfigPath(CfgFolder)
if err := d.persitence.ReadInConfig(); err != nil { // Handle errors reading the config file
log.Warn("No persistence file found, I will start with a empty list of volume. ", err)
log.Warn().Err(err).Msg("No persistence file found, I will start with a empty list of volume")
} else {
log.Debug("Retrieving volume list from persistence file.")
log.Debug().Msg("Retrieving volume list from persistence file.")

var version int
err := d.persitence.UnmarshalKey("version", &version)
if err != nil || version != CfgVersion {
log.Warnf("Unable to decode version of persistence, %s", err.Error())
log.Warn().Err(err).Msg("Unable to decode version of persistence")
d.volumes = make(map[string]*rcloneVolume)
d.mounts = make(map[string]*rcloneMountpoint)
} else { //We have the same version
err := d.persitence.UnmarshalKey("volumes", &d.volumes)
if err != nil {
log.Warnf("Unable to decode into struct -> start with empty list, %s", err.Error())
log.Warn().Err(err).Msg("Unable to decode into struct -> start with empty list")
d.volumes = make(map[string]*rcloneVolume)
}
err = d.persitence.UnmarshalKey("mounts", &d.mounts)
if err != nil {
log.Warnf("Unable to decode into struct -> start with empty list, %s", err.Error())
log.Warn().Err(err).Msg("Unable to decode into struct -> start with empty list")
d.mounts = make(map[string]*rcloneMountpoint)
}
}
Expand All @@ -99,7 +100,7 @@ func Init(root string) *RcloneDriver {

//Create create and init the requested volume
func (d *RcloneDriver) Create(r *volume.CreateRequest) error {
log.Debugf("Entering Create: name: %s, options %v", r.Name, r.Options)
log.Debug().Msgf("Entering Create: name: %s, options %v", r.Name, r.Options)
d.Lock()
defer d.Unlock()

Expand Down Expand Up @@ -141,46 +142,46 @@ func (d *RcloneDriver) Create(r *volume.CreateRequest) error {
}

d.volumes[r.Name] = v
log.Debugf("Volume Created: %v", v)
log.Debug().Msgf("Volume Created: %v", v)
return d.saveConfig()
}

//List volumes handled by the driver
func (d *RcloneDriver) List() (*volume.ListResponse, error) {
log.Debugf("Entering List")
log.Debug().Msgf("Entering List")
d.Lock()
defer d.Unlock()

var vols []*volume.Volume
for name, v := range d.volumes {
log.Debugf("Volume found: %v", v)
log.Debug().Msgf("Volume found: %v", v)
m, ok := d.mounts[v.Mount]
if !ok {
return nil, fmt.Errorf("volume mount %s not found for %s", v.Mount, v.Remote)
}
log.Debugf("Mount found: %v", m)
log.Debug().Msgf("Mount found: %v", m)
vols = append(vols, &volume.Volume{Name: name, Mountpoint: m.Path, CreatedAt: v.CreatedAt})
}
return &volume.ListResponse{Volumes: vols}, nil
}

//Get get info on the requested volume
func (d *RcloneDriver) Get(r *volume.GetRequest) (*volume.GetResponse, error) {
log.Debugf("Entering Get: name: %s", r.Name)
log.Debug().Msgf("Entering Get: name: %s", r.Name)
d.Lock()
defer d.Unlock()

v, ok := d.volumes[r.Name]
if !ok {
return nil, fmt.Errorf("volume %s not found", r.Name)
}
log.Debugf("Volume found: %v", v)
log.Debug().Msgf("Volume found: %v", v)

m, ok := d.mounts[v.Mount]
if !ok {
return nil, fmt.Errorf("volume mount %s not found for %s", v.Mount, r.Name)
}
log.Debugf("Mount found: %v", m)
log.Debug().Msgf("Mount found: %v", m)

return &volume.GetResponse{Volume: &volume.Volume{Name: r.Name, Mountpoint: m.Path, CreatedAt: v.CreatedAt}}, nil
}
Expand All @@ -190,20 +191,20 @@ func (d *RcloneDriver) Remove(r *volume.RemoveRequest) error {
//TODO remove related mounts
//TODO Error response from daemon: unable to remove volume: remove hubic-crypt: VolumeDriver.Remove: volume hubic-crypt is currently used by a container

log.Debugf("Entering Remove: name: %s", r.Name)
log.Debug().Msgf("Entering Remove: name: %s", r.Name)
d.Lock()
defer d.Unlock()
v, ok := d.volumes[r.Name]
if !ok {
return fmt.Errorf("volume %s not found", r.Name)
}
log.Debugf("Volume found: %v", v)
log.Debug().Msgf("Volume found: %v", v)

m, ok := d.mounts[v.Mount]
if !ok {
return fmt.Errorf("volume mount %s not found for %s", v.Mount, r.Name)
}
log.Debugf("Mount found: %v", m)
log.Debug().Msgf("Mount found: %v", m)

//disable check as it seems to fail and in this plugin v.Mount = r.Name
//if v.Connections == 0 {
Expand Down Expand Up @@ -240,28 +241,28 @@ func (d *RcloneDriver) Remove(r *volume.RemoveRequest) error {

//Path get path of the requested volume
func (d *RcloneDriver) Path(r *volume.PathRequest) (*volume.PathResponse, error) {
log.Debugf("Entering Path: name: %s", r.Name)
log.Debug().Msgf("Entering Path: name: %s", r.Name)
d.RLock()
defer d.RUnlock()

v, ok := d.volumes[r.Name]
if !ok {
return nil, fmt.Errorf("volume %s not found", r.Name)
}
log.Debugf("Volume found: %v", v)
log.Debug().Msgf("Volume found: %v", v)

m, ok := d.mounts[v.Mount]
if !ok {
return nil, fmt.Errorf("volume mount %s not found for %s", v.Mount, r.Name)
}
log.Debugf("Mount found: %v", m)
log.Debug().Msgf("Mount found: %v", m)

return &volume.PathResponse{Mountpoint: m.Path}, nil
}

//Mount mount the requested volume
func (d *RcloneDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error) {
log.Debugf("Entering Mount: %v", r)
log.Debug().Msgf("Entering Mount: %v", r)
d.Lock()
defer d.Unlock()

Expand Down Expand Up @@ -294,7 +295,7 @@ func (d *RcloneDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, err

//TODO write temp file before dans don't use base64
var cmd string
if log.GetLevel() == log.DebugLevel {
if zerolog.GlobalLevel() == zerolog.DebugLevel {
cmd = fmt.Sprintf("/usr/bin/rclone --log-file /var/log/rclone.%d.log --config=<(echo \"%s\"| base64 -d) %s mount \"%s\" \"%s\" & sleep 5s", time.Now().Unix(), v.Config, v.Args, v.Remote, m.Path)
} else {
cmd = fmt.Sprintf("/usr/bin/rclone --config=<(echo \"%s\"| base64 -d) %s mount \"%s\" \"%s\" & sleep 5s", v.Config, v.Args, v.Remote, m.Path)
Expand All @@ -307,7 +308,7 @@ func (d *RcloneDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, err
cmdCheck := fmt.Sprintf("mount | grep %s > /dev/null", m.Path)
folderMounted := false
for !folderMounted {
log.Debugf("Waiting for mount: %s", m.Path)
log.Debug().Msgf("Waiting for mount: %s", m.Path)
time.Sleep(5 * time.Second)
folderMounted = (nil == d.runCmd(cmdCheck))
}
Expand All @@ -325,7 +326,7 @@ func (d *RcloneDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, err

//Unmount unmount the requested volume
func (d *RcloneDriver) Unmount(r *volume.UnmountRequest) error {
log.Debugf("Entering Unmount: %v", r)
log.Debug().Msgf("Entering Unmount: %v", r)
d.Lock()
defer d.Unlock()

Expand Down Expand Up @@ -368,7 +369,7 @@ func (d *RcloneDriver) Unmount(r *volume.UnmountRequest) error {

//Capabilities Send capabilities of the local driver
func (d *RcloneDriver) Capabilities() *volume.CapabilitiesResponse {
log.Debugf("Entering Capabilities")
log.Debug().Msgf("Entering Capabilities")
return &volume.CapabilitiesResponse{
Capabilities: volume.Capability{
Scope: "local",
Expand Down
8 changes: 4 additions & 4 deletions rclone/driver/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os/exec"

"github.com/docker/go-plugins-helpers/volume"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
)

//RclonePersistence represent struct of persistence file
Expand All @@ -33,20 +33,20 @@ func (d *RcloneDriver) saveConfig() error {
}
b, err := json.Marshal(RclonePersistence{Version: CfgVersion, Volumes: d.volumes, Mounts: d.mounts})
if err != nil {
log.Warnf("Unable to encode persistence struct, %s", err.Error())
log.Warn().Err(err).Msg("Unable to encode persistence struct")
}
//log.Debug("Writing persistence struct, %v", b, d.volumes)
err = ioutil.WriteFile(CfgFolder+"/persistence.json", b, 0600)
if err != nil {
log.Warnf("Unable to write persistence struct, %s", err.Error())
log.Warn().Err(err).Msg("Unable to write persistence struct, %s")
}
//TODO display error messages
return err
}

// run deamon in context of this gvfs drive with custome env
func (d *RcloneDriver) runCmd(cmd string) error {
log.Debugf(cmd)
log.Debug().Msg(cmd)
/*
cli := exec.Command("/bin/bash", "-c", cmd)
stdoutStderr, err := cli.CombinedOutput()
Expand Down
Loading

0 comments on commit 664bfeb

Please sign in to comment.