Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ func (m *Manager) RebuildReferences() error {
return nil
}

// VaultRoot returns the root directory of the vault.
func (m *Manager) VaultRoot() string {
return m.vaultRoot
}

// Helper function to load a file manifest
func loadFileManifest(path string) (*FileManifest, error) {
// Read manifest file
Expand Down
35 changes: 33 additions & 2 deletions internal/p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/libp2p/go-libp2p/core/protocol"

"github.com/substantialcattle5/sietch/internal/config"
"github.com/substantialcattle5/sietch/internal/manifest" //golangci-lint error
)

const (
Expand Down Expand Up @@ -916,8 +917,38 @@ func (s *SyncService) SyncWithPeer(ctx context.Context, peerID peer.ID) (*SyncRe
result.BytesTransferred += int64(size)
}

// Step 5: Update file manifests
result.FileCount = len(remoteManifest.Files) - len(localManifest.Files)
// Step 5: Save file manifests for synced files
fmt.Println("Saving file manifests...")
savedCount := 0
for _, remoteFile := range remoteManifest.Files {
// Check if this file already exists locally
exists := false
for _, localFile := range localManifest.Files {
if localFile.FilePath == remoteFile.FilePath {
exists = true
break
}
}

if !exists {
// Create a copy of the file manifest to avoid pointer issues
fileManifest := remoteFile

err := manifest.StoreFileManifest(
s.vaultMgr.VaultRoot(),
fileManifest.FilePath,
&fileManifest,
)
if err != nil {
return nil, fmt.Errorf("failed to save manifest for %s: %v",
fileManifest.FilePath, err)
}
fmt.Printf("Saved manifest for: %s\n", fileManifest.FilePath)
savedCount++
}
}
fmt.Printf("Saved %d file manifests\n", savedCount)
result.FileCount = savedCount

// Step 6: Rebuild references
if err := s.vaultMgr.RebuildReferences(); err != nil {
Expand Down
Loading