mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-10 18:10:49 +09:00
GO-1664: replace filepath with ***
Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
parent
81720d748e
commit
a215ff3541
12 changed files with 84 additions and 26 deletions
|
@ -35,6 +35,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/space"
|
||||
"github.com/anyproto/anytype-heart/util/builtinobjects"
|
||||
"github.com/anyproto/anytype-heart/util/constant"
|
||||
oserror "github.com/anyproto/anytype-heart/util/os"
|
||||
"github.com/anyproto/anytype-heart/util/pbtypes"
|
||||
)
|
||||
|
||||
|
@ -139,7 +140,7 @@ func (mw *Middleware) AccountCreate(cctx context.Context, req *pb.RpcAccountCrea
|
|||
storePath := filepath.Join(req.StorePath, address)
|
||||
err := os.MkdirAll(storePath, 0700)
|
||||
if err != nil {
|
||||
return response(nil, pb.RpcAccountCreateResponseError_FAILED_TO_CREATE_LOCAL_REPO, fmt.Errorf("failed to create store path"))
|
||||
return response(nil, pb.RpcAccountCreateResponseError_FAILED_TO_CREATE_LOCAL_REPO, oserror.TransformError(err))
|
||||
}
|
||||
if err := config.WriteJsonConfig(configPath, config.ConfigRequired{CustomFileStorePath: storePath}); err != nil {
|
||||
return response(nil, pb.RpcAccountCreateResponseError_FAILED_TO_WRITE_CONFIG, err)
|
||||
|
@ -355,7 +356,7 @@ func (mw *Middleware) AccountStop(cctx context.Context, req *pb.RpcAccountStopRe
|
|||
if req.RemoveData {
|
||||
err := mw.AccountRemoveLocalData()
|
||||
if err != nil {
|
||||
return response(pb.RpcAccountStopResponseError_FAILED_TO_REMOVE_ACCOUNT_DATA, fmt.Errorf("failed to revoce local account data"))
|
||||
return response(pb.RpcAccountStopResponseError_FAILED_TO_REMOVE_ACCOUNT_DATA, oserror.TransformError(err))
|
||||
}
|
||||
} else {
|
||||
err := mw.stop()
|
||||
|
@ -415,13 +416,13 @@ func (mw *Middleware) AccountMove(cctx context.Context, req *pb.RpcAccountMoveRe
|
|||
|
||||
if _, err := os.Stat(destination); !os.IsNotExist(err) { // if already exist (in case of the previous fail moving)
|
||||
if err := removeDirs(destination, dirs); err != nil {
|
||||
return response(pb.RpcAccountMoveResponseError_FAILED_TO_REMOVE_ACCOUNT_DATA, fmt.Errorf("failed to remove local repo"))
|
||||
return response(pb.RpcAccountMoveResponseError_FAILED_TO_REMOVE_ACCOUNT_DATA, oserror.TransformError(err))
|
||||
}
|
||||
}
|
||||
|
||||
err := os.MkdirAll(destination, 0700)
|
||||
if err != nil {
|
||||
return response(pb.RpcAccountMoveResponseError_FAILED_TO_CREATE_LOCAL_REPO, fmt.Errorf("failed to create local repo"))
|
||||
return response(pb.RpcAccountMoveResponseError_FAILED_TO_CREATE_LOCAL_REPO, oserror.TransformError(err))
|
||||
}
|
||||
|
||||
err = mw.stop()
|
||||
|
@ -443,12 +444,12 @@ func (mw *Middleware) AccountMove(cctx context.Context, req *pb.RpcAccountMoveRe
|
|||
}
|
||||
|
||||
if err := removeDirs(srcPath, dirs); err != nil {
|
||||
return response(pb.RpcAccountMoveResponseError_FAILED_TO_REMOVE_ACCOUNT_DATA, fmt.Errorf("failed to create account repo"))
|
||||
return response(pb.RpcAccountMoveResponseError_FAILED_TO_REMOVE_ACCOUNT_DATA, oserror.TransformError(err))
|
||||
}
|
||||
|
||||
if srcPath != conf.RepoPath { // remove root account dir, if move not from anytype source dir
|
||||
if err := os.RemoveAll(srcPath); err != nil {
|
||||
return response(pb.RpcAccountMoveResponseError_FAILED_TO_REMOVE_ACCOUNT_DATA, fmt.Errorf("failed to remove local repo"))
|
||||
return response(pb.RpcAccountMoveResponseError_FAILED_TO_REMOVE_ACCOUNT_DATA, oserror.TransformError(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -565,7 +566,7 @@ func (mw *Middleware) AccountRecoverFromLegacyExport(cctx context.Context,
|
|||
}
|
||||
profile, err := getUserProfile(req)
|
||||
if err != nil {
|
||||
return response("", pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, fmt.Errorf("failed to read profile file"))
|
||||
return response("", pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, oserror.TransformError(err))
|
||||
}
|
||||
address, code, err := mw.createAccountFromExport(profile, req)
|
||||
if err != nil {
|
||||
|
@ -620,7 +621,7 @@ func (mw *Middleware) createAccountFromExport(profile *pb.Profile, req *pb.RpcAc
|
|||
mw.rootPath = req.RootPath
|
||||
err = os.MkdirAll(mw.rootPath, 0700)
|
||||
if err != nil {
|
||||
return "", pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, fmt.Errorf("failed to create account data repo")
|
||||
return "", pb.RpcAccountRecoverFromLegacyExportResponseError_UNKNOWN_ERROR, oserror.TransformError(err)
|
||||
}
|
||||
mw.accountSearchCancel()
|
||||
if _, statErr := os.Stat(filepath.Join(mw.rootPath, address)); os.IsNotExist(statErr) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/pkg/lib/core"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/logging"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
|
||||
oserror "github.com/anyproto/anytype-heart/util/os"
|
||||
"github.com/anyproto/anytype-heart/util/pbtypes"
|
||||
)
|
||||
|
||||
|
@ -356,7 +357,7 @@ func (dp *dropFilesProcess) Init(paths []string) (err error) {
|
|||
entry := &dropFileEntry{path: path, name: filepath.Base(path)}
|
||||
ok, e := dp.readdir(entry, true)
|
||||
if e != nil {
|
||||
return fmt.Errorf("failed to read file path")
|
||||
return oserror.TransformError(err)
|
||||
}
|
||||
if ok {
|
||||
dp.root.child = append(dp.root.child, entry)
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/pkg/lib/core"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/mill"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
|
||||
oserror "github.com/anyproto/anytype-heart/util/os"
|
||||
"github.com/anyproto/anytype-heart/util/uri"
|
||||
)
|
||||
|
||||
|
@ -258,7 +259,7 @@ func (u *uploader) SetFile(path string) Uploader {
|
|||
u.getReader = func(ctx context.Context) (*fileReader, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open file")
|
||||
return nil, oserror.TransformError(err)
|
||||
}
|
||||
|
||||
buf := bufio.NewReaderSize(f, bufSize)
|
||||
|
|
|
@ -3,7 +3,6 @@ package export
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -37,6 +36,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
|
||||
"github.com/anyproto/anytype-heart/space/typeprovider"
|
||||
"github.com/anyproto/anytype-heart/util/constant"
|
||||
oserror "github.com/anyproto/anytype-heart/util/os"
|
||||
"github.com/anyproto/anytype-heart/util/pbtypes"
|
||||
"github.com/anyproto/anytype-heart/util/text"
|
||||
)
|
||||
|
@ -99,12 +99,12 @@ func (e *export) Export(req pb.RpcObjectListExportRequest) (path string, succeed
|
|||
var wr writer
|
||||
if req.Zip {
|
||||
if wr, err = newZipWriter(req.Path, tempFileName); err != nil {
|
||||
err = fmt.Errorf("failed to create zip file")
|
||||
err = oserror.TransformError(err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if wr, err = newDirWriter(req.Path, req.IncludeFiles); err != nil {
|
||||
err = fmt.Errorf("failed to create direcotory file")
|
||||
err = oserror.TransformError(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/core/block/process"
|
||||
"github.com/anyproto/anytype-heart/core/files"
|
||||
"github.com/anyproto/anytype-heart/pb"
|
||||
oserror "github.com/anyproto/anytype-heart/util/os"
|
||||
)
|
||||
|
||||
// TODO Move residual file methods here
|
||||
|
@ -23,7 +24,7 @@ func (s *Service) DownloadFile(req *pb.RpcFileDownloadRequest) (string, error) {
|
|||
|
||||
err := os.MkdirAll(req.Path, 0755)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("mkdir -p: %w", err)
|
||||
return "", fmt.Errorf("mkdir -p: %w", oserror.TransformError(err))
|
||||
}
|
||||
progress := process.NewProgress(pb.ModelProcess_SaveFile)
|
||||
defer progress.Finish()
|
||||
|
|
|
@ -64,7 +64,7 @@ func (n *Notion) GetSnapshots(req *pb.RpcObjectImportRequest, progress process.P
|
|||
|
||||
// always add this error because it's mean that we need to return error to user, even in case IGNORE_ERRORS is turned on
|
||||
// see shouldReturnError
|
||||
ce.Add("", converter.ErrFailedToReceiveListOfObjects)
|
||||
ce.Add(converter.ErrFailedToReceiveListOfObjects)
|
||||
logger.With("err", ce.Error()).With("pages", len(pages)).With("dbs", len(db)).Error("import from notion failed")
|
||||
return nil, ce
|
||||
}
|
||||
|
|
|
@ -19627,7 +19627,6 @@ var xxx_messageInfo_RpcObjectImport proto.InternalMessageInfo
|
|||
|
||||
type RpcObjectImportRequest struct {
|
||||
// Types that are valid to be assigned to Params:
|
||||
//
|
||||
// *RpcObjectImportRequestParamsOfNotionParams
|
||||
// *RpcObjectImportRequestParamsOfBookmarksParams
|
||||
// *RpcObjectImportRequestParamsOfMarkdownParams
|
||||
|
@ -31176,7 +31175,6 @@ type RpcBlockListUpdateRequest struct {
|
|||
ContextId string `protobuf:"bytes,1,opt,name=contextId,proto3" json:"contextId,omitempty"`
|
||||
BlockIds []string `protobuf:"bytes,2,rep,name=blockIds,proto3" json:"blockIds,omitempty"`
|
||||
// Types that are valid to be assigned to Field:
|
||||
//
|
||||
// *RpcBlockListUpdateRequestFieldOfText
|
||||
// *RpcBlockListUpdateRequestFieldOfBackgroundColor
|
||||
// *RpcBlockListUpdateRequestFieldOfAlign
|
||||
|
@ -31328,7 +31326,6 @@ func (*RpcBlockListUpdateRequest) XXX_OneofWrappers() []interface{} {
|
|||
|
||||
type RpcBlockListUpdateRequestText struct {
|
||||
// Types that are valid to be assigned to Field:
|
||||
//
|
||||
// *RpcBlockListUpdateRequestTextFieldOfStyle
|
||||
// *RpcBlockListUpdateRequestTextFieldOfColor
|
||||
// *RpcBlockListUpdateRequestTextFieldOfMark
|
||||
|
|
|
@ -7332,7 +7332,6 @@ func (m *EventBlockDataviewViewUpdateFields) GetDefaultTemplateId() string {
|
|||
|
||||
type EventBlockDataviewViewUpdateFilter struct {
|
||||
// Types that are valid to be assigned to Operation:
|
||||
//
|
||||
// *EventBlockDataviewViewUpdateFilterOperationOfAdd
|
||||
// *EventBlockDataviewViewUpdateFilterOperationOfRemove
|
||||
// *EventBlockDataviewViewUpdateFilterOperationOfUpdate
|
||||
|
@ -7654,7 +7653,6 @@ func (m *EventBlockDataviewViewUpdateFilterMove) GetIds() []string {
|
|||
|
||||
type EventBlockDataviewViewUpdateRelation struct {
|
||||
// Types that are valid to be assigned to Operation:
|
||||
//
|
||||
// *EventBlockDataviewViewUpdateRelationOperationOfAdd
|
||||
// *EventBlockDataviewViewUpdateRelationOperationOfRemove
|
||||
// *EventBlockDataviewViewUpdateRelationOperationOfUpdate
|
||||
|
@ -7982,7 +7980,6 @@ func (m *EventBlockDataviewViewUpdateRelationMove) GetIds() []string {
|
|||
|
||||
type EventBlockDataviewViewUpdateSort struct {
|
||||
// Types that are valid to be assigned to Operation:
|
||||
//
|
||||
// *EventBlockDataviewViewUpdateSortOperationOfAdd
|
||||
// *EventBlockDataviewViewUpdateSortOperationOfRemove
|
||||
// *EventBlockDataviewViewUpdateSortOperationOfUpdate
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/anyproto/anytype-heart/core/wallet"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/datastore"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/logging"
|
||||
oserror "github.com/anyproto/anytype-heart/util/os"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -116,12 +117,12 @@ func (r *clientds) Init(a *app.App) (err error) {
|
|||
|
||||
r.localstoreDS, err = dsbadgerv3.NewDatastore(r.getRepoPath(localstoreDSDir), &r.cfg.Localstore)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to init local datastore")
|
||||
return oserror.TransformError(err)
|
||||
}
|
||||
|
||||
r.spaceDS, err = dsbadgerv3.NewDatastore(r.getRepoPath(SpaceDSDir), &r.cfg.Spacestore)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to init space datastore")
|
||||
return oserror.TransformError(err)
|
||||
}
|
||||
|
||||
err = r.migrateIfNeeded()
|
||||
|
|
|
@ -1427,7 +1427,6 @@ type Block struct {
|
|||
Align BlockAlign `protobuf:"varint,6,opt,name=align,proto3,enum=anytype.model.BlockAlign" json:"align,omitempty"`
|
||||
VerticalAlign BlockVerticalAlign `protobuf:"varint,7,opt,name=verticalAlign,proto3,enum=anytype.model.BlockVerticalAlign" json:"verticalAlign,omitempty"`
|
||||
// Types that are valid to be assigned to Content:
|
||||
//
|
||||
// *BlockContentOfSmartblock
|
||||
// *BlockContentOfText
|
||||
// *BlockContentOfFile
|
||||
|
@ -3284,7 +3283,6 @@ func (m *BlockContentDataviewObjectOrder) GetObjectIds() []string {
|
|||
type BlockContentDataviewGroup struct {
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
// Types that are valid to be assigned to Value:
|
||||
//
|
||||
// *BlockContentDataviewGroupValueOfStatus
|
||||
// *BlockContentDataviewGroupValueOfTag
|
||||
// *BlockContentDataviewGroupValueOfCheckbox
|
||||
|
@ -4065,7 +4063,6 @@ func (m *Account) GetInfo() *AccountInfo {
|
|||
// Avatar of a user's account. It could be an image or color
|
||||
type AccountAvatar struct {
|
||||
// Types that are valid to be assigned to Avatar:
|
||||
//
|
||||
// *AccountAvatarAvatarOfImage
|
||||
// *AccountAvatarAvatarOfColor
|
||||
Avatar IsAccountAvatarAvatar `protobuf_oneof:"avatar"`
|
||||
|
|
25
util/os/error.go
Normal file
25
util/os/error.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package os
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func TransformError(err error) error {
|
||||
if pathErr, ok := err.(*os.PathError); ok {
|
||||
filePathParts := strings.Split(pathErr.Path, string(filepath.Separator))
|
||||
anonymizedFilePathParts := lo.Map(filePathParts, func(item string, index int) string {
|
||||
if item == "" {
|
||||
return ""
|
||||
}
|
||||
return strings.ReplaceAll(item, item, "***")
|
||||
})
|
||||
newPath := strings.Join(anonymizedFilePathParts, string(filepath.Separator))
|
||||
pathErr.Path = newPath
|
||||
return pathErr
|
||||
}
|
||||
return err
|
||||
}
|
37
util/os/error_test.go
Normal file
37
util/os/error_test.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package os
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTransformError(t *testing.T) {
|
||||
sep := string(filepath.Separator)
|
||||
pathError := &os.PathError{
|
||||
Op: "read",
|
||||
Path: sep + "test" + sep + "file" + sep + "path" + sep,
|
||||
Err: fmt.Errorf("test"),
|
||||
}
|
||||
|
||||
resultErrorMessage := "read /***/***/***/: test"
|
||||
assert.NotNil(t, TransformError(pathError))
|
||||
assert.Equal(t, resultErrorMessage, TransformError(pathError).Error())
|
||||
|
||||
pathError = &os.PathError{
|
||||
Op: "read",
|
||||
Path: "test" + sep + "file",
|
||||
Err: fmt.Errorf("test"),
|
||||
}
|
||||
|
||||
resultErrorMessage = "read ***/***: test"
|
||||
assert.NotNil(t, TransformError(pathError))
|
||||
assert.Equal(t, resultErrorMessage, TransformError(pathError).Error())
|
||||
|
||||
err := fmt.Errorf("test")
|
||||
resultErrorMessage = "test"
|
||||
assert.NotNil(t, TransformError(err))
|
||||
assert.Equal(t, resultErrorMessage, TransformError(err).Error())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue