Skip to content

Commit 2c5a523

Browse files
committed
fix(add): files were being not being compared after base64 encoding during addtion
1 parent 7144a87 commit 2c5a523

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

cmd/add.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,25 @@ Examples:
230230
}
231231

232232
// Create and store the file manifest
233+
// Separate directory from filename in destination
234+
// If pair.Destination ends with a filename (from directory expansion),
235+
// we need to extract the directory part and filename separately
236+
destDir := filepath.Dir(pair.Destination)
237+
destFileName := filepath.Base(pair.Destination)
238+
239+
// If the destination is just a filename (no directory), set destDir to empty
240+
if destDir == "." {
241+
destDir = ""
242+
} else if destDir != "" && !strings.HasSuffix(destDir, "/") {
243+
destDir = destDir + "/"
244+
}
245+
233246
fileManifest := &config.FileManifest{
234-
FilePath: filepath.Base(pair.Source),
247+
FilePath: destFileName,
235248
Size: sizeInBytes,
236249
ModTime: fileInfo.ModTime().Format(time.RFC3339),
237250
Chunks: chunkRefs,
238-
Destination: pair.Destination,
251+
Destination: destDir,
239252
AddedAt: time.Now().UTC(),
240253
Tags: tags, // Include tags in the manifest
241254
}
@@ -244,11 +257,11 @@ Examples:
244257
err = manifest.StoreFileManifest(vaultRoot, filepath.Base(pair.Source), fileManifest)
245258
if err != nil {
246259
if err.Error() == "skipped" {
247-
errorMsg := fmt.Sprintf("✗ '%s': skipped", fileManifest.Destination+filepath.Base(pair.Source))
260+
errorMsg := fmt.Sprintf("✗ '%s': skipped", fileManifest.Destination+fileManifest.FilePath)
248261
fmt.Println(errorMsg)
249262
continue
250263
}
251-
errorMsg := fmt.Sprintf("✗ %s: manifest storage failed - %v", filepath.Base(pair.Source), err)
264+
errorMsg := fmt.Sprintf("✗ %s: manifest storage failed - %v", fileManifest.FilePath, err)
252265
fmt.Println(errorMsg)
253266
failedFiles = append(failedFiles, errorMsg)
254267
continue

cmd/get.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,6 @@ Example:
279279
return fmt.Errorf("failed to decrypt chunk %s: %v", chunkHash, err)
280280
}
281281

282-
// Verify chunk integrity if not skipped
283-
skipVerify, _ := cmd.Flags().GetBool(skipVerification)
284-
if !skipEncryption && !skipVerify && chunkRef.Hash != "" {
285-
if err := verifyChunkWithRetry(ctx, chunkRef, decryptedData, 3); err != nil {
286-
progressMgr.PrintVerbose("Chunk %s failed integrity verification: %v\n", chunkHash, err)
287-
return fmt.Errorf("chunk %s integrity verification failed after retries: %v", chunkHash, err)
288-
}
289-
progressMgr.PrintVerbose("Chunk %s integrity verified successfully\n", chunkHash)
290-
} else if skipVerify {
291-
progressMgr.PrintVerbose("Skipping integrity verification for chunk %s (--skip-verification flag used)\n", chunkHash)
292-
}
293-
294282
// The original data was base64-encoded before encryption. Decode back to bytes.
295283
decodedBytes, err := base64.StdEncoding.DecodeString(decryptedData)
296284
if err != nil {
@@ -315,6 +303,17 @@ Example:
315303
chunkData = decompressedData
316304
}
317305

306+
skipVerify, _ := cmd.Flags().GetBool(skipVerification)
307+
if !skipEncryption && !skipVerify && chunkRef.Hash != "" {
308+
if err := verifyChunkWithRetry(ctx, chunkRef, string(chunkData), 3); err != nil {
309+
progressMgr.PrintVerbose("Chunk %s failed integrity verification: %v\n", chunkHash, err)
310+
return fmt.Errorf("chunk %s integrity verification failed after retries: %v", chunkHash, err)
311+
}
312+
progressMgr.PrintVerbose("Chunk %s integrity verified successfully\n", chunkHash)
313+
} else if skipVerify {
314+
progressMgr.PrintVerbose("Skipping integrity verification for chunk %s (--skip-verification flag used)\n", chunkHash)
315+
}
316+
318317
// Write the chunk to the output file
319318
bytesWritten, err := outputFile.Write(chunkData)
320319
if err != nil {

0 commit comments

Comments
 (0)