MCPcopy Index your code
hub / github.com/kopia/kopia / getOutput

Function getOutput

cli/command_policy_export.go:98–125  ·  view source on GitHub ↗
(c *commandPolicyExport)

Source from the content-addressed store, hash-verified

96}
97
98func getOutput(c *commandPolicyExport) (io.Writer, error) {
99 var err error
100
101 if c.filePath == "" {
102 if c.overwrite {
103 return nil, errors.New("overwrite was passed but no file path was given")
104 }
105
106 return c.svc.stdout(), nil
107 }
108
109 var file *os.File
110
111 if c.overwrite {
112 file, err = os.Create(c.filePath)
113 } else {
114 file, err = os.OpenFile(c.filePath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, exportFilePerms)
115 if os.IsExist(err) {
116 return nil, errors.Wrap(err, "file already exists and overwrite flag is not set")
117 }
118 }
119
120 if err != nil {
121 return nil, errors.Wrap(err, "error opening file to write to")
122 }
123
124 return file, nil
125}

Callers 1

runMethod · 0.85

Calls 3

stdoutMethod · 0.65
IsExistMethod · 0.65
OpenFileMethod · 0.45

Tested by

no test coverage detected