From: Simon Ruderich Date: Sun, 4 Apr 2021 08:43:19 +0000 (+0200) Subject: sync: remove duplication when setting path to temporary file X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=commitdiff_plain;h=1639aafa622b89263864870cf1397f6d3440e5f7 sync: remove duplication when setting path to temporary file --- diff --git a/cmd/safcm-remote/sync/files.go b/cmd/safcm-remote/sync/files.go index 12508ce..158b553 100644 --- a/cmd/safcm-remote/sync/files.go +++ b/cmd/safcm-remote/sync/files.go @@ -328,16 +328,16 @@ reopen: } dir := filepath.Dir(file.Path) - base := filepath.Base(file.Path) + // Create hidden file which should be ignored by most other tools and + // thus not affect anything during creation + base := "." + filepath.Base(file.Path) var tmpPath string switch file.Mode.Type() { case 0: // regular file debugf("creating temporary file %q", - filepath.Join(dir, "."+base+"*")) - // Create hidden file which should be ignored by most other - // tools and thus not affect anything during creation - newFh, err := os.CreateTemp(dir, "."+base) + filepath.Join(dir, base+"*")) + newFh, err := os.CreateTemp(dir, base) if err != nil { return err } @@ -381,7 +381,7 @@ reopen: // Similar to os.CreateTemp() but for symlinks which we cannot // open as file tmpPath = filepath.Join(dir, - "."+base+strconv.Itoa(rand.Int())) + base+strconv.Itoa(rand.Int())) debugf("creating temporary symlink %q", tmpPath) err := os.Symlink(string(file.Data), tmpPath) if err != nil {