Skip to content

fix: get command now uses deduplication manager for chunk retrieval#106

Closed
kpj2006 wants to merge 1 commit intoS4tvara:mainfrom
kpj2006:fix-get-command-deduplication
Closed

fix: get command now uses deduplication manager for chunk retrieval#106
kpj2006 wants to merge 1 commit intoS4tvara:mainfrom
kpj2006:fix-get-command-deduplication

Conversation

@kpj2006
Copy link
Copy Markdown

@kpj2006 kpj2006 commented Oct 5, 2025

fix: #93

1. Initialize Deduplication Manager

Added in cmd/get.go after passphrase retrieval:

// Initialize deduplication manager
dedupManager, err := deduplication.NewManager(vaultRoot, vaultConfig.Deduplication)
if err != nil {
    return fmt.Errorf("failed to initialize deduplication manager: %v", err)
}

2. Replaced Direct Filesystem Access

Before (Broken):

// Get the chunk path
chunkPath := filepath.Join(vaultRoot, ".sietch", "chunks", chunkHash)

// Check if chunk exists
if _, err := os.Stat(chunkPath); os.IsNotExist(err) {
    return fmt.Errorf("chunk %s not found", chunkHash)
}

// Read the chunk data
chunkData, err := os.ReadFile(chunkPath)
if err != nil {
    return fmt.Errorf("failed to read chunk: %v", err)
}

After (Fixed):

// Read the chunk data using deduplication manager
// This properly resolves chunks through the deduplication index
chunkData, err := dedupManager.GetChunk(chunkHash)
if err != nil {
    return fmt.Errorf("failed to read chunk %s: %v", chunkHash, err)
}

🧪 How It Works

The dedupManager.GetChunk() method:

  • If deduplication disabled: Falls back to direct filesystem access (backward compatible)
  • If deduplication enabled:
    1. Looks up chunk in deduplication index
    2. Gets the actual storage hash from index entry
    3. Reads chunk from disk using storage hash

- Initialize deduplication manager in get command
- Replace direct filesystem access with dedupManager.GetChunk()
- Fixes retrieval failure when deduplication is enabled
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 6, 2025

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/get.go 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

@S4tvara
Copy link
Copy Markdown
Owner

S4tvara commented Oct 6, 2025

Hi @kpj2006 ,
Thanks a lot for working on this! Another PR has already addressed the same issue, so I’ll be closing this one to avoid duplication. Really appreciate your effort here 🙏

Cheers,
Nilay

@S4tvara S4tvara closed this Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The get command doesn't take into account deduplication index

2 participants