Skip to content

Commit

Permalink
Adapt export comparison to support multiple files
Browse files Browse the repository at this point in the history
Further changes to compare all related source files.
  • Loading branch information
joyfullservice committed Dec 7, 2023
1 parent 7fc2add commit 0975da4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 37 deletions.
27 changes: 3 additions & 24 deletions Version Control.accda.src/modules/clsVCSIndex.cls
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Public Function Update(cItem As IDbComponent, intAction As eIndexOperationType,
End Select

' Save timestamp of exported source file.
dteDateTime = GetLastModifiedDate(cItem.SourceFile)
dteDateTime = GetSourceModifiedDate(cItem, cItem.SourceFile)
.Item("SourceModified") = ZNDate(dteDateTime)

' Save hash of file properties
Expand Down Expand Up @@ -560,7 +560,7 @@ Public Sub CheckExportConflicts(dDbComponents As Dictionary)
Me.Conflicts.Add cItem, _
CStr(varKey), _
Me.Item(cItem).ExportDate, _
GetLastModifiedDate(cItem.SourceFile), _
GetSourceModifiedDate(cItem, cItem.SourceFile), _
ercOverwrite
End If
' Increment the progress bar
Expand Down Expand Up @@ -638,7 +638,7 @@ Private Function IsExportConflict(cItem As IDbComponent) As Boolean
strTempFile = Replace(strFile, Options.GetExportFolder, GetTempExportFolder)
Log.Add " Exporting " & cItem.Name, False
cItem.Export strTempFile
blnConflict = Not FileContentsMatch(strFile, strTempFile)
blnConflict = Not SourceMatches(cItem, strFile, strTempFile)
End If

' Return result
Expand Down Expand Up @@ -829,27 +829,6 @@ Private Function SourceMatches(cType As IDbComponent, strFile1 As String, strFil
End Function


'---------------------------------------------------------------------------------------
' Procedure : FileContentsMatch
' Author : Adam Waller
' Date : 9/15/2021
' Purpose : Returns true if the contents of the files match. Starts with the least
' : expensive comparison of size, then goes on to compare a hash of the
' : full contents.
'---------------------------------------------------------------------------------------
'
Private Function FileContentsMatch(strFile1 As String, strFile2 As String) As Boolean
If FSO.FileExists(strFile1) And FSO.FileExists(strFile2) Then
If FSO.GetFile(strFile1).Size = FSO.GetFile(strFile2).Size Then
If GetFileHash(strFile1) = GetFileHash(strFile2) Then
' The contents of the two files is identical
FileContentsMatch = True
End If
End If
End If
End Function


'---------------------------------------------------------------------------------------
' Procedure : GetTempExportFolder
' Author : Adam Waller
Expand Down
22 changes: 11 additions & 11 deletions Version Control.accda.src/modules/modOrphaned.bas
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ End Sub
' : to list this as a possible conflict item.
'---------------------------------------------------------------------------------------
'
Private Sub CompareToIndex(cType As IDbComponent, strFile As String, dExtensions As Dictionary, dBaseNames As Dictionary)
Private Sub CompareToIndex(cType As IDbComponent, strFilePath As String, dExtensions As Dictionary, dBaseNames As Dictionary)

Dim strFileName As String
Dim strBaseName As String
Dim strExt As String
Dim strHash As String

' Get base name and file extension to build primary source file name
strFileName = FSO.GetFileName(strFile)
strFileName = FSO.GetFileName(strFilePath)
strBaseName = FSO.GetBaseName(strFileName)
strExt = Mid$(strFileName, Len(strBaseName) + 2)

Expand All @@ -120,35 +120,35 @@ Private Sub CompareToIndex(cType As IDbComponent, strFile As String, dExtensions

' If file is unchanged from the index, we can go ahead and delete it.
' (The source file matches the last version imported or exported)
strHash = GetSourceFilesPropertyHash(cType, strFileName)
strHash = GetSourceFilesPropertyHash(cType, strFilePath)
If VCSIndex.Item(cType, strFileName).FilePropertiesHash = strHash Then

' Remove file and index entry
Log.Add " Removing orphaned file: " & cType.BaseFolder & strFileName, Options.ShowDebug
DeleteFile strFile, True
VCSIndex.Remove cType, strFile
DeleteFile strFilePath, True
VCSIndex.Remove cType, strFileName
Else
' File properties different from index. Add as a conflict to resolve.
' (This can happen when the last export was during a different daylight savings time
' setting, as the past file modified date returned by FSO is not adjusted for DST.)
Log.Add " Orphaned source file does not match last export: " & strFile, Options.ShowDebug
VCSIndex.Conflicts.Add cType, strFile, 0, GetLastModifiedDate(strFile), ercDelete, strFile, ercDelete
Log.Add " Orphaned source file does not match last export: " & strFilePath, Options.ShowDebug
VCSIndex.Conflicts.Add cType, strFilePath, 0, GetSourceModifiedDate(cType, strFilePath), ercDelete, strFilePath, ercDelete
End If
Else
' Object does not exist in the index. It might be a new file added
' by another developer. Don't delete it, as it may need to be merged
' into the database. (Defaults to skip deleting the file)
Log.Add " Found new source file: " & strFile, Options.ShowDebug
VCSIndex.Conflicts.Add cType, strFile, 0, GetLastModifiedDate(strFile), ercDelete, strFile, ercSkip
Log.Add " Found new source file: " & strFilePath, Options.ShowDebug
VCSIndex.Conflicts.Add cType, strFilePath, 0, GetSourceModifiedDate(cType, strFilePath), ercDelete, strFilePath, ercSkip
End If

Else
' Not the primary extension for this component type.
' If the primary source file exists, we will let that file handle evaluate any conflicts
If Not FSO.FileExists(SwapExtension(strFile, CStr(dExtensions(0)))) Then
If Not FSO.FileExists(SwapExtension(strFilePath, CStr(dExtensions(0)))) Then
' The primary source file does not exist. Go ahead and delete this orphaned file.
Log.Add " Removing orphaned file: " & cType.BaseFolder & strFileName, Options.ShowDebug
DeleteFile strFile, True
DeleteFile strFilePath, True
End If
End If
End If
Expand Down
4 changes: 2 additions & 2 deletions Version Control.accda.src/modules/modVCSUtility.bas
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,10 @@ Public Function GetSourceFilesPropertyHash(cmp As IDbComponent, Optional strFile
' Build base file path without extension
If Len(strFile) Then
' Use provided file name first
strBaseFile = FSO.GetBaseName(strFile)
strBaseFile = FSO.BuildPath(FSO.GetParentFolderName(strFile), FSO.GetBaseName(strFile))
Else
' Otherwise use default source file name
strBaseFile = FSO.GetBaseName(cmp.SourceFile)
strBaseFile = FSO.BuildPath(FSO.GetParentFolderName(cmp.SourceFile), FSO.GetBaseName(cmp.SourceFile))
End If

' Build a combined string with all the properties
Expand Down

0 comments on commit 0975da4

Please sign in to comment.