auto daemon-reload where applicable

This commit is contained in:
2026-03-19 19:55:25 +00:00
parent c0ea7bf29e
commit c116ac9444
3 changed files with 24 additions and 0 deletions

23
app.go
View File

@@ -253,6 +253,9 @@ func (a *App) setupClientMount() error {
return err
}
if mountNow {
if err := a.reloadSystemdIfNeeded(); err != nil {
return err
}
if err := a.mountCIFS(cfg.MountPoint); err != nil {
return err
}
@@ -779,6 +782,26 @@ func (a *App) mountCIFS(path string) error {
return nil
}
func (a *App) reloadSystemdIfNeeded() error {
if _, err := os.Stat("/run/systemd/system"); err != nil {
if os.IsNotExist(err) {
return nil
}
return fmt.Errorf("check for systemd: %w", err)
}
if a.lookPath != nil {
if _, err := a.lookPath("systemctl"); err != nil {
return nil
}
}
if err := a.runPrivilegedOrLocal("systemctl", []string{"daemon-reload"}, "Refreshing system mount settings needs administrator permission."); err != nil {
return fmt.Errorf("reload systemd after updating /etc/fstab: %w", err)
}
return nil
}
func (a *App) ensureShareDirectories(doc *Document) error {
for _, section := range doc.ShareSections() {
cfg := ShareFromSection(section)