MCPcopy Create free account
hub / github.com/pydio/cells / processCreateFile

Method processCreateFile

common/sync/proc/create-file.go:59–127  ·  view source on GitHub ↗
(ctx context.Context, operation merger.Operation, operationId string, pg chan int64)

Source from the content-addressed store, hash-verified

57}
58
59func (pr *Processor) processCreateFile(ctx context.Context, operation merger.Operation, operationId string, pg chan int64) error {
60
61 dataTarget, dtOk := model.AsDataSyncTarget(operation.Target())
62 dataSource, dsOk := model.AsDataSyncSource(operation.Source())
63
64 localPath := operation.GetRefPath()
65 if pr.Locker != nil {
66 defer pr.Locker.UnlockFile(operation, localPath)
67 pr.Locker.LockFile(operation, localPath, operationId)
68 }
69 if dtOk && dsOk {
70
71 reader, rErr := dataSource.GetReaderOn(ctx, localPath, operation.GetNode())
72 if rErr != nil {
73 pr.Logger().Error("Cannot get reader on source", zap.String("job", "create"), zap.String("path", localPath), zap.Error(rErr))
74 return rErr
75 }
76 defer reader.Close()
77 wCtx, cancel := context.WithCancel(ctx)
78 writer, writeDone, writeErr, wErr := dataTarget.GetWriterOn(wCtx, localPath, operation.GetNode().GetSize(), operation.GetNode())
79 if wErr != nil {
80 pr.Logger().Error("Cannot get writer on target", zap.String("job", "create"), zap.String("path", localPath), zap.Error(wErr))
81 return wErr
82 }
83 progressReader := &cancellableReaderWithProgress{
84 Reader: reader,
85 pg: pg,
86 canceler: ctx,
87 }
88 _, err := io.Copy(writer, progressReader)
89 if err != nil {
90 cancel() // There was an error during copy, properly cancel the Writer
91 if progressReader.totalRead > 0 {
92 // Revert progress count to 0 for this operation
93 pg <- -progressReader.totalRead
94 }
95 }
96 writer.Close()
97 if err == nil && writeDone != nil {
98 // Wait for real write to be finished
99 for {
100 select {
101 case <-writeDone:
102 return nil
103 case e := <-writeErr:
104 return e
105 }
106 }
107 } else {
108 return err
109 }
110
111 } else {
112
113 pg <- 1
114 update := false
115 if operation.Type() == merger.OpUpdateFile || operation.GetNode().GetUuid() != "" {
116 update = true

Callers

nothing calls this directly

Calls 15

LoggerMethod · 0.95
AsDataSyncTargetFunction · 0.92
AsDataSyncSourceFunction · 0.92
LoggerFunction · 0.92
TargetMethod · 0.65
SourceMethod · 0.65
GetRefPathMethod · 0.65
UnlockFileMethod · 0.65
LockFileMethod · 0.65
GetReaderOnMethod · 0.65
GetNodeMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected