mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-04 14:46:57 -05:00
Merge branch 'main' into add-priority-to-ProtectedBranch
This commit is contained in:
commit
7588f5442b
@ -50,25 +50,35 @@ func (repo *Repository) readTreeToIndex(id ObjectID, indexFilename ...string) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadTreeToTemporaryIndex reads a treeish to a temporary index file
|
// ReadTreeToTemporaryIndex reads a treeish to a temporary index file
|
||||||
func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename, tmpDir string, cancel context.CancelFunc, err error) {
|
func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (tmpIndexFilename, tmpDir string, cancel context.CancelFunc, err error) {
|
||||||
tmpDir, err = os.MkdirTemp("", "index")
|
defer func() {
|
||||||
if err != nil {
|
// if error happens and there is a cancel function, do clean up
|
||||||
return filename, tmpDir, cancel, err
|
if err != nil && cancel != nil {
|
||||||
}
|
cancel()
|
||||||
|
cancel = nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
filename = filepath.Join(tmpDir, ".tmp-index")
|
removeDirFn := func(dir string) func() { // it can't use the return value "tmpDir" directly because it is empty when error occurs
|
||||||
cancel = func() {
|
return func() {
|
||||||
err := util.RemoveAll(tmpDir)
|
if err := util.RemoveAll(dir); err != nil {
|
||||||
if err != nil {
|
log.Error("failed to remove tmp index dir: %v", err)
|
||||||
log.Error("failed to remove tmp index file: %v", err)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = repo.ReadTreeToIndex(treeish, filename)
|
|
||||||
|
tmpDir, err = os.MkdirTemp("", "index")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
defer cancel()
|
return "", "", nil, err
|
||||||
return "", "", func() {}, err
|
|
||||||
}
|
}
|
||||||
return filename, tmpDir, cancel, err
|
|
||||||
|
tmpIndexFilename = filepath.Join(tmpDir, ".tmp-index")
|
||||||
|
cancel = removeDirFn(tmpDir)
|
||||||
|
err = repo.ReadTreeToIndex(treeish, tmpIndexFilename)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", cancel, err
|
||||||
|
}
|
||||||
|
return tmpIndexFilename, tmpDir, cancel, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmptyIndex empties the index
|
// EmptyIndex empties the index
|
||||||
|
Loading…
Reference in New Issue
Block a user