Исправление "двоения" ErrNotFound x2
This commit is contained in:
10
api.go
10
api.go
@@ -4,9 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitea.unprism.ru/KRBL/Agate/archive"
|
|
||||||
"gitea.unprism.ru/KRBL/Agate/interfaces"
|
|
||||||
"gitea.unprism.ru/KRBL/Agate/remote"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -14,6 +11,11 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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/store"
|
||||||
"gitea.unprism.ru/KRBL/Agate/stores"
|
"gitea.unprism.ru/KRBL/Agate/stores"
|
||||||
)
|
)
|
||||||
@@ -480,7 +482,7 @@ func (ag *Agate) RegisterLocalSnapshot(ctx context.Context, snapshotID, parentID
|
|||||||
return nil // Snapshot already exists
|
return nil // Snapshot already exists
|
||||||
}
|
}
|
||||||
// We expect ErrNotFound, anything else is a real error.
|
// 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)
|
return fmt.Errorf("failed to check for existing snapshot: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
manager.go
25
manager.go
@@ -13,6 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.unprism.ru/KRBL/Agate/models"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"gitea.unprism.ru/KRBL/Agate/archive"
|
"gitea.unprism.ru/KRBL/Agate/archive"
|
||||||
@@ -49,13 +50,13 @@ func (data *SnapshotManagerData) CreateSnapshot(ctx context.Context, sourceDir s
|
|||||||
info, err := os.Stat(sourceDir)
|
info, err := os.Stat(sourceDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil, ErrSourceNotFound
|
return nil, models.ErrSourceNotFound
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to access source directory: %w", err)
|
return nil, fmt.Errorf("failed to access source directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
return nil, ErrSourceNotDirectory
|
return nil, models.ErrSourceNotDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if parent exists if specified
|
// Check if parent exists if specified
|
||||||
@@ -165,8 +166,8 @@ func (data *SnapshotManagerData) GetSnapshotDetails(ctx context.Context, snapsho
|
|||||||
// Retrieve snapshot metadata from the store
|
// Retrieve snapshot metadata from the store
|
||||||
snapshot, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID)
|
snapshot, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrNotFound) {
|
if errors.Is(err, models.ErrNotFound) {
|
||||||
return nil, ErrNotFound
|
return nil, models.ErrNotFound
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to retrieve snapshot details: %w", err)
|
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)
|
snapshot, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrNotFound) {
|
if errors.Is(err, models.ErrNotFound) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to check if snapshot exists: %w", err)
|
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
|
// First check if the snapshot exists
|
||||||
_, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID)
|
_, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrNotFound) {
|
if errors.Is(err, models.ErrNotFound) {
|
||||||
return nil, ErrNotFound
|
return nil, models.ErrNotFound
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("failed to check if snapshot exists: %w", err)
|
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)
|
err := archive.ExtractFileFromArchive(blobPath, filePath, pw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, archive.ErrFileNotFoundInArchive) {
|
if errors.Is(err, archive.ErrFileNotFoundInArchive) {
|
||||||
pw.CloseWithError(ErrFileNotFound)
|
pw.CloseWithError(models.ErrFileNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pw.CloseWithError(fmt.Errorf("failed to extract file from archive: %w", err))
|
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
|
// First check if the snapshot exists
|
||||||
_, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID)
|
_, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrNotFound) {
|
if errors.Is(err, models.ErrNotFound) {
|
||||||
return ErrNotFound
|
return models.ErrNotFound
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to check if snapshot exists: %w", err)
|
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)
|
snapshot, err := data.metadataStore.GetSnapshotMetadata(ctx, snapshotID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, ErrNotFound) {
|
if errors.Is(err, models.ErrNotFound) {
|
||||||
return ErrNotFound
|
return models.ErrNotFound
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to get snapshot metadata: %w", err)
|
return fmt.Errorf("failed to get snapshot metadata: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package agate
|
package models
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
agate "gitea.unprism.ru/KRBL/Agate"
|
"gitea.unprism.ru/KRBL/Agate/models"
|
||||||
"gitea.unprism.ru/KRBL/Agate/store"
|
"gitea.unprism.ru/KRBL/Agate/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ func (fs *fileSystemStore) RetrieveBlob(ctx context.Context, snapshotID string)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
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)
|
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 _, err := os.Stat(blobPath); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return "", agate.ErrNotFound
|
return "", models.ErrNotFound
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("failed to stat blob file %s: %w", blobPath, err)
|
return "", fmt.Errorf("failed to stat blob file %s: %w", blobPath, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
agate "gitea.unprism.ru/KRBL/Agate"
|
|
||||||
"gitea.unprism.ru/KRBL/Agate/store"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.unprism.ru/KRBL/Agate/models"
|
||||||
|
"gitea.unprism.ru/KRBL/Agate/store"
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -131,7 +132,7 @@ func (s *sqliteStore) GetSnapshotMetadata(ctx context.Context, snapshotID string
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
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)
|
return nil, fmt.Errorf("failed to query snapshot %s: %w", snapshotID, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user