Removed unnecessary error recovery method and dolt_docs.go

This commit is contained in:
Zach Musgrave
2021-08-04 18:11:39 -07:00
parent 29565615fe
commit 9499872e2e
2 changed files with 2 additions and 71 deletions

View File

@@ -41,12 +41,7 @@ func StageTables(ctx context.Context, roots doltdb.Roots, dbData env.DbData, tbl
}
}
err = stageTables(ctx, roots, rsw, tables)
if err != nil {
env.ResetWorkingDocsToStagedDocs(ctx, roots, rsw)
return err
}
return nil
return stageTables(ctx, roots, rsw, tables)
}
func StageTablesNoDocs(ctx context.Context, roots doltdb.Roots, tbls []string) (doltdb.Roots, error) {
@@ -54,7 +49,6 @@ func StageTablesNoDocs(ctx context.Context, roots doltdb.Roots, tbls []string) (
}
func StageAllTables(ctx context.Context, roots doltdb.Roots, dbData env.DbData) (doltdb.Roots, error) {
rsw := dbData.Rsw
drw := dbData.Drw
docs, err := drw.GetDocsOnDisk()
@@ -72,13 +66,7 @@ func StageAllTables(ctx context.Context, roots doltdb.Roots, dbData env.DbData)
return doltdb.Roots{}, err
}
roots, err = stageTablesNoEnvUpdate(ctx, roots, tbls)
if err != nil {
_ = env.ResetWorkingDocsToStagedDocs(ctx, roots, rsw)
return doltdb.Roots{}, err
}
return roots, nil
return stageTablesNoEnvUpdate(ctx, roots, tbls)
}
func StageAllTablesNoDocs(ctx context.Context, roots doltdb.Roots) (doltdb.Roots, error) {

View File

@@ -1,57 +0,0 @@
// Copyright 2019 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package env
import (
"context"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
)
// ResetWorkingDocsToStagedDocs resets the `dolt_docs` table on the working root to match the staged root.
// If the `dolt_docs` table does not exist on the staged root, it will be removed from the working root.
func ResetWorkingDocsToStagedDocs(
ctx context.Context,
roots doltdb.Roots,
rsw RepoStateWriter,
) error {
stgDocTbl, stgDocsFound, err := roots.Staged.GetTable(ctx, doltdb.DocTableName)
if err != nil {
return err
}
_, wrkDocsFound, err := roots.Working.GetTable(ctx, doltdb.DocTableName)
if err != nil {
return err
}
if wrkDocsFound && !stgDocsFound {
newWrkRoot, err := roots.Working.RemoveTables(ctx, doltdb.DocTableName)
if err != nil {
return err
}
return rsw.UpdateWorkingRoot(ctx, newWrkRoot)
}
if stgDocsFound {
newWrkRoot, err := roots.Working.PutTable(ctx, doltdb.DocTableName, stgDocTbl)
if err != nil {
return err
}
return rsw.UpdateWorkingRoot(ctx, newWrkRoot)
}
return nil
}