From 99764eb91f71e13b9c26734ceb87a0f8fc441bcd Mon Sep 17 00:00:00 2001 From: Alexander Lazarenko Date: Thu, 30 Oct 2025 01:54:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20"=D0=B4=D0=B2=D0=BE=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F"=20`ErrNotFound`=20x2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.go | 10 ++++++---- manager.go | 25 +++++++++++++------------ errors.go => models/errors.go | 2 +- store/filesystem/filesystem.go | 6 +++--- store/sqlite/sqlite.go | 9 +++++---- 5 files changed, 28 insertions(+), 24 deletions(-) rename errors.go => models/errors.go (99%) diff --git a/api.go b/api.go index 19ef16b..619bd26 100644 --- a/api.go +++ b/api.go @@ -4,9 +4,6 @@ import ( "context" "errors" "fmt" - "gitea.unprism.ru/KRBL/Agate/archive" - "gitea.unprism.ru/KRBL/Agate/interfaces" - "gitea.unprism.ru/KRBL/Agate/remote" "io" "log" "os" @@ -14,6 +11,11 @@ import ( "sync" "time" + "gitea.unprism.ru/KRBL/Agate/archive" + "gitea.unprism.ru/KRBL/Agate/interfaces" + "gitea.unprism.ru/KRBL/Agate/models" + "gitea.unprism.ru/KRBL/Agate/remote" + "gitea.unprism.ru/KRBL/Agate/store" "gitea.unprism.ru/KRBL/Agate/stores" ) @@ -480,7 +482,7 @@ func (ag *Agate) RegisterLocalSnapshot(ctx context.Context, snapshotID, parentID return nil // Snapshot already exists } // We expect ErrNotFound, anything else is a real error. - if !errors.Is(err, ErrNotFound) { + if !errors.Is(err, models.ErrNotFound) { return fmt.Errorf("failed to check for existing snapshot: %w", err) } diff --git a/manager.go b/manager.go index 5099f19..cf16515 100644 --- a/manager.go +++ b/manager.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "gitea.unprism.ru/KRBL/Agate/models" "github.com/google/uuid" "gitea.unprism.ru/KRBL/Agate/archive" @@ -49,13 +50,13 @@ func (data *SnapshotManagerData) CreateSnapshot(ctx context.Context, sourceDir s info, err := os.Stat(sourceDir) if err != nil { if os.IsNotExist(err) { - return nil, ErrSourceNotFound + return nil, models.ErrSourceNotFound } return nil, fmt.Errorf("failed to access source directory: %w", err) } if !info.IsDir() { - return nil, ErrSourceNotDirectory + return nil, models.ErrSourceNotDirectory } // Check if parent exists if specified @@ -165,8 +166,8 @@ func (data *SnapshotManagerData) GetSnapshotDetails(ctx context.Context, snapsho // Retrieve snapshot metadata from the store snapshot, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID) if err != nil { - if errors.Is(err, ErrNotFound) { - return nil, ErrNotFound + if errors.Is(err, models.ErrNotFound) { + return nil, models.ErrNotFound } return nil, fmt.Errorf("failed to retrieve snapshot details: %w", err) } @@ -191,7 +192,7 @@ func (data *SnapshotManagerData) DeleteSnapshot(ctx context.Context, snapshotID snapshot, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID) if err != nil { - if errors.Is(err, ErrNotFound) { + if errors.Is(err, models.ErrNotFound) { return nil } return fmt.Errorf("failed to check if snapshot exists: %w", err) @@ -237,8 +238,8 @@ func (data *SnapshotManagerData) OpenFile(ctx context.Context, snapshotID string // First check if the snapshot exists _, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID) if err != nil { - if errors.Is(err, ErrNotFound) { - return nil, ErrNotFound + if errors.Is(err, models.ErrNotFound) { + return nil, models.ErrNotFound } return nil, fmt.Errorf("failed to check if snapshot exists: %w", err) } @@ -261,7 +262,7 @@ func (data *SnapshotManagerData) OpenFile(ctx context.Context, snapshotID string err := archive.ExtractFileFromArchive(blobPath, filePath, pw) if err != nil { if errors.Is(err, archive.ErrFileNotFoundInArchive) { - pw.CloseWithError(ErrFileNotFound) + pw.CloseWithError(models.ErrFileNotFound) return } pw.CloseWithError(fmt.Errorf("failed to extract file from archive: %w", err)) @@ -284,8 +285,8 @@ func (data *SnapshotManagerData) ExtractSnapshot(ctx context.Context, snapshotID // First check if the snapshot exists _, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID) if err != nil { - if errors.Is(err, ErrNotFound) { - return ErrNotFound + if errors.Is(err, models.ErrNotFound) { + return models.ErrNotFound } return fmt.Errorf("failed to check if snapshot exists: %w", err) } @@ -388,8 +389,8 @@ func (data *SnapshotManagerData) UpdateSnapshotMetadata(ctx context.Context, sna snapshot, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID) if err != nil { - if errors.Is(err, ErrNotFound) { - return ErrNotFound + if errors.Is(err, models.ErrNotFound) { + return models.ErrNotFound } return fmt.Errorf("failed to get snapshot metadata: %w", err) } diff --git a/errors.go b/models/errors.go similarity index 99% rename from errors.go rename to models/errors.go index 1489c61..334f579 100644 --- a/errors.go +++ b/models/errors.go @@ -1,4 +1,4 @@ -package agate +package models import "errors" diff --git a/store/filesystem/filesystem.go b/store/filesystem/filesystem.go index 57ca0da..b0bd96c 100644 --- a/store/filesystem/filesystem.go +++ b/store/filesystem/filesystem.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" - agate "gitea.unprism.ru/KRBL/Agate" + "gitea.unprism.ru/KRBL/Agate/models" "gitea.unprism.ru/KRBL/Agate/store" ) @@ -76,7 +76,7 @@ func (fs *fileSystemStore) RetrieveBlob(ctx context.Context, snapshotID string) if err != nil { if os.IsNotExist(err) { // Если файл не найден, возвращаем кастомную ошибку - return nil, agate.ErrNotFound + return nil, models.ErrNotFound } return nil, fmt.Errorf("failed to open blob file %s: %w", blobPath, err) } @@ -110,7 +110,7 @@ func (fs *fileSystemStore) GetBlobPath(ctx context.Context, snapshotID string) ( // Проверяем существование файла if _, err := os.Stat(blobPath); err != nil { if os.IsNotExist(err) { - return "", agate.ErrNotFound + return "", models.ErrNotFound } return "", fmt.Errorf("failed to stat blob file %s: %w", blobPath, err) } diff --git a/store/sqlite/sqlite.go b/store/sqlite/sqlite.go index 8e8782f..3124a06 100644 --- a/store/sqlite/sqlite.go +++ b/store/sqlite/sqlite.go @@ -6,12 +6,13 @@ import ( "encoding/json" "errors" "fmt" - agate "gitea.unprism.ru/KRBL/Agate" - "gitea.unprism.ru/KRBL/Agate/store" - _ "github.com/mattn/go-sqlite3" "os" "path/filepath" "time" + + "gitea.unprism.ru/KRBL/Agate/models" + "gitea.unprism.ru/KRBL/Agate/store" + _ "github.com/mattn/go-sqlite3" ) const ( @@ -131,7 +132,7 @@ func (s *sqliteStore) GetSnapshotMetadata(ctx context.Context, snapshotID string if err != nil { if errors.Is(err, sql.ErrNoRows) { // Если запись не найдена, возвращаем кастомную ошибку - return nil, agate.ErrNotFound + return nil, models.ErrNotFound } return nil, fmt.Errorf("failed to query snapshot %s: %w", snapshotID, err) }