@cryptotaxi247 / kubo / commits / 0a17fc876

clean up tmp file

Signed-off-by: Tiger <rbalajis25@gmail.com>

Tiger committed May 10, 2020 at 18:04 UTC 0a17fc87642a8677fa4844904043cf7e318145f8
1 file changed +10 -1
repo/fsrepo/fsrepo.go
+10 -1
@@ -374,7 +374,16 @@ func (r *FSRepo) SetAPIAddr(addr ma.Multiaddr) error {
374 }
375
376 // Atomically rename the temp file to the correct file name.
377 - return os.Rename(filepath.Join(r.path, "."+apiFile+".tmp"), filepath.Join(r.path, apiFile))
377 + if err = os.Rename(filepath.Join(r.path, "."+apiFile+".tmp"), filepath.Join(r.path,
378 + apiFile)); err == nil {
379 + return nil
380 + }
381 + // Remove the temp file when rename return error
382 + if err1 := os.Remove(filepath.Join(r.path, "."+apiFile+".tmp")); err1 != nil {
383 + return fmt.Errorf("File Rename error: %s, File remove error: %s", err.Error(),
384 + err1.Error())
385 + }
386 + return err
387 }
388
389 // openConfig returns an error if the config file is not present.