]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
sync: remove duplication when setting path to temporary file
authorSimon Ruderich <simon@ruderich.org>
Sun, 4 Apr 2021 08:43:19 +0000 (10:43 +0200)
committerSimon Ruderich <simon@ruderich.org>
Mon, 5 Apr 2021 07:41:12 +0000 (09:41 +0200)
cmd/safcm-remote/sync/files.go

index 12508ce08c2f7e7d2c17b74dca980285ec01f334..158b5539274f3b54fb1f3671190594a51976e58d 100644 (file)
@@ -328,16 +328,16 @@ reopen:
        }
 
        dir := filepath.Dir(file.Path)
        }
 
        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",
 
        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
                }
                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,
                // 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 {
                debugf("creating temporary symlink %q", tmpPath)
                err := os.Symlink(string(file.Data), tmpPath)
                if err != nil {