Skip to content

Commit a8c87be

Browse files
author
Qingping Hou
committed
write out objects in 0666 mode
This is that we can run objinsync in a sidecar container under a different uid than the one used in the main application container
1 parent 34db797 commit a8c87be

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

pkg/sync/pull.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/hex"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"os"
109
"path/filepath"
1110
"strings"
@@ -151,9 +150,11 @@ func (self *Puller) downloadHandler(task DownloadTask, downloader GenericDownloa
151150
}
152151

153152
// create file
154-
tmpfile, err := ioutil.TempFile(self.workingDir, filepath.Base(task.LocalPath))
153+
tmpfileName := fmt.Sprintf("%x", md5.Sum([]byte(task.LocalPath)))
154+
tmpfilePath := filepath.Join(self.workingDir, tmpfileName)
155+
tmpfile, err := os.OpenFile(tmpfilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
155156
if err != nil {
156-
self.errMsgQueue <- fmt.Sprintf("Failed to create file for download: %v", err)
157+
self.errMsgQueue <- fmt.Sprintf("Failed to create temp file for download: %v", err)
157158
return
158159
}
159160
defer tmpfile.Close()
@@ -164,7 +165,7 @@ func (self *Puller) downloadHandler(task DownloadTask, downloader GenericDownloa
164165
})
165166

166167
// use rename to make file update atomic
167-
err = os.Rename(tmpfile.Name(), task.LocalPath)
168+
err = os.Rename(tmpfilePath, task.LocalPath)
168169
if err != nil {
169170
self.errMsgQueue <- fmt.Sprintf("Failed to replace file %s for download: %v", task.LocalPath, err)
170171
return

0 commit comments

Comments
 (0)