Skip to content

Commit

Permalink
feat: add deduplication check for file downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
PlusOne committed Jan 26, 2025
1 parent 3490c2f commit f6f5eee
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,19 @@ func handleUpload(w http.ResponseWriter, r *http.Request, absFilename, fileStore
func handleDownload(w http.ResponseWriter, r *http.Request, absFilename, fileStorePath string) {
log.Debugf("Attempting to download file from path: %s", absFilename)

if _, err := os.Stat(absFilename); os.IsNotExist(err) {
// Check possible dedup location
dedupPath := getDeduplicatedLocation(absFilename)
if _, err2 := os.Stat(dedupPath); err2 == nil {
absFilename = dedupPath
} else {
log.WithError(err).Errorf("Failed to get file information for %s", absFilename)
http.NotFound(w, r)
downloadErrorsTotal.Inc()
return
}
}

fileInfo, err := getFileInfo(absFilename)
if err != nil {
log.Errorf("Failed to get file information for %s: %v", absFilename, err)
Expand Down Expand Up @@ -2766,4 +2779,11 @@ func setupRouter() *http.ServeMux {

func getTempFilename(filename string) string {
return filename + ".tmp"
}

// getDeduplicatedLocation returns the dedup path if the file is moved.
func getDeduplicatedLocation(original string) string {
// For example:
// return "/mnt/nfs_vol01/hmac-file-server/deduplication/" + <calculated-hash> + "/" + filepath.Base(original)
return original
}

0 comments on commit f6f5eee

Please sign in to comment.