From bd13f4727b857958572845b359f9d3a038376bdc Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sat, 18 Oct 2025 08:52:51 +0200 Subject: [PATCH] Use 4 spaces per tab for Go files --- cmd/safcm-remote/main.go | 2 + cmd/safcm/config/commands.go | 2 + cmd/safcm/config/config.go | 2 + cmd/safcm/config/files.go | 21 ++- cmd/safcm/config/files_test.go | 2 + cmd/safcm/config/groups.go | 46 +++---- cmd/safcm/config/groups_test.go | 5 +- cmd/safcm/config/hosts.go | 16 +-- cmd/safcm/config/hosts_test.go | 2 + cmd/safcm/config/packages.go | 2 + cmd/safcm/config/permissions.go | 10 +- cmd/safcm/config/permissions_test.go | 6 +- cmd/safcm/config/services.go | 2 + cmd/safcm/config/templates.go | 12 +- cmd/safcm/config/templates_test.go | 6 +- cmd/safcm/config/triggers.go | 5 +- cmd/safcm/config/triggers_test.go | 6 +- cmd/safcm/fixperms.go | 7 +- cmd/safcm/main.go | 2 + cmd/safcm/main_sync_test.go | 14 +- cmd/safcm/remote.go | 2 + cmd/safcm/sync.go | 15 +-- cmd/safcm/sync_info.go | 2 + cmd/safcm/sync_info_test.go | 2 + cmd/safcm/sync_sync.go | 34 ++--- cmd/safcm/sync_sync_test.go | 9 +- cmd/safcm/sync_test.go | 2 + cmd/safcm/version.go | 6 +- frontend/changes.go | 39 +++--- frontend/changes_test.go | 6 +- frontend/conn.go | 2 + frontend/log.go | 6 +- frontend/log_test.go | 14 +- frontend/loop.go | 12 +- frontend/term.go | 2 + frontend/term_test.go | 2 + gob.go | 6 +- log.go | 2 + remote/ainsl/ainsl.go | 32 ++--- remote/ainsl/ainsl_test.go | 5 +- remote/info/info.go | 9 +- remote/log/logger.go | 2 + remote/main.go | 8 +- remote/run/cmd.go | 14 +- remote/run/runner.go | 2 + remote/sync/commands.go | 14 +- remote/sync/commands_test.go | 6 +- remote/sync/files.go | 186 +++++++++++++-------------- remote/sync/files_compat_windows.go | 2 + remote/sync/files_test.go | 28 ++-- remote/sync/filetest/filetest.go | 2 + remote/sync/packages.go | 2 + remote/sync/packages_debian.go | 11 +- remote/sync/packages_debian_test.go | 6 +- remote/sync/services.go | 2 + remote/sync/services_systemd.go | 34 ++--- remote/sync/services_systemd_test.go | 6 +- remote/sync/sync.go | 2 + remote/sync/sync_test.go | 2 + remote/sync/triggers.go | 8 +- remote/sync/triggers_test.go | 2 + rpc/conn.go | 6 +- rpc/dial.go | 40 +++--- testutil/testutil.go | 5 +- types.go | 2 + 65 files changed, 406 insertions(+), 365 deletions(-) diff --git a/cmd/safcm-remote/main.go b/cmd/safcm-remote/main.go index 09ef818..6880ce0 100644 --- a/cmd/safcm-remote/main.go +++ b/cmd/safcm-remote/main.go @@ -12,3 +12,5 @@ import ( func main() { remote.Main() } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/commands.go b/cmd/safcm/config/commands.go index b479fce..673c539 100644 --- a/cmd/safcm/config/commands.go +++ b/cmd/safcm/config/commands.go @@ -40,3 +40,5 @@ func LoadCommands(group string) ([]*safcm.Command, error) { } return res, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/config.go b/cmd/safcm/config/config.go index 7ec8d4f..43214ea 100644 --- a/cmd/safcm/config/config.go +++ b/cmd/safcm/config/config.go @@ -44,3 +44,5 @@ func LoadConfig() (*Config, error) { } return &cfg, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/files.go b/cmd/safcm/config/files.go index a488974..66b9c60 100644 --- a/cmd/safcm/config/files.go +++ b/cmd/safcm/config/files.go @@ -47,18 +47,16 @@ via "safcm fixperms". perm := FileModeToFullPerm(info.Mode()) var data []byte - // See errMsg above. If a user stores a file with stricter - // permissions they could assume that these permissions are - // respected. This is not the case. + // See errMsg above. If a user stores a file with stricter permissions + // they could assume that these permissions are respected. This is not + // the case. if typ == 0 /* regular file */ { if windows { perm = 0644 - // 0755 must be set via permissions.yaml if - // windows is used + // 0755 must be set via permissions.yaml if windows is used } if perm != 0644 && perm != 0755 { - return fmt.Errorf( - "%q: invalid permissions %#o%s", + return fmt.Errorf("%q: invalid permissions %#o%s", path, perm, errMsg) } data, err = os.ReadFile(path) @@ -70,8 +68,7 @@ via "safcm fixperms". perm = 0755 } if perm != 0755 { - return fmt.Errorf( - "%q: invalid permissions %#o%s", + return fmt.Errorf("%q: invalid permissions %#o%s", path, perm, errMsg) } } else if typ == fs.ModeSymlink { @@ -85,8 +82,8 @@ via "safcm fixperms". return fmt.Errorf("%q: file type not supported", path) } - // Convert to absolute and slash-separated path as used on the - // target host + // Convert to absolute and slash-separated path as used on the target + // host x, err := filepath.Rel(basePath, path) if err != nil { return err @@ -110,3 +107,5 @@ via "safcm fixperms". } return files, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/files_test.go b/cmd/safcm/config/files_test.go index de9a2ad..1942380 100644 --- a/cmd/safcm/config/files_test.go +++ b/cmd/safcm/config/files_test.go @@ -204,3 +204,5 @@ host3.example.net }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/groups.go b/cmd/safcm/config/groups.go index d77dbbe..626c053 100644 --- a/cmd/safcm/config/groups.go +++ b/cmd/safcm/config/groups.go @@ -49,24 +49,20 @@ func LoadGroups(cfg *Config, hosts *Hosts) (map[string][]string, error) { errPrefix, name) } if hosts.Map[name] != nil || - hosts.Map[strings.TrimSuffix(name, - GroupRemoveSuffix)] != nil { - return nil, fmt.Errorf( - "%s conflict with existing host", + hosts.Map[strings.TrimSuffix(name, GroupRemoveSuffix)] != nil { + return nil, fmt.Errorf("%s conflict with existing host", errPrefix) } if strings.HasPrefix(name, GroupDetectedPrefix) { - return nil, fmt.Errorf( - "%s name must not start with %q "+ - "(reserved for detected groups)", + return nil, fmt.Errorf("%s name must not start with %q "+ + "(reserved for detected groups)", errPrefix, GroupDetectedPrefix) } if !groupNameRegexp.MatchString( strings.TrimSuffix(name, GroupRemoveSuffix)) { - return nil, fmt.Errorf( - "%s name contains invalid characters "+ - "(must match %s)", + return nil, fmt.Errorf("%s name contains invalid characters "+ + "(must match %s)", errPrefix, groupNameRegexp) } @@ -74,11 +70,10 @@ func LoadGroups(cfg *Config, hosts *Hosts) (map[string][]string, error) { if x == GroupAll { continue } - // Don't validate against groupNameRegexp because - // hosts have less strict restrictions. + // Don't validate against groupNameRegexp because hosts have less + // strict restrictions. if strings.Contains(x, GroupSpecialSeparator) { - return nil, fmt.Errorf( - "%s member %q must not contain %q", + return nil, fmt.Errorf("%s member %q must not contain %q", errPrefix, x, GroupSpecialSeparator) } if strings.HasPrefix(x, GroupDetectedPrefix) { @@ -87,8 +82,7 @@ func LoadGroups(cfg *Config, hosts *Hosts) (map[string][]string, error) { if hosts.Map[x] != nil || groups[x] != nil { continue } - return nil, fmt.Errorf("%s member %q not found", - errPrefix, x) + return nil, fmt.Errorf("%s member %q not found", errPrefix, x) } } @@ -100,8 +94,7 @@ func LoadGroups(cfg *Config, hosts *Hosts) (map[string][]string, error) { continue } if strings.Contains(x, GroupSpecialSeparator) { - return nil, fmt.Errorf("%s invalid group name %q", - errPrefix, x) + return nil, fmt.Errorf("%s invalid group name %q", errPrefix, x) } if strings.HasPrefix(x, GroupDetectedPrefix) { continue @@ -109,8 +102,7 @@ func LoadGroups(cfg *Config, hosts *Hosts) (map[string][]string, error) { if groups[x] != nil { continue } - return nil, fmt.Errorf("%s group %q does not exist", - errPrefix, x) + return nil, fmt.Errorf("%s group %q does not exist", errPrefix, x) } return groups, nil @@ -139,8 +131,7 @@ func ResolveHostGroups(host string, groups map[string][]string, if x == host || detectedGroupsMap[x] || x == GroupAll { return true } - if lookup(x, depth+1) && - !lookup(x+GroupRemoveSuffix, depth+1) { + if lookup(x, depth+1) && !lookup(x+GroupRemoveSuffix, depth+1) { return true } } @@ -165,8 +156,7 @@ func ResolveHostGroups(host string, groups map[string][]string, } } if cycle != nil { - return nil, fmt.Errorf( - "groups.yaml: cycle while expanding group %q", + return nil, fmt.Errorf("groups.yaml: cycle while expanding group %q", *cycle) } @@ -194,12 +184,10 @@ func TransitivelyDetectedGroups(groups map[string][]string) map[string]bool { change := false for group, members := range work { for _, x := range members { - if !detected[x] && !strings.HasPrefix(x, - GroupDetectedPrefix) { + if !detected[x] && !strings.HasPrefix(x, GroupDetectedPrefix) { continue } - detected[strings.TrimSuffix(group, - GroupRemoveSuffix)] = true + detected[strings.TrimSuffix(group, GroupRemoveSuffix)] = true delete(work, group) change = true } @@ -210,3 +198,5 @@ func TransitivelyDetectedGroups(groups map[string][]string) map[string]bool { } return detected } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/groups_test.go b/cmd/safcm/config/groups_test.go index 6f08d1c..bba47d9 100644 --- a/cmd/safcm/config/groups_test.go +++ b/cmd/safcm/config/groups_test.go @@ -285,8 +285,7 @@ func TestResolveHostGroups(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - res, err := ResolveHostGroups(tc.host, allGroups, - tc.detected) + res, err := ResolveHostGroups(tc.host, allGroups, tc.detected) testutil.AssertEqual(t, "res", res, tc.exp) testutil.AssertErrorEqual(t, "err", err, tc.expErr) }) @@ -435,3 +434,5 @@ func TestTransitivelyDetectedGroups(t *testing.T) { }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/hosts.go b/cmd/safcm/config/hosts.go index 457f1e3..4c36718 100644 --- a/cmd/safcm/config/hosts.go +++ b/cmd/safcm/config/hosts.go @@ -41,25 +41,21 @@ func LoadHosts() (*Hosts, error) { for _, x := range hostList { errPrefix := fmt.Sprintf("%s: host %q:", path, x.Name) if x.Name == GroupAll { - return nil, fmt.Errorf( - "%s conflict with pre-defined group %q", + return nil, fmt.Errorf("%s conflict with pre-defined group %q", errPrefix, x.Name) } if strings.HasPrefix(x.Name, GroupDetectedPrefix) { - return nil, fmt.Errorf( - "%s name must not start with %q "+ - "(reserved for detected groups)", + return nil, fmt.Errorf("%s name must not start with %q "+ + "(reserved for detected groups)", errPrefix, GroupDetectedPrefix) } if strings.Contains(x.Name, GroupSpecialSeparator) { - return nil, fmt.Errorf( - "%s name must not contain %q", + return nil, fmt.Errorf("%s name must not contain %q", errPrefix, GroupSpecialSeparator) } if hostMap[x.Name] != nil { - return nil, fmt.Errorf("%s host name already exists", - errPrefix) + return nil, fmt.Errorf("%s host name already exists", errPrefix) } hostMap[x.Name] = x } @@ -69,3 +65,5 @@ func LoadHosts() (*Hosts, error) { Map: hostMap, }, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/hosts_test.go b/cmd/safcm/config/hosts_test.go index 0eebc56..c55b766 100644 --- a/cmd/safcm/config/hosts_test.go +++ b/cmd/safcm/config/hosts_test.go @@ -75,3 +75,5 @@ func TestLoadHosts(t *testing.T) { }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/packages.go b/cmd/safcm/config/packages.go index 6f87c5a..c936081 100644 --- a/cmd/safcm/config/packages.go +++ b/cmd/safcm/config/packages.go @@ -41,3 +41,5 @@ func LoadPackages(group string) ([]string, error) { return res, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/permissions.go b/cmd/safcm/config/permissions.go index 8a8ae64..3a92aca 100644 --- a/cmd/safcm/config/permissions.go +++ b/cmd/safcm/config/permissions.go @@ -37,8 +37,7 @@ func LoadPermissions(group string, files map[string]*safcm.File) error { for p, x := range cfg { _, ok := files[p] if !ok { - return fmt.Errorf("%s: %q does not exist in files/", - path, p) + return fmt.Errorf("%s: %q does not exist in files/", path, p) } xs := strings.Fields(x) @@ -62,9 +61,8 @@ func LoadPermissions(group string, files map[string]*safcm.File) error { file := files[p] // Sanity check if file.Mode.Perm()&0111 != 0 && perm&0111 == 0 { - return fmt.Errorf( - "%s: %q: trying to remove +x from file, "+ - "manually chmod -x in files/", + return fmt.Errorf("%s: %q: trying to remove +x from file, "+ + "manually chmod -x in files/", path, p) } file.Mode = file.Mode.Type() | FullPermToFileMode(int(perm)) @@ -104,3 +102,5 @@ func FullPermToFileMode(perm int) fs.FileMode { } return mode } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/permissions_test.go b/cmd/safcm/config/permissions_test.go index 3c043f0..4a15a15 100644 --- a/cmd/safcm/config/permissions_test.go +++ b/cmd/safcm/config/permissions_test.go @@ -241,8 +241,8 @@ host3.example.net for _, tc := range tests { t.Run(tc.group, func(t *testing.T) { - // Use LoadFiles() so we work on real data and don't - // make any mistakes generating it + // Use LoadFiles() so we work on real data and don't make any + // mistakes generating it files, err := LoadFiles(tc.group) if err != nil { t.Fatalf("err = %#v, want nil", err) @@ -254,3 +254,5 @@ host3.example.net }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/services.go b/cmd/safcm/config/services.go index 84a85d3..6f921fd 100644 --- a/cmd/safcm/config/services.go +++ b/cmd/safcm/config/services.go @@ -41,3 +41,5 @@ func LoadServices(group string) ([]string, error) { return res, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/templates.go b/cmd/safcm/config/templates.go index b03b28e..fd46182 100644 --- a/cmd/safcm/config/templates.go +++ b/cmd/safcm/config/templates.go @@ -53,12 +53,10 @@ func LoadTemplates(group string, files map[string]*safcm.File, for _, x := range templates { f, ok := files[x] if !ok { - return fmt.Errorf("%s: %q does not exist in files/", - path, x) + return fmt.Errorf("%s: %q does not exist in files/", path, x) } if f.Mode.Type() != 0 /* regular file */ { - return fmt.Errorf("%s: %q is not a regular file", - path, x) + return fmt.Errorf("%s: %q is not a regular file", path, x) } tmplPath := filepath.Join(group, "files", x) @@ -102,8 +100,8 @@ func (t *templateArgs) IsHost(host string) bool { return t.host == host } func (t *templateArgs) InGroup(group string) bool { - // Don't permit invalid groups to detect typos; detected groups cannot - // be checked + // Don't permit invalid groups to detect typos; detected groups cannot be + // checked if group != GroupAll && !t.allGroups[group] && !t.allHosts[group] && @@ -112,3 +110,5 @@ func (t *templateArgs) InGroup(group string) bool { } return t.groups[group] } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/templates_test.go b/cmd/safcm/config/templates_test.go index ff62cdc..a305782 100644 --- a/cmd/safcm/config/templates_test.go +++ b/cmd/safcm/config/templates_test.go @@ -228,8 +228,8 @@ host1.example.org for _, tc := range tests { t.Run(tc.group, func(t *testing.T) { - // Use LoadFiles() so we work on real data and don't - // make any mistakes generating it + // Use LoadFiles() so we work on real data and don't make any + // mistakes generating it files, err := LoadFiles(tc.group) if err != nil { t.Fatalf("err = %#v, want nil", err) @@ -242,3 +242,5 @@ host1.example.org }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/triggers.go b/cmd/safcm/config/triggers.go index da91558..de1ed61 100644 --- a/cmd/safcm/config/triggers.go +++ b/cmd/safcm/config/triggers.go @@ -34,11 +34,12 @@ func LoadTriggers(group string, files map[string]*safcm.File) error { for p, x := range triggers { f, ok := files[p] if !ok { - return fmt.Errorf("%s: %q does not exist in files/", - path, p) + return fmt.Errorf("%s: %q does not exist in files/", path, p) } f.TriggerCommands = x } return nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/config/triggers_test.go b/cmd/safcm/config/triggers_test.go index c395249..f15bc66 100644 --- a/cmd/safcm/config/triggers_test.go +++ b/cmd/safcm/config/triggers_test.go @@ -123,8 +123,8 @@ host3.example.net for _, tc := range tests { t.Run(tc.group, func(t *testing.T) { - // Use LoadFiles() so we work on real data and don't - // make any mistakes generating it + // Use LoadFiles() so we work on real data and don't make any + // mistakes generating it files, err := LoadFiles(tc.group) if err != nil { t.Fatalf("err = %#v, want nil", err) @@ -136,3 +136,5 @@ host3.example.net }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/fixperms.go b/cmd/safcm/fixperms.go index 738261e..cebe6f6 100644 --- a/cmd/safcm/fixperms.go +++ b/cmd/safcm/fixperms.go @@ -64,9 +64,8 @@ func fixpermsWalkDirFunc(path string, d fs.DirEntry, err error) error { perm = 0644 } log.Printf("chmodding %q to %#o", path, perm) - // This is safe because perm does not include - // setuid/setgid/sticky which use different values in - // FileMode. + // This is safe because perm does not include setuid/setgid/sticky + // which use different values in FileMode. err := chmodNoFollow(path, fs.FileMode(perm)) if err != nil { return err @@ -102,3 +101,5 @@ func chmodNoFollow(path string, mode fs.FileMode) error { return nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/main.go b/cmd/safcm/main.go index 2a9b11e..f1d5f9e 100644 --- a/cmd/safcm/main.go +++ b/cmd/safcm/main.go @@ -64,3 +64,5 @@ func LoadBaseFiles() (*config.Config, *config.Hosts, map[string][]string, } return cfg, hosts, groups, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/main_sync_test.go b/cmd/safcm/main_sync_test.go index b31b2ef..ac1ace0 100644 --- a/cmd/safcm/main_sync_test.go +++ b/cmd/safcm/main_sync_test.go @@ -140,8 +140,8 @@ func TestSyncSshEndToEnd(t *testing.T) { nil, }, - // NOTE: We use -n on regular runs to prevent changing - // anything important on the host when running as root! + // NOTE: We use -n on regular runs to prevent changing anything + // important on the host when running as root! { "no changes (dry-run)", @@ -336,8 +336,8 @@ executed 2 command(s): // Fake $PATH so safcm cannot find the `ssh` binary. t.Setenv("PATH", "") - cmd := exec.Command("../../../../../safcm", - "sync", "-n", "no-settings.example.org") + cmd := exec.Command("../../../../../safcm", "sync", "-n", + "no-settings.example.org") _, err = cmd.CombinedOutput() if err == nil { t.Errorf("err = nil") @@ -358,8 +358,8 @@ executed 2 command(s): var tmp []string for _, x := range strings.Split(string(out), "\n") { - // Strip parts which change on each run (LOG) - // or depending on the system (DET) + // Strip parts which change on each run (LOG) or depending on + // the system (DET) x = logRegexp.ReplaceAllString(x, "") x = detectedRegexp.ReplaceAllString(x, "") tmp = append(tmp, x) @@ -373,3 +373,5 @@ executed 2 command(s): _ = os.Remove(remotePath) } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/remote.go b/cmd/safcm/remote.go index 6f87d20..fc29494 100644 --- a/cmd/safcm/remote.go +++ b/cmd/safcm/remote.go @@ -14,3 +14,5 @@ import ( // //go:embed remote/* var RemoteHelpers embed.FS + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/sync.go b/cmd/safcm/sync.go index 232ff6d..13a9c9a 100644 --- a/cmd/safcm/sync.go +++ b/cmd/safcm/sync.go @@ -38,8 +38,7 @@ type Sync struct { func MainSync(args []string) error { flag.Usage = func() { - fmt.Fprintf(os.Stderr, - "usage: %s sync [] \n", + fmt.Fprintf(os.Stderr, "usage: %s sync [] \n", args[0]) flag.PrintDefaults() } @@ -110,8 +109,7 @@ func MainSync(args []string) error { isTTY: isTTY, loop: loop, } - s.logFunc = func(level safcm.LogLevel, escaped bool, - msg string) { + s.logFunc = func(level safcm.LogLevel, escaped bool, msg string) { s.loop.Log(s, level, escaped, msg) } hosts = append(hosts, s) @@ -120,8 +118,8 @@ func MainSync(args []string) error { succ := loop.Run(hosts) if !succ { - // Exit instead of returning an error to prevent an extra log - // message from main() + // Exit instead of returning an error to prevent an extra log message + // from main() os.Exit(1) } return nil @@ -189,8 +187,7 @@ are only available after the hosts were contacted. var unmatched []string for x := range nameMap { if !nameMatched[x] { - unmatched = append(unmatched, - fmt.Sprintf("%q", x)) + unmatched = append(unmatched, fmt.Sprintf("%q", x)) } } sort.Strings(unmatched) @@ -249,3 +246,5 @@ func (s *Sync) logDebugf(format string, a ...interface{}) { func (s *Sync) logVerbosef(format string, a ...interface{}) { s.log(safcm.LogVerbose, false, fmt.Sprintf(format, a...)) } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/sync_info.go b/cmd/safcm/sync_info.go index a298ff3..ed443b1 100644 --- a/cmd/safcm/sync_info.go +++ b/cmd/safcm/sync_info.go @@ -50,3 +50,5 @@ func hostInfoDetectedGroupName(x string) string { x = config.GroupDetectedPrefix + "_" + x return x } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/sync_info_test.go b/cmd/safcm/sync_info_test.go index 355db6d..e36c0c3 100644 --- a/cmd/safcm/sync_info_test.go +++ b/cmd/safcm/sync_info_test.go @@ -73,3 +73,5 @@ func TestHostInfoRespToGroups(t *testing.T) { }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/sync_sync.go b/cmd/safcm/sync_sync.go index c76ec4a..dfb3386 100644 --- a/cmd/safcm/sync_sync.go +++ b/cmd/safcm/sync_sync.go @@ -55,16 +55,15 @@ func (s *Sync) hostSyncReq(detectedGroups []string) ( return empty, err } { - // Don't leak internal group priority which is confusing - // without knowing the implementation details. + // Don't leak internal group priority which is confusing without + // knowing the implementation details. groupsSorted := make([]string, len(groups)) copy(groupsSorted, groups) sort.Strings(groupsSorted) - s.logVerbosef("host groups: %s", - strings.Join(groupsSorted, " ")) + s.logVerbosef("host groups: %s", strings.Join(groupsSorted, " ")) - // Don't leak internal priority values. Instead, order groups - // by priority. + // Don't leak internal priority values. Instead, order groups by + // priority. var priorities []string for x := range groupPriority { priorities = append(priorities, x) @@ -98,8 +97,8 @@ func (s *Sync) hostSyncReq(detectedGroups []string) ( if err != nil { return empty, err } - err = config.LoadTemplates(group, files, - s.host.Name, groups, s.allHosts, s.allGroups) + err = config.LoadTemplates(group, files, s.host.Name, groups, + s.allHosts, s.allGroups) if err != nil { return empty, err } @@ -108,8 +107,7 @@ func (s *Sync) hostSyncReq(detectedGroups []string) ( return empty, err } for k, v := range files { - err := s.checkFileConflict(group, k, v, - allFiles, groupPriority) + err := s.checkFileConflict(group, k, v, allFiles, groupPriority) if err != nil { return empty, err } @@ -169,8 +167,8 @@ func (s *Sync) hostSyncReq(detectedGroups []string) ( func (s *Sync) resolveHostGroups(detectedGroups []string) ( []string, map[string]int, error) { - groups, err := config.ResolveHostGroups(s.host.Name, - s.allGroups, detectedGroups) + groups, err := config.ResolveHostGroups(s.host.Name, s.allGroups, + detectedGroups) if err != nil { return nil, nil, err } @@ -222,8 +220,8 @@ func (s *Sync) checkFileConflict(group string, path string, file *safcm.File, panic("invalid group priorities") } - // Directories with default permissions and no triggers do not count - // as conflict + // Directories with default permissions and no triggers do not count as + // conflict if file.Mode.IsDir() && file.Mode == old.Mode && config.FileModeToFullPerm(file.Mode) == 0755 && file.TriggerCommands == nil && old.TriggerCommands == nil { @@ -247,9 +245,9 @@ func resolveFileDirConflicts(files map[string]*safcm.File) { // Slash separated paths are used for the configuration const sep = "/" - // Remove invalid paths which can result from group_priority - // overriding paths from another group (e.g. "/foo" as file from one - // group and "/foo/bar" from another). + // Remove invalid paths which can result from group_priority overriding + // paths from another group (e.g. "/foo" as file from one group and + // "/foo/bar" from another). var last *safcm.File for _, x := range paths { file := files[x] @@ -262,3 +260,5 @@ func resolveFileDirConflicts(files map[string]*safcm.File) { last = file } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/sync_sync_test.go b/cmd/safcm/sync_sync_test.go index 6493fe3..8f377ac 100644 --- a/cmd/safcm/sync_sync_test.go +++ b/cmd/safcm/sync_sync_test.go @@ -27,8 +27,8 @@ func TestHostSyncReq(t *testing.T) { expErr error }{ - // NOTE: Also update MsgSyncReq in safcm-remote test cases - // changing the MsgSyncReq struct! + // NOTE: Also update MsgSyncReq in safcm-remote test cases changing + // the MsgSyncReq struct! { "project: host1", @@ -367,8 +367,9 @@ func TestHostSyncReq(t *testing.T) { res, err := s.hostSyncReq(tc.detected) testutil.AssertEqual(t, "res", res, tc.exp) testutil.AssertErrorEqual(t, "err", err, tc.expErr) - testutil.AssertEqual(t, "events", - events, tc.expEvents) + testutil.AssertEqual(t, "events", events, tc.expEvents) }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/sync_test.go b/cmd/safcm/sync_test.go index 8677412..cd1579d 100644 --- a/cmd/safcm/sync_test.go +++ b/cmd/safcm/sync_test.go @@ -168,3 +168,5 @@ are only available after the hosts were contacted. }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/cmd/safcm/version.go b/cmd/safcm/version.go index 8ff7298..06c5291 100644 --- a/cmd/safcm/version.go +++ b/cmd/safcm/version.go @@ -16,8 +16,8 @@ var ( ) func MainVersion() error { - fmt.Printf("safcm %s, compiled with %s\n", - versionGit, - versionGo) + fmt.Printf("safcm %s, compiled with %s\n", versionGit, versionGo) return nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/frontend/changes.go b/frontend/changes.go index 6dd01ce..3388b32 100644 --- a/frontend/changes.go +++ b/frontend/changes.go @@ -27,20 +27,16 @@ type Changes struct { func (c *Changes) FormatChanges(resp safcm.MsgSyncResp) string { var changes []string if len(resp.FileChanges) > 0 { - changes = append(changes, - c.FormatFileChanges(resp.FileChanges)) + changes = append(changes, c.FormatFileChanges(resp.FileChanges)) } if len(resp.PackageChanges) > 0 { - changes = append(changes, - c.FormatPackageChanges(resp.PackageChanges)) + changes = append(changes, c.FormatPackageChanges(resp.PackageChanges)) } if len(resp.ServiceChanges) > 0 { - changes = append(changes, - c.FormatServiceChanges(resp.ServiceChanges)) + changes = append(changes, c.FormatServiceChanges(resp.ServiceChanges)) } if len(resp.CommandChanges) > 0 { - changes = append(changes, - c.FormatCommandChanges(resp.CommandChanges)) + changes = append(changes, c.FormatCommandChanges(resp.CommandChanges)) } if len(changes) == 0 { // Notify user that the host was synced successfully @@ -48,10 +44,10 @@ func (c *Changes) FormatChanges(resp safcm.MsgSyncResp) string { } x := strings.Join(changes, "\n") - // If quiet is used and only commands without output were executed - // then don't prepend a newline so that the whole change output of a - // host fits in a single line. This makes the output much more - // readable with multiple hosts. + // If quiet is used and only commands without output were executed then + // don't prepend a newline so that the whole change output of a host fits + // in a single line. This makes the output much more readable with + // multiple hosts. if strings.Count(x, "\n") == 1 { return x } @@ -61,8 +57,7 @@ func (c *Changes) FormatChanges(resp safcm.MsgSyncResp) string { func (c *Changes) FormatFileChanges(changes []safcm.FileChange) string { var buf strings.Builder if c.DryRun { - fmt.Fprintf(&buf, "will change %d file(s): (dry-run)\n", - len(changes)) + fmt.Fprintf(&buf, "will change %d file(s): (dry-run)\n", len(changes)) } else { fmt.Fprintf(&buf, "changed %d file(s):\n", len(changes)) } @@ -167,8 +162,7 @@ func (c *Changes) FormatServiceChanges(changes []safcm.ServiceChange) string { info = append(info, "enabled") } fmt.Fprintf(&buf, "%s: %s\n", - c.FormatTarget(x.Name), - strings.Join(info, ", ")) + c.FormatTarget(x.Name), strings.Join(info, ", ")) } return buf.String() } @@ -180,14 +174,12 @@ func (c *Changes) FormatCommandChanges(changes []safcm.CommandChange) string { // output. This is useful as many commands will be used to enforce a // certain state (e.g. file not-present, `ainsl`, etc.) and are run on // each sync. Displaying them provides not much useful information. - // Instead, quiet shows them only when they produce output (e.g. - // `ainsl`, `rm -v`) and thus modify the host's state. + // Instead, quiet shows them only when they produce output (e.g. `ainsl`, + // `rm -v`) and thus modify the host's state. var noOutput int if c.Quiet { for _, x := range changes { - if x.Trigger == "" && - x.Error == "" && - x.Output == "" { + if x.Trigger == "" && x.Error == "" && x.Output == "" { noOutput++ } } @@ -225,8 +217,7 @@ func (c *Changes) FormatCommandChanges(changes []safcm.CommandChange) string { if x.Output != "" { // TODO: truncate very large outputs? x := indentBlock(x.Output, indent) - fmt.Fprintf(&buf, ":\n%s", - EscapeControlCharacters(c.IsTTY, x)) + fmt.Fprintf(&buf, ":\n%s", EscapeControlCharacters(c.IsTTY, x)) } fmt.Fprintf(&buf, "\n") } @@ -270,3 +261,5 @@ func indentBlock(x string, sep string) string { return sep + strings.Join(lines, "\n"+sep) } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/frontend/changes_test.go b/frontend/changes_test.go index e0f7e56..a038318 100644 --- a/frontend/changes_test.go +++ b/frontend/changes_test.go @@ -21,8 +21,8 @@ func TestFormatChanges(t *testing.T) { exp string }{ - // Just a few basic tests and border cases; see the other - // tests for more detailed tests of each format function + // Just a few basic tests and border cases; see the other tests for + // more detailed tests of each format function { "no changes", @@ -1220,3 +1220,5 @@ func TestFormatCommandChanges(t *testing.T) { }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/frontend/conn.go b/frontend/conn.go index 8546169..c2b7cfd 100644 --- a/frontend/conn.go +++ b/frontend/conn.go @@ -69,3 +69,5 @@ func (l *Loop) HostSyncMsg(host Host, conn *rpc.Conn, req safcm.MsgSyncReq) ( } return resp, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/frontend/log.go b/frontend/log.go index 4224996..41c10b6 100644 --- a/frontend/log.go +++ b/frontend/log.go @@ -98,10 +98,12 @@ func LogEvent(x Event, level safcm.LogLevel, isTTY bool, if color != 0 { host = ColorString(isTTY, color, host) } - // Make sure to escape control characters to prevent terminal - // injection attacks + // Make sure to escape control characters to prevent terminal injection + // attacks if !x.Escaped { data = EscapeControlCharacters(isTTY, data) } log.Printf("%-9s [%s] %s", prefix, host, data) } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/frontend/log_test.go b/frontend/log_test.go index 12fa5be..d67a899 100644 --- a/frontend/log_test.go +++ b/frontend/log_test.go @@ -156,8 +156,7 @@ func TestLogEvent(t *testing.T) { }, safcm.LogDebug3, false, - fmt.Sprintf("[INVALID=%d] [fake-host] debug3 log\n", - safcm.LogDebug3), + fmt.Sprintf("[INVALID=%d] [fake-host] debug3 log\n", safcm.LogDebug3), false, }, { @@ -170,8 +169,7 @@ func TestLogEvent(t *testing.T) { }, safcm.LogDebug3, true, - fmt.Sprintf("[INVALID=%d] [\x1b[31mfake-host\x1b[0m] debug3 log\n", - safcm.LogDebug3), + fmt.Sprintf("[INVALID=%d] [\x1b[31mfake-host\x1b[0m] debug3 log\n", safcm.LogDebug3), false, }, { @@ -369,10 +367,10 @@ func TestLogEvent(t *testing.T) { var failed bool LogEvent(tc.event, tc.level, tc.isTTY, &failed) - testutil.AssertEqual(t, "log", - buf.String(), tc.exp) - testutil.AssertEqual(t, "failed", - failed, tc.expFailed) + testutil.AssertEqual(t, "log", buf.String(), tc.exp) + testutil.AssertEqual(t, "failed", failed, tc.expFailed) }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/frontend/loop.go b/frontend/loop.go index 4e70ed3..ff6d829 100644 --- a/frontend/loop.go +++ b/frontend/loop.go @@ -58,8 +58,8 @@ func (l *Loop) Run(hosts []Host) bool { sigint := make(chan os.Signal, 1) // buffered for Notify() signal.Notify(sigint, os.Interrupt) // = SIGINT = Ctrl-C go func() { - // Running `ssh` processes get killed by SIGINT which is sent - // to all processes + // Running `ssh` processes get killed by SIGINT which is sent to all + // processes <-sigint log.Print("Received SIGINT, aborting ...") @@ -67,9 +67,9 @@ func (l *Loop) Run(hosts []Host) bool { // Print all queued events events <- Event{} // poison pill <-done - // "races" with <-done in the main function and will hang here - // if the other is faster. This is fine because then all hosts - // were synced successfully. + // "races" with <-done in the main function and will hang here if the + // other is faster. This is fine because then all hosts were synced + // successfully. hostsLeftMutex.Lock() var hosts []string @@ -156,3 +156,5 @@ func (l *Loop) syncHost(wg *sync.WaitGroup, host Host) error { return nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/frontend/term.go b/frontend/term.go index 559445d..19e16bd 100644 --- a/frontend/term.go +++ b/frontend/term.go @@ -63,3 +63,5 @@ func EscapeControlCharacters(isTTY bool, x string) string { return ColorString(isTTY, ColorMagenta, x) }) } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/frontend/term_test.go b/frontend/term_test.go index f96786c..e6c9549 100644 --- a/frontend/term_test.go +++ b/frontend/term_test.go @@ -76,3 +76,5 @@ func TestEscapeControlCharacters(t *testing.T) { }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/gob.go b/gob.go index e5b8e9c..dea8bf8 100644 --- a/gob.go +++ b/gob.go @@ -23,8 +23,8 @@ func NewGobConn(r io.Reader, w io.Writer) *GobConn { } func (c *GobConn) Send(x Msg) error { - // & lets Encode send the interface itself and not a concrete type - // which is necessary to Decode as an interface + // & lets Encode send the interface itself and not a concrete type which + // is necessary to Decode as an interface return c.enc.Encode(&x) } @@ -36,3 +36,5 @@ func (c *GobConn) Recv() (Msg, error) { } return x, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/log.go b/log.go index 51e8a31..9aeb643 100644 --- a/log.go +++ b/log.go @@ -50,3 +50,5 @@ func ParseLogLevel(s string) (LogLevel, error) { } return x, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/ainsl/ainsl.go b/remote/ainsl/ainsl.go index 01c660e..2d5c0b8 100644 --- a/remote/ainsl/ainsl.go +++ b/remote/ainsl/ainsl.go @@ -26,8 +26,7 @@ import ( func Main(args []string) error { flag.Usage = func() { - fmt.Fprintf(os.Stderr, - "usage: %s ainsl [] \n", + fmt.Fprintf(os.Stderr, "usage: %s ainsl [] \n", args[0]) flag.PrintDefaults() } @@ -59,8 +58,7 @@ func handle(path string, line string, create bool) ([]string, error) { return nil, fmt.Errorf("empty line") } if strings.Contains(line, "\n") { - return nil, fmt.Errorf("line must not contain newlines: %q", - line) + return nil, fmt.Errorf("line must not contain newlines: %q", line) } parentFd, baseName, err := sync.OpenParentDirectoryNoSymlinks(path) @@ -79,23 +77,21 @@ func handle(path string, line string, create bool) ([]string, error) { return nil, fmt.Errorf("%q: %v", path, err) } if !create { - return nil, fmt.Errorf( - "%q: file does not exist, use -create", + return nil, fmt.Errorf("%q: file does not exist, use -create", path) } uid, gid = os.Getuid(), os.Getgid() - // Read current umask. Don't do this in programs where - // multiple goroutines create files because this is inherently - // racy! No goroutines here, so it's fine. + // Read current umask. Don't do this in programs where multiple + // goroutines create files because this is inherently racy! No + // goroutines here, so it's fine. umask := syscall.Umask(0) syscall.Umask(umask) // Apply umask to created file mode = 0666 & ^fs.FileMode(umask) changes = append(changes, - fmt.Sprintf("%q: created file (%d/%d %s)", - path, uid, gid, mode)) + fmt.Sprintf("%q: created file (%d/%d %s)", path, uid, gid, mode)) } else { // Preserve user/group and mode of existing file @@ -117,16 +113,14 @@ func handle(path string, line string, create bool) ([]string, error) { break } } - // Make sure the file has a trailing newline. This enforces symmetry - // with our changes. Whenever we add a line we also append a trailing - // newline. When we conclude that no changes are necessary the file - // should be in the same state as we would leave it if there were - // changes. + // Make sure the file has a trailing newline. This enforces symmetry with + // our changes. Whenever we add a line we also append a trailing newline. + // When we conclude that no changes are necessary the file should be in + // the same state as we would leave it if there were changes. if len(data) != 0 && data[len(data)-1] != '\n' { data = append(data, '\n') changes = append(changes, - fmt.Sprintf("%q: added missing trailing newline", - path)) + fmt.Sprintf("%q: added missing trailing newline", path)) } // Line present, nothing to do @@ -183,3 +177,5 @@ func readFileAtNoFollow(dirfd int, base string) ([]byte, fs.FileInfo, error) { return x, stat, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/ainsl/ainsl_test.go b/remote/ainsl/ainsl_test.go index d846594..0454ae4 100644 --- a/remote/ainsl/ainsl_test.go +++ b/remote/ainsl/ainsl_test.go @@ -284,8 +284,7 @@ func TestHandle(t *testing.T) { } changes, err := handle(tc.path, tc.line, tc.create) - testutil.AssertEqual(t, "changes", - changes, tc.expChanges) + testutil.AssertEqual(t, "changes", changes, tc.expChanges) testutil.AssertErrorEqual(t, "err", err, tc.expErr) files, err := ft.WalkDir(path) @@ -296,3 +295,5 @@ func TestHandle(t *testing.T) { }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/info/info.go b/remote/info/info.go index 5ae48be..6f37b66 100644 --- a/remote/info/info.go +++ b/remote/info/info.go @@ -22,8 +22,8 @@ type Info struct { logger *log.Logger } -func Handle(req safcm.MsgInfoReq, - runner run.Runner, fun log.LogFunc) safcm.MsgInfoResp { +func Handle(req safcm.MsgInfoReq, runner run.Runner, + fun log.LogFunc) safcm.MsgInfoResp { i := Info{ req: req, @@ -43,8 +43,7 @@ func (i *Info) handle() error { i.resp.Goarch = runtime.GOARCH for _, x := range i.req.DetectGroups { - stdout, _, err := i.cmd.Run("detect group", - "/bin/sh", "-c", x) + stdout, _, err := i.cmd.Run("detect group", "/bin/sh", "-c", x) if err != nil { return err } @@ -53,3 +52,5 @@ func (i *Info) handle() error { return nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/log/logger.go b/remote/log/logger.go index 6a150a4..4a3e664 100644 --- a/remote/log/logger.go +++ b/remote/log/logger.go @@ -38,3 +38,5 @@ func (l *Logger) log(level safcm.LogLevel, format string, a ...interface{}) { l.fun(level, fmt.Sprintf(format, a...)) } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/main.go b/remote/main.go index 4f29a1f..da17e7b 100644 --- a/remote/main.go +++ b/remote/main.go @@ -63,9 +63,9 @@ func mainLoop() error { var logLevel safcm.LogLevel logFunc := func(level safcm.LogLevel, msg string) { if logLevel >= level { - // Handling errors here is complex and quite verbose. - // If it happens the connection is gone anyway so skip - // the error handling. + // Handling errors here is complex and quite verbose. If it + // happens the connection is gone anyway so skip the error + // handling. conn.Send(safcm.MsgLog{ //nolint:errcheck Level: level, Text: msg, @@ -103,3 +103,5 @@ func mainLoop() error { } return nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/run/cmd.go b/remote/run/cmd.go index fbd9b88..b622e8e 100644 --- a/remote/run/cmd.go +++ b/remote/run/cmd.go @@ -41,16 +41,13 @@ func (c *Cmd) Run(module string, args ...string) ([]byte, []byte, error) { c.logger.Debugf("%s: running %s", module, quoted) err := c.Runner.Run(cmd) if stdout.Len() > 0 { - c.logger.Debug2f("%s: command stdout:\n%s", - module, stdout.Bytes()) + c.logger.Debug2f("%s: command stdout:\n%s", module, stdout.Bytes()) } if stderr.Len() > 0 { - c.logger.Debug2f("%s: command stderr:\n%s", - module, stderr.Bytes()) + c.logger.Debug2f("%s: command stderr:\n%s", module, stderr.Bytes()) } if err != nil { - return nil, nil, fmt.Errorf( - "%s failed: %v; stdout: %q, stderr: %q", + return nil, nil, fmt.Errorf("%s failed: %v; stdout: %q, stderr: %q", quoted, err, stdout.String(), stderr.String()) } return stdout.Bytes(), stderr.Bytes(), nil @@ -66,8 +63,7 @@ func (c *Cmd) CombinedOutputCmd(module string, cmd *exec.Cmd) ([]byte, error) { c.logger.Debug2f("%s: command output:\n%s", module, out) } if err != nil { - return nil, fmt.Errorf("%s failed: %v; output: %q", - quoted, err, out) + return nil, fmt.Errorf("%s failed: %v; output: %q", quoted, err, out) } return out, nil } @@ -80,3 +76,5 @@ func QuoteForDebug(cmd *exec.Cmd) string { } return strings.Join(quoted, " ") } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/run/runner.go b/remote/run/runner.go index 6fd35e5..ac5de61 100644 --- a/remote/run/runner.go +++ b/remote/run/runner.go @@ -26,3 +26,5 @@ func (r ExecRunner) Run(cmd *exec.Cmd) error { func (r ExecRunner) CombinedOutput(cmd *exec.Cmd) ([]byte, error) { return cmd.CombinedOutput() } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/commands.go b/remote/sync/commands.go index 7837c12..0b0b7f5 100644 --- a/remote/sync/commands.go +++ b/remote/sync/commands.go @@ -25,8 +25,7 @@ func (s *Sync) syncCommands() error { } } } - // Regular commands afterwards so they can react on triggers if - // necessary + // Regular commands afterwards so they can react on triggers if necessary for _, x := range s.req.Commands { err := s.syncCommand(x.Cmd, x.OrigGroup, "") if err != nil { @@ -56,11 +55,10 @@ func (s *Sync) syncCommand(command, group, trigger string) error { cmd := exec.Command("/bin/sh", "-c", command) cmd.Env = safcmEnviroment(s.req.Groups) - // Cannot use cmd.CombinedOutputCmd() because we need another log - // level (here the command is the actual change and not a side effect) - // and different error handling. - s.log.Verbosef("commands: running %s (%s)", - run.QuoteForDebug(cmd), info) + // Cannot use cmd.CombinedOutputCmd() because we need another log level + // (here the command is the actual change and not a side effect) and + // different error handling. + s.log.Verbosef("commands: running %s (%s)", run.QuoteForDebug(cmd), info) out, err := s.cmd.Runner.CombinedOutput(cmd) if len(out) > 0 { s.log.Debug2f("commands: command output:\n%s", out) @@ -90,3 +88,5 @@ func safcmEnviroment(groups []string) []string { } return env } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/commands_test.go b/remote/sync/commands_test.go index eba5199..44583a0 100644 --- a/remote/sync/commands_test.go +++ b/remote/sync/commands_test.go @@ -41,8 +41,8 @@ func TestSyncCommands(t *testing.T) { expErr error }{ - // NOTE: Also update MsgSyncResp in safcm test cases when - // changing the MsgSyncResp struct! + // NOTE: Also update MsgSyncResp in safcm test cases when changing the + // MsgSyncResp struct! { "successful command", @@ -529,3 +529,5 @@ func TestSyncCommands(t *testing.T) { }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/files.go b/remote/sync/files.go index 620890f..3363196 100644 --- a/remote/sync/files.go +++ b/remote/sync/files.go @@ -41,8 +41,8 @@ import ( const openReadonlyFlags = unix.O_RDONLY | unix.O_NOFOLLOW | unix.O_NONBLOCK func (s *Sync) syncFiles() error { - // Sort for deterministic order and so parent directories are present - // when files in them are created + // Sort for deterministic order and so parent directories are present when + // files in them are created var files []*safcm.File for _, x := range s.req.Files { files = append(files, x) @@ -66,28 +66,28 @@ func (s *Sync) syncFiles() error { } func (s *Sync) syncFile(file *safcm.File, changed *bool) error { - // The general strategy is "update by rename": If any property of a - // file changes the new version will be written to a temporary file - // and then renamed "over" the original file. This is simple and - // prevents race conditions where the file is partially readable while - // changes to permissions or owner/group are applied. However, this - // strategy does not work for directories which must be removed first - // (was directory), must remove the existing file (will be directory) - // or must be directly modified (changed permissions or owner). In the - // first two cases the old path is removed. In the last the directory - // is modified (carefully) in place. + // The general strategy is "update by rename": If any property of a file + // changes the new version will be written to a temporary file and then + // renamed "over" the original file. This is simple and prevents race + // conditions where the file is partially readable while changes to + // permissions or owner/group are applied. However, this strategy does not + // work for directories which must be removed first (was directory), must + // remove the existing file (will be directory) or must be directly + // modified (changed permissions or owner). In the first two cases the old + // path is removed. In the last the directory is modified (carefully) in + // place. // // The implementation is careful not to follow any symlinks to prevent // possible race conditions which can be exploited and are especially - // dangerous when running with elevated privileges (which will most - // likely be the case). This includes not using absolute paths in - // syscalls to prevent symlink attacks when a directory is writable by - // other users (e.g. when syncing a file to /home/user/dir/file the - // user could create dir as symlink to another directory and file - // would be written there). To prevent this *at syscalls are used and - // all symlinks in the path are rejected. This still permits the user - // to move dir during the sync but only to places which are writable - // by the user which cannot be prevented. + // dangerous when running with elevated privileges (which will most likely + // be the case). This includes not using absolute paths in syscalls to + // prevent symlink attacks when a directory is writable by other users + // (e.g. when syncing a file to /home/user/dir/file the user could create + // dir as symlink to another directory and file would be written there). + // To prevent this *at syscalls are used and all symlinks in the path are + // rejected. This still permits the user to move dir during the sync but + // only to places which are writable by the user which cannot be + // prevented. err := s.fileResolveIds(file) if err != nil { @@ -161,10 +161,9 @@ reopen: var oldData []byte var changeType, changePerm, changeUserOrGroup, changeData bool if !change.Created { - // Manually convert to FileMode; from src/os/stat_linux.go in - // Go's sources (stat_*.go for other UNIX systems are - // identical, except for stat_darwin.go which has an extra - // S_IFWHT) + // Manually convert to FileMode; from src/os/stat_linux.go in Go's + // sources (stat_*.go for other UNIX systems are identical, except for + // stat_darwin.go which has an extra S_IFWHT) mode := fs.FileMode(oldStat.Mode & 0777) switch oldStat.Mode & unix.S_IFMT { case unix.S_IFBLK: @@ -181,8 +180,7 @@ reopen: // nothing to do case unix.S_IFSOCK: mode |= fs.ModeSocket - // Guard against unknown file types (e.g. on darwin); not in - // stat_*.go + // Guard against unknown file types (e.g. on darwin); not in stat_*.go default: return fmt.Errorf("unexpected file mode %v", oldStat.Mode&unix.S_IFMT) @@ -200,11 +198,10 @@ reopen: // Compare permissions change.Old.Mode = mode if change.Old.Mode.Type() == fs.ModeSymlink { - // Some BSD systems permit changing permissions of - // symlinks but ignore them on traversal. To keep it - // simple we don't support that and always use 0777 - // for symlink permissions (the value on GNU/Linux) - // when comparing. The actual permissions on the file + // Some BSD systems permit changing permissions of symlinks but + // ignore them on traversal. To keep it simple we don't support + // that and always use 0777 for symlink permissions (the value on + // GNU/Linux) when comparing. The actual permissions on the file // system might be different on BSD systems. // // TODO: Add proper support for symlinks on BSD @@ -217,8 +214,8 @@ reopen: change.Old.Mode.Type(), file.Mode.Type()) } else { - // Be careful with .Perm() which does not - // contain the setuid/setgid/sticky bits! + // Be careful with .Perm() which does not contain the + // setuid/setgid/sticky bits! changePerm = true debugf("permission differs %s -> %s", change.Old.Mode, file.Mode) @@ -235,9 +232,8 @@ reopen: file.Uid, file.Gid) } u, g, err := resolveIdsToNames(change.Old.Uid, change.Old.Gid) - // Errors are not relevant as this is only used to report the - // change. If the user/group no longer exits only the ids will - // be reported. + // Errors are not relevant as this is only used to report the change. + // If the user/group no longer exits only the ids will be reported. if err == nil { change.Old.User = u change.Old.Group = g @@ -248,16 +244,14 @@ reopen: case 0: // regular file x, err := io.ReadAll(oldFh) if err != nil { - return fmt.Errorf("reading old content: %v", - err) + return fmt.Errorf("reading old content: %v", err) } oldData = x case fs.ModeSymlink: buf := make([]byte, unix.PathMax) n, err := unix.Readlinkat(parentFd, baseName, buf) if err != nil { - return fmt.Errorf("reading old content: %v", - err) + return fmt.Errorf("reading old content: %v", err) } oldData = buf[:n] } @@ -278,10 +272,10 @@ reopen: } *changed = true - // Don't show a diff with the full content for newly created files or - // on type changes. This is just noise for the user as the new file - // content is obvious. But we always want to see a diff when files are - // replaced because this destroys data. + // Don't show a diff with the full content for newly created files or on + // type changes. This is just noise for the user as the new file content + // is obvious. But we always want to see a diff when files are replaced + // because this destroys data. if !change.Created && (change.Old.Mode.Type() == 0 || change.Old.Mode.Type() == fs.ModeSymlink) { @@ -291,8 +285,8 @@ reopen: } } - // Add change here so it is stored even when applying it fails. This - // way the user knows exactly what was attempted. + // Add change here so it is stored even when applying it fails. This way + // the user knows exactly what was attempted. s.resp.FileChanges = append(s.resp.FileChanges, change) if change.Created { @@ -310,16 +304,15 @@ reopen: if changeType && (change.Old.Mode.IsDir() || file.Mode.IsDir()) { debugf("removing (due to type change)") // In the past os.RemoveAll() was used here. However, this is - // difficult to implement manually with *at syscalls. To keep - // it simple only permit removing files and empty directories - // here. This also has the bonus of preventing data loss when - // (accidentally) replacing a directory tree with a file. + // difficult to implement manually with *at syscalls. To keep it + // simple only permit removing files and empty directories here. This + // also has the bonus of preventing data loss when (accidentally) + // replacing a directory tree with a file. const msg = "will not replace non-empty directory, " + "please remove manually" err := unix.Unlinkat(parentFd, baseName, 0 /* flags */) if err != nil && !os.IsNotExist(err) { - err2 := unix.Unlinkat(parentFd, baseName, - unix.AT_REMOVEDIR) + err2 := unix.Unlinkat(parentFd, baseName, unix.AT_REMOVEDIR) if err2 != nil && !os.IsNotExist(err2) { // See src/os/file_unix.go in Go's sources if err2 == unix.ENOTDIR { @@ -340,10 +333,10 @@ reopen: if err != nil { return err } - // We must be careful not to chmod arbitrary files. If the - // target directory is writable then it might have changed to - // a symlink at this point. There's no lchmod and fchmodat is - // incomplete so open the directory. + // We must be careful not to chmod arbitrary files. If the target + // directory is writable then it might have changed to a symlink at + // this point. There's no lchmod and fchmodat is incomplete so open + // the directory. debugf("chmodding %s", file.Mode) dh, err := OpenAtNoFollow(parentFd, baseName) if err != nil { @@ -355,8 +348,8 @@ reopen: if err != nil { return err } - // Less restrictive access is not relevant here because there - // are no files present yet. + // Less restrictive access is not relevant here because there are no + // files present yet. debugf("chowning %d/%d", file.Uid, file.Gid) err = dh.Chown(file.Uid, file.Gid) if err != nil { @@ -366,20 +359,19 @@ reopen: } // Directory: changed permission or user/group if file.Mode.IsDir() { - // We don't know if the new permission or if the new - // user/group is more restrictive (e.g. root:root 0750 -> - // user:group 0700; applying group first gives group - // unexpected access). To prevent a short window where the - // access might be too lax we temporarily deny all access. + // We don't know if the new permission or if the new user/group is + // more restrictive (e.g. root:root 0750 -> user:group 0700; applying + // group first gives group unexpected access). To prevent a short + // window where the access might be too lax we temporarily deny all + // access. if changePerm && changeUserOrGroup { - // Only drop group and other permission because user - // has access anyway (either before or after the - // change). This also prevents temporary errors during - // the error when the user tries to access this - // directory (access for the group will fail though). + // Only drop group and other permission because user has access + // anyway (either before or after the change). This also prevents + // temporary errors during the error when the user tries to access + // this directory (access for the group will fail though). mode := change.Old.Mode & fs.ModePerm & 0700 - // Retain setgid/sticky so that the behavior does not - // change when creating and removing files. + // Retain setgid/sticky so that the behavior does not change when + // creating and removing files. mode |= change.Old.Mode & fs.ModeSetgid mode |= change.Old.Mode & fs.ModeSticky debugf("chmodding %#o (temporary)", mode) @@ -406,14 +398,13 @@ reopen: } dir := slashpath.Dir(file.Path) // only used in debug messages - // Create hidden file which should be ignored by most other tools and - // thus not affect anything during creation + // Create hidden file which should be ignored by most other tools and thus + // not affect anything during creation tmpBase := "." + baseName switch file.Mode.Type() { case 0: // regular file - debugf("creating temporary file %q", - slashpath.Join(dir, tmpBase+"*")) + debugf("creating temporary file %q", slashpath.Join(dir, tmpBase+"*")) x, err := WriteTempAt(parentFd, tmpBase, file.Data, file.Uid, file.Gid, file.Mode) if err != nil { @@ -425,8 +416,7 @@ reopen: i := 0 retry: x := tmpBase + strconv.Itoa(rand.Int()) - debugf("creating temporary symlink %q", - slashpath.Join(dir, x)) + debugf("creating temporary symlink %q", slashpath.Join(dir, x)) err := unix.Symlinkat(string(file.Data), parentFd, x) if err != nil { if os.IsExist(err) && i < 10000 { @@ -458,11 +448,11 @@ reopen: // To guarantee durability fsync must be called on a parent directory // after adding, renaming or removing files therein. // - // Calling sync on the files itself is not enough according to POSIX; - // man 2 fsync: "Calling fsync() does not necessarily ensure that the - // entry in the directory containing the file has also reached disk. - // For that an explicit fsync() on a file descriptor for the directory - // is also needed." + // Calling sync on the files itself is not enough according to POSIX; man + // 2 fsync: "Calling fsync() does not necessarily ensure that the entry in + // the directory containing the file has also reached disk. For that an + // explicit fsync() on a file descriptor for the directory is also + // needed." err = unix.Fsync(parentFd) if err != nil { return err @@ -529,8 +519,8 @@ func OpenParentDirectoryNoSymlinks(path string) (int, string, error) { var dir string if path == "/" { - // Root: use root itself as base name because root is the - // parent of itself + // Root: use root itself as base name because root is the parent of + // itself dir = "/" parts = []string{"/"} } else if parts[0] == "" { @@ -538,12 +528,12 @@ func OpenParentDirectoryNoSymlinks(path string) (int, string, error) { dir = "/" parts = parts[1:] } else if path == "." { - // Current directory: open parent directory and use current - // directory name as base name + // Current directory: open parent directory and use current directory + // name as base name wd, err := os.Getwd() if err != nil { - return -1, "", fmt.Errorf( - "failed to get working directory: %w", err) + return -1, "", fmt.Errorf("failed to get working directory: %w", + err) } dir = ".." parts = []string{filepath.Base(wd)} @@ -555,24 +545,22 @@ func OpenParentDirectoryNoSymlinks(path string) (int, string, error) { } } - dirFd, err := unix.Openat(unix.AT_FDCWD, dir, - openReadonlyFlags, 0 /* mode */) + dirFd, err := unix.Openat(unix.AT_FDCWD, dir, openReadonlyFlags, + 0 /* mode */) if err != nil { return -1, "", err } - // Walk path one directory at a time to ensure there are no symlinks - // in the path. This prevents users with write access to change the - // path to point to arbitrary locations. O_NOFOLLOW when opening the - // path is not enough as only the last path component is checked. + // Walk path one directory at a time to ensure there are no symlinks in + // the path. This prevents users with write access to change the path to + // point to arbitrary locations. O_NOFOLLOW when opening the path is not + // enough as only the last path component is checked. for i, name := range parts[:len(parts)-1] { fd, err := unix.Openat(dirFd, name, openReadonlyFlags, 0) if err != nil { unix.Close(dirFd) //nolint:errcheck if err == unix.ELOOP || err == unix.EMLINK { - x := filepath.Join(append([]string{dir}, - parts[:i+1]...)...) - return -1, "", fmt.Errorf( - "symlink not permitted in path: %q", + x := filepath.Join(append([]string{dir}, parts[:i+1]...)...) + return -1, "", fmt.Errorf("symlink not permitted in path: %q", x) } return -1, "", err @@ -709,3 +697,5 @@ retry: return os.NewFile(uintptr(fd), ""), tmpBase, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/files_compat_windows.go b/remote/sync/files_compat_windows.go index f6e7b76..bfe896a 100644 --- a/remote/sync/files_compat_windows.go +++ b/remote/sync/files_compat_windows.go @@ -20,3 +20,5 @@ func (s *Sync) syncFiles() error { func OpenFileNoSymlinks(path string) (*os.File, error) { return nil, fmt.Errorf("not implemented on Windows") } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/files_test.go b/remote/sync/files_test.go index b1c91ef..9376413 100644 --- a/remote/sync/files_test.go +++ b/remote/sync/files_test.go @@ -41,11 +41,11 @@ func TestSyncFiles(t *testing.T) { expErr error }{ - // NOTE: Also update MsgSyncResp in safcm test cases when - // changing the MsgSyncResp struct! + // NOTE: Also update MsgSyncResp in safcm test cases when changing the + // MsgSyncResp struct! - // See TestSyncFile() for most file related tests. This - // function only tests the overall results and triggers. + // See TestSyncFile() for most file related tests. This function only + // tests the overall results and triggers. { "basic: create", @@ -236,13 +236,12 @@ func TestSyncFiles(t *testing.T) { }, { - // We use relative paths for most tests because we - // don't want to modify the running system. Use this - // test (and the one below for triggers) as a basic - // check that absolute paths work. + // We use relative paths for most tests because we don't want to + // modify the running system. Use this test (and the one below for + // triggers) as a basic check that absolute paths work. // - // Use numeric IDs as not all systems use root/root; - // for example BSDs use root/wheel. + // Use numeric IDs as not all systems use root/root; for example + // BSDs use root/wheel. "absolute paths: no change", skipUnlessCiRun, safcm.MsgSyncReq{ @@ -837,8 +836,7 @@ func TestSyncFiles(t *testing.T) { testutil.AssertEqual(t, "files", files, tc.expFiles) testutil.AssertEqual(t, "resp", s.resp, tc.expResp) - testutil.AssertEqual(t, "triggers", - s.triggers, tc.expTriggers) + testutil.AssertEqual(t, "triggers", s.triggers, tc.expTriggers) }) } @@ -864,8 +862,8 @@ func TestSyncFile(t *testing.T) { expErr error }{ - // NOTE: Also update MsgSyncResp in safcm test cases when - // changing the MsgSyncResp struct! + // NOTE: Also update MsgSyncResp in safcm test cases when changing the + // MsgSyncResp struct! // TODO: Add tests for chown and run them only as root @@ -2582,3 +2580,5 @@ file }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/filetest/filetest.go b/remote/sync/filetest/filetest.go index 07e803a..5d22ded 100644 --- a/remote/sync/filetest/filetest.go +++ b/remote/sync/filetest/filetest.go @@ -134,3 +134,5 @@ func CreateFifo(path string, mode fs.FileMode) { panic(err) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/packages.go b/remote/sync/packages.go index 9afff83..c31cd44 100644 --- a/remote/sync/packages.go +++ b/remote/sync/packages.go @@ -22,3 +22,5 @@ func (s *Sync) syncPackages() error { // TODO: support more distributions return fmt.Errorf("not yet supported on this distribution") } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/packages_debian.go b/remote/sync/packages_debian.go index 56fcc2d..bd9e22f 100644 --- a/remote/sync/packages_debian.go +++ b/remote/sync/packages_debian.go @@ -84,15 +84,16 @@ func (s *Sync) debianInstalledPackages() (map[string]bool, error) { for _, line := range lines { xs := strings.Split(line, "\t") if len(xs) != 2 { - return nil, fmt.Errorf("invalid dpkg-query line %q", - line) + return nil, fmt.Errorf("invalid dpkg-query line %q", line) } - // We only care if the package is currently successfully - // installed (last two fields). If a package is on hold (first - // field) this is fine as well. + // We only care if the package is currently successfully installed + // (last two fields). If a package is on hold (first field) this is + // fine as well. if strings.HasSuffix(xs[0], " ok installed") { res[xs[1]] = true } } return res, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/packages_debian_test.go b/remote/sync/packages_debian_test.go index 30b3b54..356d335 100644 --- a/remote/sync/packages_debian_test.go +++ b/remote/sync/packages_debian_test.go @@ -27,8 +27,8 @@ func TestSyncPackagesDebian(t *testing.T) { expErr error }{ - // NOTE: Also update MsgSyncResp in safcm test cases when - // changing the MsgSyncResp struct! + // NOTE: Also update MsgSyncResp in safcm test cases when changing the + // MsgSyncResp struct! { "packages already installed", @@ -302,3 +302,5 @@ install ok installed golang-1.16-src }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/services.go b/remote/sync/services.go index ee3885d..a89c0bd 100644 --- a/remote/sync/services.go +++ b/remote/sync/services.go @@ -25,3 +25,5 @@ func (s *Sync) syncServices() error { // TODO: support more distributions return fmt.Errorf("not yet supported on this distribution") } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/services_systemd.go b/remote/sync/services_systemd.go index fe8e2a4..ca432eb 100644 --- a/remote/sync/services_systemd.go +++ b/remote/sync/services_systemd.go @@ -36,8 +36,7 @@ func (s *Sync) syncServicesSystemd() error { if change.Started || change.Enabled { change.Name = name - s.resp.ServiceChanges = append(s.resp.ServiceChanges, - change) + s.resp.ServiceChanges = append(s.resp.ServiceChanges, change) } } if len(start) == 0 && len(enable) == 0 { @@ -48,15 +47,14 @@ func (s *Sync) syncServicesSystemd() error { return nil } - // Reload service files which were possibly changed during file sync - // or package installation + // Reload service files which were possibly changed during file sync or + // package installation _, _, err = s.cmd.Run("services", "/bin/systemctl", "daemon-reload") if err != nil { return err } if len(start) != 0 { - s.log.Verbosef("services: starting %s", - strings.Join(start, " ")) + s.log.Verbosef("services: starting %s", strings.Join(start, " ")) _, _, err := s.cmd.Run("services", append([]string{ "/bin/systemctl", "start", "--", }, start...)...) @@ -65,8 +63,7 @@ func (s *Sync) syncServicesSystemd() error { } } if len(enable) != 0 { - s.log.Verbosef("services: enabling %s", - strings.Join(enable, " ")) + s.log.Verbosef("services: enabling %s", strings.Join(enable, " ")) _, _, err := s.cmd.Run("services", append([]string{ "/bin/systemctl", "enable", "--", }, enable...)...) @@ -102,8 +99,7 @@ func (s *Sync) systemdServiceState(services []string) ( for _, block := range strings.Split(string(out), "\n\n") { lines := strings.Split(strings.TrimSpace(block), "\n") if len(lines) != 3 { - return nil, fmt.Errorf("invalid systemctl output: %q", - block) + return nil, fmt.Errorf("invalid systemctl output: %q", block) } var service SystemdService @@ -115,23 +111,19 @@ func (s *Sync) systemdServiceState(services []string) ( ) if strings.HasPrefix(x, activePrefix) { - service.ActiveState = strings.TrimPrefix(x, - activePrefix) + service.ActiveState = strings.TrimPrefix(x, activePrefix) } else if strings.HasPrefix(x, unitPrefix) { - service.UnitFileState = strings.TrimPrefix(x, - unitPrefix) + service.UnitFileState = strings.TrimPrefix(x, unitPrefix) } else if strings.HasPrefix(x, errorPrefix) { x := strings.TrimPrefix(x, errorPrefix) - // Older systemd versions (e.g. 237) add empty - // quotes even if there is no error + // Older systemd versions (e.g. 237) add empty quotes even if + // there is no error if x != "" && x != ` ""` { - return nil, fmt.Errorf( - "systemd unit %q not found", + return nil, fmt.Errorf("systemd unit %q not found", services[i]) } } else { - return nil, fmt.Errorf( - "invalid systemctl show line %q", x) + return nil, fmt.Errorf("invalid systemctl show line %q", x) } } res[services[i]] = service @@ -141,3 +133,5 @@ func (s *Sync) systemdServiceState(services []string) ( return res, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/services_systemd_test.go b/remote/sync/services_systemd_test.go index 935828a..e464060 100644 --- a/remote/sync/services_systemd_test.go +++ b/remote/sync/services_systemd_test.go @@ -26,8 +26,8 @@ func TestSyncServicesSystemd(t *testing.T) { expErr error }{ - // NOTE: Also update MsgSyncResp in safcm test cases when - // changing the MsgSyncResp struct! + // NOTE: Also update MsgSyncResp in safcm test cases when changing the + // MsgSyncResp struct! { "no service change necessary", @@ -505,3 +505,5 @@ LoadError= }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/sync.go b/remote/sync/sync.go index ce87a83..e17217b 100644 --- a/remote/sync/sync.go +++ b/remote/sync/sync.go @@ -82,3 +82,5 @@ func (s *Sync) setDefaults() error { return nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/sync_test.go b/remote/sync/sync_test.go index dfe498b..c601c44 100644 --- a/remote/sync/sync_test.go +++ b/remote/sync/sync_test.go @@ -143,3 +143,5 @@ func (s *syncTestResult) Wait() []string { return s.dbg } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/triggers.go b/remote/sync/triggers.go index d786724..9a5be18 100644 --- a/remote/sync/triggers.go +++ b/remote/sync/triggers.go @@ -20,14 +20,12 @@ func (s *Sync) queueTriggers(file *safcm.File) { } // Queue each trigger only once if s.triggersActive[path] { - s.log.Debugf( - "files: %q: skipping trigger on %q, already active", + s.log.Debugf("files: %q: skipping trigger on %q, already active", file.Path, path) continue } - s.log.Verbosef("files: %q: queuing trigger on %q", - file.Path, path) + s.log.Verbosef("files: %q: queuing trigger on %q", file.Path, path) s.triggers = append(s.triggers, path) s.triggersActive[path] = true } @@ -58,3 +56,5 @@ func triggerPaths(path string) []string { } return res } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/remote/sync/triggers_test.go b/remote/sync/triggers_test.go index 07652ca..c1e97fb 100644 --- a/remote/sync/triggers_test.go +++ b/remote/sync/triggers_test.go @@ -48,3 +48,5 @@ func TestTriggerPaths(t *testing.T) { }) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/rpc/conn.go b/rpc/conn.go index 41e5be1..80a51cc 100644 --- a/rpc/conn.go +++ b/rpc/conn.go @@ -108,8 +108,8 @@ func (c *Conn) wait() error { close(c.events) // We cannot reuse this channel. c.events = nil - // Don't set c.Events to nil because this creates a data race when - // another thread is still waiting. + // Don't set c.Events to nil because this creates a data race when another + // thread is still waiting. return err } @@ -159,3 +159,5 @@ func (c *Conn) handleStderrAsEvents(cmd *exec.Cmd) error { return nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/rpc/dial.go b/rpc/dial.go index 0838c97..3b6a956 100644 --- a/rpc/dial.go +++ b/rpc/dial.go @@ -135,23 +135,23 @@ compat_sha512sum() { return fmt.Errorf("internal error: no support for %q", goos) } - // Use a function so the shell cannot execute the input line-wise. - // This is important because we're also using stdin to send data to - // the script. If the shell executes the input line-wise then our - // script is interpreted as input for `read`. + // Use a function so the shell cannot execute the input line-wise. This is + // important because we're also using stdin to send data to the script. If + // the shell executes the input line-wise then our script is interpreted + // as input for `read`. // - // The target directory must no permit other users to delete our files - // or symlink attacks and arbitrary code execution is possible. For - // /tmp this is guaranteed by the sticky bit. The code verifies the - // directory has the proper permissions. + // The target directory must no permit other users to delete our files or + // symlink attacks and arbitrary code execution is possible. For /tmp this + // is guaranteed by the sticky bit. The code verifies the directory has + // the proper permissions. // // We cannot use `test -f && test -O` because this is open to TOCTOU - // attacks. `stat` gives use the full file state. If the file is owned - // by us and not a symlink then it's safe to use (assuming sticky - // directory or directory not writable by others). + // attacks. `stat` gives use the full file state. If the file is owned by + // us and not a symlink then it's safe to use (assuming sticky directory + // or directory not writable by others). // - // `test -e` is only used to prevent error messages if the file - // doesn't exist. It does not guard against any races. + // `test -e` is only used to prevent error messages if the file doesn't + // exist. It does not guard against any races. _, err = fmt.Fprintf(stdin, ` %s f() { @@ -219,8 +219,7 @@ f } else { x := strings.Fields(remoteSum) if len(x) < 1 { - return fmt.Errorf("got unexpected checksum line %q", - remoteSum) + return fmt.Errorf("got unexpected checksum line %q", remoteSum) } sha := sha512.Sum512(helper) hex := hex.EncodeToString(sha[:]) @@ -245,11 +244,10 @@ f } // Get path to temporary file for upload. // - // Write to the temporary file instead of the final path so - // that a concurrent run of this function won't use a - // partially written file. The rm in the script could still - // cause a missing file but at least no file with unknown - // content is executed. + // Write to the temporary file instead of the final path so that a + // concurrent run of this function won't use a partially written file. + // The rm in the script could still cause a missing file but at least + // no file with unknown content is executed. path, err := stdout.ReadString('\n') if err != nil { return err @@ -350,3 +348,5 @@ func connGetUID(stdin io.Writer, stdout *bufio.Reader) (int, error) { } return uid, nil } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/testutil/testutil.go b/testutil/testutil.go index eb1857c..e3de955 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -28,7 +28,8 @@ func AssertErrorEqual(t *testing.T, name string, act, exp error) { actStr := fmt.Sprintf("%v", act) expStr := fmt.Sprintf("%v", exp) if actStr != expStr { - t.Errorf("err = %s (%#v), want %s (%#v)", - actStr, act, expStr, exp) + t.Errorf("err = %s (%#v), want %s (%#v)", actStr, act, expStr, exp) } } + +// vi: set noet ts=4 sw=4 sts=4: diff --git a/types.go b/types.go index 7333fa7..9f50100 100644 --- a/types.go +++ b/types.go @@ -130,3 +130,5 @@ type CommandChange struct { Output string // stdout and stderr combined Error string } + +// vi: set noet ts=4 sw=4 sts=4: -- 2.49.1