mirror of https://github.com/docker/docs.git
azure: create temporary file next to destination
We were doing atomic file writes by writing to /tmp and moving to the actual destination, however some filesystems do not support copying from /tmpfs. Bumping the `go-autorest` dependency version to latest. Fixes #3313. Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
parent
af4f3828f6
commit
0376230a5f
|
|
@ -96,23 +96,23 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/Azure/go-autorest/autorest",
|
||||
"Comment": "v7.0.4",
|
||||
"Rev": "b01ec2b60f95678fa759f796bac3c6b9bceaead4"
|
||||
"Comment": "v7.0.4-6-gec603a8",
|
||||
"Rev": "ec603a8ea5ffc45df35c7d948d9acfd6cbc07b46"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/Azure/go-autorest/autorest/azure",
|
||||
"Comment": "v7.0.4",
|
||||
"Rev": "b01ec2b60f95678fa759f796bac3c6b9bceaead4"
|
||||
"Comment": "v7.0.4-6-gec603a8",
|
||||
"Rev": "ec603a8ea5ffc45df35c7d948d9acfd6cbc07b46"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/Azure/go-autorest/autorest/date",
|
||||
"Comment": "v7.0.4",
|
||||
"Rev": "b01ec2b60f95678fa759f796bac3c6b9bceaead4"
|
||||
"Comment": "v7.0.4-6-gec603a8",
|
||||
"Rev": "ec603a8ea5ffc45df35c7d948d9acfd6cbc07b46"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/Azure/go-autorest/autorest/to",
|
||||
"Comment": "v7.0.4",
|
||||
"Rev": "b01ec2b60f95678fa759f796bac3c6b9bceaead4"
|
||||
"Comment": "v7.0.4-6-gec603a8",
|
||||
"Rev": "ec603a8ea5ffc45df35c7d948d9acfd6cbc07b46"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/aws/aws-sdk-go/aws",
|
||||
|
|
|
|||
|
|
@ -34,13 +34,13 @@ func SaveToken(path string, mode os.FileMode, token Token) error {
|
|||
return fmt.Errorf("failed to create directory (%s) to store token in: %v", dir, err)
|
||||
}
|
||||
|
||||
newFile, err := ioutil.TempFile(os.TempDir(), "token")
|
||||
newFile, err := ioutil.TempFile(dir, "token")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create the temp file to write the token: %v", err)
|
||||
}
|
||||
tempPath := newFile.Name()
|
||||
|
||||
if json.NewEncoder(newFile).Encode(token); err != nil {
|
||||
if err := json.NewEncoder(newFile).Encode(token); err != nil {
|
||||
return fmt.Errorf("failed to encode token to file (%s) while saving token: %v", tempPath, err)
|
||||
}
|
||||
if err := newFile.Close(); err != nil {
|
||||
|
|
@ -49,7 +49,7 @@ func SaveToken(path string, mode os.FileMode, token Token) error {
|
|||
|
||||
// Atomic replace to avoid multi-writer file corruptions
|
||||
if err := os.Rename(tempPath, path); err != nil {
|
||||
return fmt.Errorf("failed to move temporary token to desired output location. source=(%s). destination=(%s). error = %v", tempPath, path, err)
|
||||
return fmt.Errorf("failed to move temporary token to desired output location. src=%s dst=%s: %v", tempPath, path, err)
|
||||
}
|
||||
if err := os.Chmod(path, mode); err != nil {
|
||||
return fmt.Errorf("failed to chmod the token file %s: %v", path, err)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package autorest
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
|
@ -53,7 +54,9 @@ func (li LoggingInspector) WithInspection() PrepareDecorator {
|
|||
defer r.Body.Close()
|
||||
|
||||
r.Body = ioutil.NopCloser(io.TeeReader(r.Body, &body))
|
||||
r.Write(&b)
|
||||
if err := r.Write(&b); err != nil {
|
||||
return nil, fmt.Errorf("Failed to write response: %v", err)
|
||||
}
|
||||
|
||||
li.Logger.Printf(requestFormat, b.String())
|
||||
|
||||
|
|
@ -76,7 +79,9 @@ func (li LoggingInspector) ByInspecting() RespondDecorator {
|
|||
defer resp.Body.Close()
|
||||
|
||||
resp.Body = ioutil.NopCloser(io.TeeReader(resp.Body, &body))
|
||||
resp.Write(&b)
|
||||
if err := resp.Write(&b); err != nil {
|
||||
return fmt.Errorf("Failed to write response: %v", err)
|
||||
}
|
||||
|
||||
li.Logger.Printf(responseFormat, b.String())
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,9 @@ func ByClosing() RespondDecorator {
|
|||
return ResponderFunc(func(resp *http.Response) error {
|
||||
err := r.Respond(resp)
|
||||
if resp != nil && resp.Body != nil {
|
||||
resp.Body.Close()
|
||||
if err := resp.Body.Close(); err != nil {
|
||||
return fmt.Errorf("Error closing the response body: %v", err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
|
@ -109,7 +111,9 @@ func ByClosingIfError() RespondDecorator {
|
|||
return ResponderFunc(func(resp *http.Response) error {
|
||||
err := r.Respond(resp)
|
||||
if err != nil && resp != nil && resp.Body != nil {
|
||||
resp.Body.Close()
|
||||
if err := resp.Body.Close(); err != nil {
|
||||
return fmt.Errorf("Error closing the response body: %v", err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func SendWithSender(s Sender, r *http.Request, decorators ...SendDecorator) (*ht
|
|||
func AfterDelay(d time.Duration) SendDecorator {
|
||||
return func(s Sender) Sender {
|
||||
return SenderFunc(func(r *http.Request) (*http.Response, error) {
|
||||
if DelayForBackoff(d, 1, r.Cancel) != nil {
|
||||
if !DelayForBackoff(d, 1, r.Cancel) {
|
||||
return nil, fmt.Errorf("autorest: AfterDelay canceled before full delay")
|
||||
}
|
||||
return s.Do(r)
|
||||
|
|
@ -223,15 +223,12 @@ func WithLogging(logger *log.Logger) SendDecorator {
|
|||
|
||||
// DelayForBackoff invokes time.After for the supplied backoff duration raised to the power of
|
||||
// passed attempt (i.e., an exponential backoff delay). Backoff may be zero. The delay may be
|
||||
// canceled by closing the passed channel.
|
||||
func DelayForBackoff(backoff time.Duration, attempt int, cancel <-chan struct{}) error {
|
||||
if cancel == nil {
|
||||
cancel = make(chan struct{})
|
||||
}
|
||||
// canceled by closing the passed channel. If terminated early, returns false.
|
||||
func DelayForBackoff(backoff time.Duration, attempt int, cancel <-chan struct{}) bool {
|
||||
select {
|
||||
case <-time.After(time.Duration(math.Pow(float64(backoff), float64(attempt)))):
|
||||
return true
|
||||
case <-cancel:
|
||||
return fmt.Errorf("autorest: Delay canceled")
|
||||
return false
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue