Skip to content

Commit

Permalink
Merge pull request #96 from 0chain/sunilmhta/fix-long-file-duplicates
Browse files Browse the repository at this point in the history
Fix long file names in case of duplicates
  • Loading branch information
dabasov authored Aug 29, 2023
2 parents e291511 + 8b90da9 commit 97e53cf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,10 @@ func (m *Migration) UploadWorker(ctx context.Context, migrator *MigrationWorker)
}

func getUniqueShortObjKey(objectKey string) string {
//Max length to which objectKey would be trimmed to.
const maxLength = 100
// Max length to which objectKey would be trimmed to.
// Keeping this less than 100 chars to prevent longer name in case of uploading duplicate
// files with `_copy` suffixes.
const maxLength = 90

if len(objectKey) > maxLength {
// Generate a SHA-1 hash of the object key
Expand Down Expand Up @@ -497,7 +499,7 @@ func processOperationForMemory(ctx context.Context, downloadObj *DownloadObjectM
zlogger.Logger.Info("Replacing object" + downloadObj.ObjectKey + " size " + strconv.FormatInt(downloadObj.Size, 10))
fileOperation = migration.zStore.Replace(ctx, remotePath, r, downloadObj.Size, mimeType)
case Duplicate:
zlogger.Logger.Info("Duplicating object" + downloadObj.ObjectKey + " size " + strconv.FormatInt(downloadObj.Size, 10))
zlogger.Logger.Info("Duplicating object " + downloadObj.ObjectKey + " size " + strconv.FormatInt(downloadObj.Size, 10))
fileOperation = migration.zStore.Duplicate(ctx, remotePath, r, downloadObj.Size, mimeType)
}
} else {
Expand Down

0 comments on commit 97e53cf

Please sign in to comment.