MCPcopy
hub / github.com/kopia/kopia / restoreOutput

Method restoreOutput

cli/command_restore.go:252–315  ·  view source on GitHub ↗
(ctx context.Context, rep repo.Repository)

Source from the content-addressed store, hash-verified

250}
251
252func (c *commandRestore) restoreOutput(ctx context.Context, rep repo.Repository) (restore.Output, error) {
253 err := c.constructTargetPairs(rep)
254 if err != nil {
255 return nil, err
256 }
257
258 targetpath := c.restores[0].target
259
260 m := c.detectRestoreMode(ctx, c.restoreMode, targetpath)
261 switch m {
262 case restoreModeLocal:
263 o := &restore.FilesystemOutput{
264 TargetPath: targetpath,
265 OverwriteDirectories: c.restoreOverwriteDirectories,
266 OverwriteFiles: c.restoreOverwriteFiles,
267 OverwriteSymlinks: c.restoreOverwriteSymlinks,
268 IgnorePermissionErrors: c.restoreIgnorePermissionErrors,
269 WriteFilesAtomically: c.restoreWriteFilesAtomically,
270 SkipOwners: c.restoreSkipOwners,
271 SkipPermissions: c.restoreSkipPermissions,
272 SkipTimes: c.restoreSkipTimes,
273 WriteSparseFiles: c.restoreWriteSparseFiles,
274 FlushFiles: c.flushFiles,
275 }
276
277 if err := o.Init(ctx); err != nil {
278 return nil, errors.Wrap(err, "unable to create output file")
279 }
280
281 return o, nil
282
283 case restoreModeZip, restoreModeZipNoCompress:
284 f, err := os.Create(targetpath) //nolint:gosec
285 if err != nil {
286 return nil, errors.Wrap(err, "unable to create output file")
287 }
288
289 method := zip.Deflate
290 if m == restoreModeZipNoCompress {
291 method = zip.Store
292 }
293
294 return restore.NewZipOutput(f, method), nil
295
296 case restoreModeTar:
297 f, err := os.Create(targetpath) //nolint:gosec
298 if err != nil {
299 return nil, errors.Wrap(err, "unable to create output file")
300 }
301
302 return restore.NewTarOutput(f), nil
303
304 case restoreModeTgz:
305 f, err := os.Create(targetpath) //nolint:gosec
306 if err != nil {
307 return nil, errors.Wrap(err, "unable to create output file")
308 }
309

Callers 1

runMethod · 0.95

Calls 7

constructTargetPairsMethod · 0.95
detectRestoreModeMethod · 0.95
InitMethod · 0.95
NewZipOutputFunction · 0.92
NewTarOutputFunction · 0.92
ErrorfMethod · 0.80
NewWriterMethod · 0.65

Tested by

no test coverage detected