From 65eacf6d59cfecf7d579c5ee7c08ca35fcbb9087 Mon Sep 17 00:00:00 2001 From: Shaun Davis Date: Sat, 18 Feb 2023 19:32:33 -0600 Subject: [PATCH] Fixing double sync issue file permission issue --- internal/flypg/pg.go | 2 +- internal/flypg/repmgr.go | 4 ++-- internal/flypg/restore.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/flypg/pg.go b/internal/flypg/pg.go index 90557324..074c7ddd 100644 --- a/internal/flypg/pg.go +++ b/internal/flypg/pg.go @@ -249,7 +249,7 @@ func (c *PGConfig) initialize() error { } func (c *PGConfig) writePGConfigEntries(entries []string) error { - file, err := os.Create(c.configFilePath) + file, err := os.OpenFile(c.configFilePath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) if err != nil { return err } diff --git a/internal/flypg/repmgr.go b/internal/flypg/repmgr.go index 6fa152a2..b2157fdb 100644 --- a/internal/flypg/repmgr.go +++ b/internal/flypg/repmgr.go @@ -124,7 +124,7 @@ func (r *RepMgr) initialize() error { return fmt.Errorf("failed to set repmgr.conf ownership: %s", err) } - return file.Sync() + return nil } func (r *RepMgr) setup(ctx context.Context, conn *pgx.Conn) error { @@ -236,7 +236,7 @@ func (r *RepMgr) clonePrimary(ipStr string) error { func (r *RepMgr) writePasswdConf() error { path := "/data/.pgpass" - file, err := os.Create(path) + file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0600) if err != nil { return fmt.Errorf("failed to open repmgr password file: %s", err) } diff --git a/internal/flypg/restore.go b/internal/flypg/restore.go index 8f3f4a0e..f0b373b0 100644 --- a/internal/flypg/restore.go +++ b/internal/flypg/restore.go @@ -160,7 +160,7 @@ func restoreHBAFile() error { } func setRestoreLock() error { - file, err := os.Create(restoreLockFile) + file, err := os.OpenFile(restoreLockFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err }