Skip to content

Commit 0cd5949

Browse files
Fix/issue #90 (#112)
* feat: add more templates * refactor: update the help section for the scaffold command with new templates * feat: add flags for recursive directory and hidden file / directory support * feat: add symlink and directory support for the add command * fix: progress bar breaking * fix: ci warnings
1 parent f1dcc72 commit 0cd5949

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

internal/chunk/chunkFile.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ func ChunkFile(ctx context.Context, filePath string, chunkSize int64, vaultRoot
6969
return nil, fmt.Errorf("failed to initialize deduplication manager: %v", err)
7070
}
7171

72+
// Set progress manager for coordinated output
73+
dedupManager.SetProgressManager(progressMgr)
74+
7275
chunkRefs, err := processFileChunks(ctx, file, chunkSize, *vaultConfig, passphrase, dedupManager, progressMgr)
7376
if err != nil {
7477
return nil, err

internal/deduplication/manager.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ import (
1010

1111
// Manager handles deduplication operations for a vault
1212
type Manager struct {
13-
vaultRoot string
14-
config config.DeduplicationConfig
15-
index *DeduplicationIndex
13+
vaultRoot string
14+
config config.DeduplicationConfig
15+
index *DeduplicationIndex
16+
progressMgr ProgressManager
17+
}
18+
19+
// ProgressManager is an interface for progress reporting
20+
type ProgressManager interface {
21+
PrintVerbose(format string, args ...interface{})
1622
}
1723

1824
// NewManager creates a new deduplication manager
@@ -23,12 +29,18 @@ func NewManager(vaultRoot string, dedupConfig config.DeduplicationConfig) (*Mana
2329
}
2430

2531
return &Manager{
26-
vaultRoot: vaultRoot,
27-
config: dedupConfig,
28-
index: index,
32+
vaultRoot: vaultRoot,
33+
config: dedupConfig,
34+
index: index,
35+
progressMgr: nil, // Will be set later if needed
2936
}, nil
3037
}
3138

39+
// SetProgressManager sets the progress manager for verbose output
40+
func (m *Manager) SetProgressManager(pm ProgressManager) {
41+
m.progressMgr = pm
42+
}
43+
3244
// ProcessChunk processes a chunk for deduplication
3345
// Returns: (chunkRef, deduplicated, error)
3446
func (m *Manager) ProcessChunk(chunkRef config.ChunkRef, chunkData []byte, storageHash string) (config.ChunkRef, bool, error) {
@@ -55,8 +67,10 @@ func (m *Manager) ProcessChunk(chunkRef config.ChunkRef, chunkData []byte, stora
5567
if deduplicated {
5668
// Chunk already exists, no need to store it again
5769
chunkRef.Deduplicated = true
58-
fmt.Printf(" └─ Deduplicated chunk %s (ref count: %d)\n",
59-
chunkRef.Hash[:12], entry.RefCount)
70+
if m.progressMgr != nil {
71+
m.progressMgr.PrintVerbose(" └─ Deduplicated chunk %s (ref count: %d)\n",
72+
chunkRef.Hash[:12], entry.RefCount)
73+
}
6074
} else {
6175
// New chunk, store it
6276
if err := m.storeChunk(storageHash, chunkData); err != nil {

internal/progress/progress.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func (pm *Manager) FinishFileProgress() {
157157
// PrintVerbose prints verbose information if verbose mode is enabled
158158
func (pm *Manager) PrintVerbose(format string, args ...interface{}) {
159159
if pm.options.Verbose {
160+
// Clear the progress bar before printing to avoid line breaks
161+
if pm.totalBar != nil {
162+
_ = pm.totalBar.Clear() // #nosec G104 - progress bar clear is not critical for functionality
163+
}
164+
160165
// #nosec G104 - verbose output errors are not critical for functionality
161166
fmt.Printf(format, args...)
162167
// Ensure output ends with newline if not already present
@@ -170,6 +175,11 @@ func (pm *Manager) PrintVerbose(format string, args ...interface{}) {
170175
// PrintInfo prints informational messages (unless quiet mode)
171176
func (pm *Manager) PrintInfo(format string, args ...interface{}) {
172177
if !pm.options.Quiet {
178+
// Clear the progress bar before printing to avoid line breaks
179+
if pm.totalBar != nil {
180+
_ = pm.totalBar.Clear() // #nosec G104 - progress bar clear is not critical for functionality
181+
}
182+
173183
// #nosec G104 - info output errors are not critical for functionality
174184
fmt.Printf(format, args...)
175185
}

0 commit comments

Comments
 (0)