CopyAndObfuscateFile copies a regular file and performs basic file reference obfuscation
( clone bool, src string, dst string, makeDir bool)
| 638 | |
| 639 | // CopyAndObfuscateFile copies a regular file and performs basic file reference obfuscation |
| 640 | func CopyAndObfuscateFile( |
| 641 | clone bool, |
| 642 | src string, |
| 643 | dst string, |
| 644 | makeDir bool) error { |
| 645 | log.Debugf("CopyAndObfuscateFile(%v,%v,%v,%v)", clone, src, dst, makeDir) |
| 646 | |
| 647 | //need to preserve the extension because some of the app stacks |
| 648 | //depend on it for its compile/run time behavior |
| 649 | base := filepath.Base(dst) |
| 650 | ext := filepath.Ext(base) |
| 651 | base = strings.ReplaceAll(base, ".", "..") |
| 652 | base = fmt.Sprintf(".d.%s", base) |
| 653 | if ext != "" { |
| 654 | base = fmt.Sprintf("%s%s", base, ext) |
| 655 | } |
| 656 | |
| 657 | dirPart := filepath.Dir(dst) |
| 658 | dstData := filepath.Join(dirPart, base) |
| 659 | err := CopyRegularFile(clone, src, dstData, makeDir) |
| 660 | if err != nil { |
| 661 | return err |
| 662 | } |
| 663 | |
| 664 | err = os.Symlink(base, dst) |
| 665 | if err != nil { |
| 666 | return err |
| 667 | } |
| 668 | |
| 669 | return nil |
| 670 | } |
| 671 | |
| 672 | // AppendToFile appends the provided data to the target file |
| 673 | func AppendToFile(target string, data []byte, preserveTimes bool) error { |
no test coverage detected