MCPcopy
hub / github.com/go-git/go-git / save

Method save

storage/filesystem/dotgit/writers.go:133–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131}
132
133func (w *PackWriter) save() error {
134 base := w.fs.Join(objectsPath, packPath, fmt.Sprintf("pack-%s", w.checksum))
135
136 // Pack files are content addressable. Each file is checked
137 // individually — if it already exists on disk, skip creating it.
138 idxPath := fmt.Sprintf("%s.idx", base)
139 exists, err := fileExists(w.fs, idxPath)
140 if err != nil {
141 return err
142 }
143 if !exists {
144 idx, err := w.fs.Create(idxPath)
145 if err != nil {
146 return err
147 }
148
149 if err := w.encodeIdx(idx); err != nil {
150 _ = idx.Close()
151 return err
152 }
153
154 if err := idx.Close(); err != nil {
155 return err
156 }
157 fixPermissions(w.fs, idxPath)
158 }
159
160 packPath := fmt.Sprintf("%s.pack", base)
161 exists, err = fileExists(w.fs, packPath)
162 if err != nil {
163 return err
164 }
165 if !exists {
166 if err := w.fs.Rename(w.fw.Name(), packPath); err != nil {
167 return err
168 }
169 fixPermissions(w.fs, packPath)
170 } else {
171 // Pack already exists, clean up the temp file.
172 return w.clean()
173 }
174
175 return nil
176}
177
178// fileExists checks whether path already exists as a regular file.
179// It returns (true, nil) for an existing regular file, (false, nil) when the

Callers 1

CloseMethod · 0.95

Calls 9

encodeIdxMethod · 0.95
cleanMethod · 0.95
fileExistsFunction · 0.85
JoinMethod · 0.80
fixPermissionsFunction · 0.70
CloseMethod · 0.65
NameMethod · 0.65
CreateMethod · 0.45
RenameMethod · 0.45

Tested by

no test coverage detected