@@ -87,27 +87,32 @@ func (b *dropboxStorage) Name() string {
8787}
8888
8989// Copy copies the given file to the WebDav storage backend.
90- func (b * dropboxStorage ) Copy (file string ) error {
90+ func (b * dropboxStorage ) Copy (file string ) ( returnErr error ) {
9191 _ , name := path .Split (file )
9292
9393 folderArg := files .NewCreateFolderArg (b .DestinationPath )
9494 if _ , err := b .client .CreateFolderV2 (folderArg ); err != nil {
9595 switch err := err .(type ) {
9696 case files.CreateFolderV2APIError :
9797 if err .EndpointError .Path .Tag != files .WriteErrorConflict {
98- return errwrap .Wrap (err , fmt .Sprintf ("error creating directory '%s'" , b .DestinationPath ))
98+ returnErr = errwrap .Wrap (err , fmt .Sprintf ("error creating directory '%s'" , b .DestinationPath ))
99+ return
99100 }
100101 b .Log (storage .LogLevelInfo , b .Name (), "Destination path '%s' already exists, no new directory required." , b .DestinationPath )
101102 default :
102- return errwrap .Wrap (err , fmt .Sprintf ("error creating directory '%s'" , b .DestinationPath ))
103+ returnErr = errwrap .Wrap (err , fmt .Sprintf ("error creating directory '%s'" , b .DestinationPath ))
104+ return
103105 }
104106 }
105107
106108 r , err := os .Open (file )
107109 if err != nil {
108- return errwrap .Wrap (err , "error opening the file to be uploaded" )
110+ returnErr = errwrap .Wrap (err , "error opening the file to be uploaded" )
111+ return
109112 }
110- defer r .Close ()
113+ defer func () {
114+ returnErr = r .Close ()
115+ }()
111116
112117 // Start new upload session and get session id
113118 b .Log (storage .LogLevelInfo , b .Name (), "Starting upload session for backup '%s' at path '%s'." , file , b .DestinationPath )
@@ -116,7 +121,8 @@ func (b *dropboxStorage) Copy(file string) error {
116121 uploadSessionStartArg := files .NewUploadSessionStartArg ()
117122 uploadSessionStartArg .SessionType = & files.UploadSessionType {Tagged : dropbox.Tagged {Tag : files .UploadSessionTypeConcurrent }}
118123 if res , err := b .client .UploadSessionStart (uploadSessionStartArg , nil ); err != nil {
119- return errwrap .Wrap (err , "error starting the upload session" )
124+ returnErr = errwrap .Wrap (err , "error starting the upload session" )
125+ return
120126 } else {
121127 sessionId = res .SessionId
122128 }
@@ -197,7 +203,8 @@ loop:
197203 files .NewCommitInfo (path .Join (b .DestinationPath , name )),
198204 ), nil )
199205 if err != nil {
200- return errwrap .Wrap (err , "error finishing the upload session" )
206+ returnErr = errwrap .Wrap (err , "error finishing the upload session" )
207+ return
201208 }
202209
203210 b .Log (storage .LogLevelInfo , b .Name (), "Uploaded a copy of backup '%s' at path '%s'." , file , b .DestinationPath )
0 commit comments