fix DryRun() for instruction/copy : create/remove file if does not exist, else try to open in WRITE mode
This commit is contained in:
parent
1a7e1c2db0
commit
fa8a0a5ae5
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue