MCPcopy Create free account
hub / github.com/OpenCSGs/csghub-server / removeFiles

Method removeFiles

component/callback/git_callback.go:222–265  ·  view source on GitHub ↗
(ctx context.Context, repoType, namespace, repoName, ref string, fileNames []string)

Source from the content-addressed store, hash-verified

220}
221
222func (c *GitCallbackComponent) removeFiles(ctx context.Context, repoType, namespace, repoName, ref string, fileNames []string) error {
223 // handle removed files
224 // delete tagss
225 for _, fileName := range fileNames {
226 slog.Debug("remove file", slog.String("file", fileName))
227 // update model runtime
228 c.updateModelRuntimeFrameworks(ctx, repoType, namespace, repoName, ref, fileName, true)
229 // only care about readme file under root directory
230 if fileName == ReadmeFileName {
231 // use empty content to clear all the meta tags
232 const content string = ""
233 adjustedRepoType := types.RepositoryType(strings.TrimSuffix(repoType, "s"))
234 err := c.tc.ClearMetaTags(ctx, adjustedRepoType, namespace, repoName)
235 if err != nil {
236 slog.Error("failed to clear meta tags", slog.String("content", content),
237 slog.String("repo", path.Join(namespace, repoName)), slog.String("ref", ref),
238 slog.Any("error", err))
239 return fmt.Errorf("failed to clear met tags,cause: %w", err)
240 }
241 } else {
242 var tagScope database.TagScope
243 switch repoType {
244 case DatasetRepoType:
245 tagScope = database.DatasetTagScope
246 case ModelRepoType:
247 tagScope = database.ModelTagScope
248 default:
249 return nil
250 // case CodeRepoType:
251 // tagScope = database.CodeTagScope
252 // case SpaceRepoType:
253 // tagScope = database.SpaceTagScope
254 }
255 err := c.tc.UpdateLibraryTags(ctx, tagScope, namespace, repoName, fileName, "")
256 if err != nil {
257 slog.Error("failed to remove Library tag", slog.String("namespace", namespace),
258 slog.String("name", repoName), slog.String("ref", ref), slog.String("fileName", fileName),
259 slog.Any("error", err))
260 return fmt.Errorf("failed to remove Library tag, cause: %w", err)
261 }
262 }
263 }
264 return nil
265}
266
267func (c *GitCallbackComponent) addFiles(ctx context.Context, repoType, namespace, repoName, ref string, fileNames []string) error {
268 for _, fileName := range fileNames {

Callers 1

HandlePushMethod · 0.95

Calls 5

RepositoryTypeTypeAlias · 0.92
ClearMetaTagsMethod · 0.80
ErrorMethod · 0.80
UpdateLibraryTagsMethod · 0.80

Tested by

no test coverage detected