From fa8a0a5ae5df494855e5fd391948d0b51cf51806 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 14 Nov 2018 20:21:34 +0100 Subject: [PATCH] fix DryRun() for instruction/copy : create/remove file if does not exist, else try to open in WRITE mode --- internal/instruction/copy.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/instruction/copy.go b/internal/instruction/copy.go index 5b419da..836a1b8 100644 --- a/internal/instruction/copy.go +++ b/internal/instruction/copy.go @@ -54,16 +54,16 @@ func (d copy) DryRun(ctx ExecutionContext) ([]byte, error) { } // 2. if destination to create : try to create (then remove) - if _, err := os.Stat(d.Src); os.IsNotExist(err) { + if _, err := os.Stat(d.Dst); os.IsNotExist(err) { - file, err := os.OpenFile(d.Dst, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) - if err != nil { - return nil, fmt.Errorf("cannot copy '%s' to '%s' | %s", d.Src, d.Dst, err) + file, err2 := os.OpenFile(d.Dst, os.O_APPEND|os.O_WRONLY|os.O_CREATE, os.FileMode(0777)) + if err2 != nil { + return nil, fmt.Errorf("cannot copy to '%s' | %s", d.Dst, err2) } file.Close() - if err := os.Remove(d.Dst); err != nil { - return nil, fmt.Errorf("cannot tmp file at '%s' | %s", d.Dst, err) + if err2 := os.Remove(d.Dst); err2 != nil { + return nil, fmt.Errorf("cannot remove dry-run file '%s' | %s", d.Dst, err2) } return nil, nil @@ -73,7 +73,7 @@ func (d copy) DryRun(ctx ExecutionContext) ([]byte, error) { // 3. if destination exists : check write permission file, err := os.OpenFile(d.Dst, os.O_APPEND|os.O_WRONLY, 0600) if err != nil { - return nil, fmt.Errorf("cannot copy '%s' to '%s' | %s", d.Src, d.Dst, err) + return nil, fmt.Errorf("cannot copy to '%s' | %s", d.Dst, err) } file.Close()