File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -144,10 +144,22 @@ func (w *Listener) save(file string, data []byte) error {
144
144
w .actives [w .relativePath (file )] = true
145
145
w .activesLock .Unlock ()
146
146
147
- err = afero .WriteFile (appFs , file , data , 0600 )
147
+ tmpf , err := afero .TempFile (appFs , "" , "katafygio" )
148
+ if err != nil {
149
+ return fmt .Errorf ("failed to create a temporary file: %v" , err )
150
+ }
148
151
152
+ _ , err = tmpf .Write (data )
149
153
if err != nil {
150
- return fmt .Errorf ("failed to write to %s on disk: %v" , file , err )
154
+ return fmt .Errorf ("failed to write to %s on disk: %v" , tmpf .Name (), err )
155
+ }
156
+
157
+ if err := tmpf .Close (); err != nil {
158
+ return fmt .Errorf ("failed to close a temporary file: %v" , err )
159
+ }
160
+
161
+ if err := appFs .Rename (tmpf .Name (), file ); err != nil {
162
+ return fmt .Errorf ("failed to rename %s to %s: %v" , tmpf .Name (), file , err )
151
163
}
152
164
153
165
return nil
You can’t perform that action at this time.
0 commit comments