Fix TestFileChecksumExists to check for deleted files

This commit is contained in:
Jonathan Jenne 2023-11-14 09:56:11 +01:00
parent 0f63847d78
commit 0bf0f21f66

View File

@ -80,14 +80,20 @@ Namespace IDB
Dim oChecksumSQL = $"SELECT IDB_OBJ_ID FROM TBIDB_FILE_OBJECT WHERE FILE_HASH = '{pChecksum}'"
Dim oExistingObjectId As Long = Database.GetScalarValue(oChecksumSQL)
Dim oChecksumExists = (oExistingObjectId > 0)
If oExistingObjectId > 0 Then
Logger.Info("Returning with ObjectId [{0}] because Checksum [{1}] already exists.", oExistingObjectId, pChecksum)
Return oExistingObjectId
If oChecksumExists AndAlso TestFileDeleted(oExistingObjectId) Then
Logger.Info("Checksum exists on Object [{0}] but the Object was deleted", oExistingObjectId)
Return 0
End If
Logger.Debug("Checksum does not exist.")
Return 0
If Not oChecksumExists Then
Logger.Debug("Checksum does not exist.")
Return 0
End If
Logger.Info("Returning with ObjectId [{0}] because Checksum [{1}] already exists.", oExistingObjectId, pChecksum)
Return oExistingObjectId
Catch ex As Exception
Logger.Error(ex)
@ -96,6 +102,20 @@ Namespace IDB
End Try
End Function
Public Function TestFileDeleted(pObjectId As Long) As Boolean
Try
Logger.Debug("Checking if Object [{0}] has been deleted", pObjectId)
Dim oObjectSQL = $"SELECT IDB_OBJ_ID FROM TBIDB_OBJECT WHERE IDB_OBJ_ID = {pObjectId} AND DELETED = 1"
Dim oDeletedObjectId As Long = Database.GetScalarValue(oObjectSQL)
Return (oDeletedObjectId > 0)
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
Public Function NewObjectId(pKindType As String, pBusinessEntity As String, pWho As String) As Long
Try
Dim oNewObjectIdSQL = $"DECLARE @NEW_IDB_OBJ_ID BIGINT