From 95d880c63069c417c271871ac05e9a20c63d8236 Mon Sep 17 00:00:00 2001 From: davrot Date: Sun, 26 Jan 2025 22:22:38 +0000 Subject: [PATCH] =?UTF-8?q?Dateien=20nach=20=E2=80=9Eservices/repository/f?= =?UTF-8?q?iles=E2=80=9C=20hochladen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/repository/files/update.go | 130 ++++++++++------------------ 1 file changed, 45 insertions(+), 85 deletions(-) diff --git a/services/repository/files/update.go b/services/repository/files/update.go index 4fdb625cf6..df6f341183 100644 --- a/services/repository/files/update.go +++ b/services/repository/files/update.go @@ -92,65 +92,54 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use return nil, err } - var treePaths []string if opts.IsDir { - var newFiles []*ChangeRepoFile - for _, file := range opts.Files { - if file.Operation != "delete" { - return nil, errors.New("invalid operation: only delete is allowed for directory paths") + for _, file := range opts.Files { + if file.Operation != "delete" { + return nil, errors.New("invalid operation: only delete is allowed for directory paths") + } + treePath := CleanUploadFileName(file.TreePath) + filelist, err := gitRepo.LsFilesFromDirectory(treePath) + if err != nil { + return nil, err + } + log.Error("yyyyyy(0): %+v", gitRepo) + log.Error("yyyyyy(0): %+v", treePath) + log.Error("yyyyyy(1): %+v", filelist) + log.Error("yyyyyy(2): %+v", file) + log.Error("yyyyyy(3): %T", file) + // &{Operation:delete TreePath:blabla FromTreePath: ContentReader: SHA: Options:} } - // Clean up and validate paths - treePath := CleanUploadFileName(file.TreePath) - if treePath == "" { - return nil, models.ErrFilenameInvalid{ - Path: file.TreePath, - } - } - dirFiles, err := ListFilesInDirectory(ctx, gitRepo, treePath) - if err != nil { - return nil, err - } - for _, dirFile := range dirFiles { - treePaths = append(treePaths, dirFile) - newFiles = append(newFiles, &ChangeRepoFile{ - TreePath: dirFile, - Options: &RepoFileOptions{ - treePath: dirFile, - fromTreePath: "", - executable: false, - }, - }) - } - } - opts.Files = newFiles - } else { - for _, file := range opts.Files { - // If FromTreePath is not set, set it to the opts.TreePath - if file.TreePath != "" && file.FromTreePath == "" { - file.FromTreePath = file.TreePath - } - // Check that the path given in opts.treePath is valid (not a git path) - treePath := CleanUploadFileName(file.TreePath) - if treePath == "" { - return nil, models.ErrFilenameInvalid{ - Path: file.TreePath, - } - } - // If there is a fromTreePath (we are copying it), also clean it up - fromTreePath := CleanUploadFileName(file.FromTreePath) - if fromTreePath == "" && file.FromTreePath != "" { - return nil, models.ErrFilenameInvalid{ - Path: file.FromTreePath, - } - } + return nil, errors.New("Test") + } - file.Options = &RepoFileOptions{ - treePath: treePath, - fromTreePath: fromTreePath, - executable: false, - } - treePaths = append(treePaths, treePath) - } + var treePaths []string + for _, file := range opts.Files { + // If FromTreePath is not set, set it to the opts.TreePath + if file.TreePath != "" && file.FromTreePath == "" { + file.FromTreePath = file.TreePath + } + + // Check that the path given in opts.treePath is valid (not a git path) + treePath := CleanUploadFileName(file.TreePath) + if treePath == "" { + return nil, models.ErrFilenameInvalid{ + Path: file.TreePath, + } + } + // If there is a fromTreePath (we are copying it), also clean it up + fromTreePath := CleanUploadFileName(file.FromTreePath) + if fromTreePath == "" && file.FromTreePath != "" { + return nil, models.ErrFilenameInvalid{ + Path: file.FromTreePath, + } + } + + file.Options = &RepoFileOptions{ + treePath: treePath, + fromTreePath: fromTreePath, + executable: false, + } + treePaths = append(treePaths, treePath) } // A NewBranch can be specified for the file to be created/updated in a new branch. @@ -309,35 +298,6 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use return filesResponse, nil } - -// Helper function to recursively list files in a directory -func ListFilesInDirectory(ctx context.Context, gitRepo *git.Repository, dirPath string) ([]string, error) { - var files []string -// -// // Implement recursive directory traversal -// // This would use gitRepo methods to list files -// // For example: -// commit, err := gitRepo.GetBranchCommit(gitRepo.DefaultBranch) -// if err != nil { -// return nil, err -// } - -// tree, err := commit.SubTree(dirPath) -// if err != nil { -// return nil, err -// } -// -// err = tree.Walk(func(path string, entry *git.TreeEntry) error { -// if entry.Type == git.EntryBlob { -// files = append(files, filepath.Join(dirPath, path)) -// } -// return nil -// }) - -// return files, err - return files, nil -} - // handles the check for various issues for ChangeRepoFiles func handleCheckErrors(file *ChangeRepoFile, commit *git.Commit, opts *ChangeRepoFilesOptions) error { if file.Operation == "update" || file.Operation == "delete" {