@@ -428,7 +428,7 @@ func (w *LfsSyncWorker) getSyncPointers(
428428 var toBeUpdateLfsMetaObjects []database.LfsMetaObject
429429 for _ , lfsMetaObject := range lfsMetaObjects {
430430 objectKey := common .BuildLfsPath (repo .ID , lfsMetaObject .Oid , repo .Migrated )
431- exists , err := w .CheckIfLFSFileExists (ctx , objectKey )
431+ exists , err := w .CheckIfLFSFileExists (ctx , objectKey , lfsMetaObject . Size )
432432 if err != nil {
433433 slog .Error (
434434 "failed to check if lfs file exists" ,
@@ -567,7 +567,7 @@ func (w *LfsSyncWorker) downloadAndUploadLFSFile(
567567) error {
568568 var uploadID string
569569 objectKey := common .BuildLfsPath (repo .ID , pointer .Oid , repo .Migrated )
570- exists , err := w .CheckIfLFSFileExists (ctx , objectKey )
570+ exists , err := w .CheckIfLFSFileExists (ctx , objectKey , pointer . Size )
571571 if err != nil {
572572 slog .Error (
573573 "failed to check if lfs file exists" ,
@@ -1206,15 +1206,26 @@ func (w *LfsSyncWorker) downloadRange(
12061206func (w * LfsSyncWorker ) CheckIfLFSFileExists (
12071207 ctx context.Context ,
12081208 objectKey string ,
1209+ size int64 ,
12091210) (bool , error ) {
1210- _ , err := w .ossClient .StatObject (ctx , w .config .S3 .Bucket , objectKey , minio.StatObjectOptions {})
1211+ objInfo , err := w .ossClient .StatObject (ctx , w .config .S3 .Bucket , objectKey , minio.StatObjectOptions {})
12111212 if err != nil {
12121213 // Check if it's a "not found" error
12131214 if strings .Contains (err .Error (), "NoSuchKey" ) || strings .Contains (err .Error (), "not found" ) {
12141215 return false , nil
12151216 }
12161217 return false , err
12171218 }
1219+
1220+ // Check if the file size matches the expected size
1221+ if objInfo .Size != size {
1222+ // Delete the mismatched object
1223+ if err := w .ossClient .RemoveObject (ctx , w .config .S3 .Bucket , objectKey , minio.RemoveObjectOptions {}); err != nil {
1224+ return false , fmt .Errorf ("failed to remove mismatched object: %w" , err )
1225+ }
1226+ return false , nil
1227+ }
1228+
12181229 return true , nil
12191230}
12201231
0 commit comments