MCPcopy
hub / github.com/slimtoolkit/slim / CopyAndObfuscateFile

Function CopyAndObfuscateFile

pkg/util/fsutil/fsutil.go:640–670  ·  view source on GitHub ↗

CopyAndObfuscateFile copies a regular file and performs basic file reference obfuscation

(
	clone bool,
	src string,
	dst string,
	makeDir bool)

Source from the content-addressed store, hash-verified

638
639// CopyAndObfuscateFile copies a regular file and performs basic file reference obfuscation
640func 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
673func AppendToFile(target string, data []byte, preserveTimes bool) error {

Callers 1

saveArtifactsMethod · 0.92

Calls 1

CopyRegularFileFunction · 0.85

Tested by

no test coverage detected