Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Addin doesn't validate file name and vbe-project filename differences. #553

Open
hecon5 opened this issue Oct 22, 2024 · 4 comments
Open

Comments

@hecon5
Copy link
Contributor

hecon5 commented Oct 22, 2024

Bit of an edge case I discovered today. I discovered today that if you simply copy vbe-project.json and forget to edit the Items.Filename element to the correct file name, if you build from source the addin will grab db2 as the source folder and not db3 as expected.

Conditions: have two source folders in a directory, and two database files as shown:

\db1.accdb.src\
\db2.accdb.src\
\db3.accdb.src\ < minimal copy of db2, includes the .json files for setup from db2
db1.accdb
db2.accdb
db3.accdb < This is a copy of db2, but the file is renamed

Steps to reproduce:

  1. File and folder configured as above
  2. Open db3.accdb
  3. Open Addin and build from source
  4. db2.accdb will be built.
  5. If you then use Build As from the ribbon and select the "correct" file name, it will build correctly.

Potential fix:

Add a check to validate that the opened filename matches that of vbe-project.json.

Proposed options if it doesn't match:

  1. Error out: I don't think this is needed.
  2. Ask if they want to build with the open file name (db3.accdb in the example above).
    a. If they select "NO" present them with the Build As dialog and then build as the selected item.
    b. If they selected Yes, simply build as the file name.
  3. If they cancel the build as dialog throw a critical error and bail out.
@joyfullservice
Copy link
Owner

That sounds like a reasonable approach to me. 👍

@hecon5
Copy link
Contributor Author

hecon5 commented Oct 23, 2024

looks like we can just turn off the outer If statement, and ask if they want to bail out instead of merging on non full build. Here's a mockup.

modImportExport.bas:

diff --git a/Version Control.accda.src/modules/modImportExport.bas b/Version Control.accda.src/modules/modImportExport.bas
index 9f73efe..2038a0f 100644
--- a/Version Control.accda.src/modules/modImportExport.bas	
+++ b/Version Control.accda.src/modules/modImportExport.bas	
@@ -726,18 +726,38 @@ Public Sub Build(strSourceFolder As String, blnFullBuild As Boolean, _
     End If
 
     ' Verify that the source files are being merged into the correct database.
-    If Not blnFullBuild Then
-        strPath = GetOriginalDbFullPathFromSource(strSourceFolder)
-        ' Resolve any relative directives (i.e. "\..\") to actual path
-        If FSO.FileExists(strPath) Then strPath = FSO.GetFile(strPath).Path
-        If strPath = vbNullString Then
-            MsgBox2 "Unable to determine database file name", "Required source files were not found or could not be decrypted:", strSourceFolder, vbExclamation
-            GoTo CleanUp
-        ElseIf StrComp(strPath, CurrentProject.FullName, vbTextCompare) <> 0 Then
-            MsgBox2 "Cannot merge to a different database", _
+    strPath = GetOriginalDbFullPathFromSource(strSourceFolder)
+    ' Resolve any relative directives (i.e. "\..\") to actual path
+    If FSO.FileExists(strPath) Then strPath = FSO.GetFile(strPath).Path
+    If strPath = vbNullString Then
+        MsgBox2 "Unable to determine database file name", "Required source files were not found or could not be decrypted:", strSourceFolder, vbExclamation
+        GoTo CleanUp
+    ElseIf StrComp(strPath, CurrentProject.FullName, vbTextCompare) <> 0 Then
+        If blnFullBuild Then
+            ' Full build allows you to use source file name.
+            If Not MsgBox2("Current Database filename does not match source filename." _
+                            , "Do you want to " & strType & " to the Source Defined Filename?" & _
+                            vbNewLine & vbNewLine & "Current: " & CurrentProject.FullName & vbNewLine & _
+                            "Source: " & strPath _
+                            , "[Ok] = Build with Source Configured Name" & vbNewLine & vbNewLine & _
+                                "Otherwise cancel and select 'Build As...' from the ribbon to change build name. " & _
+                                "Performing an export from this file name will also reset the file name, but will " & _
+                                "overwrite source. If this file stared as a copy of an existing source controlled " & _
+                                "database, select build as to avoid overwriting." _
+                            , vbQuestion + vbOKCancel + vbDefaultButton1 _
+                            , strType & " Name Conflict" _
+                            , vbOK) = vbOK Then
+                GoTo CleanUp
+            End If
+
+        Else
+            MsgBox2 "Cannot " & strType & " to a different database", _
                 "The database file name for the source files must match the currently open database.", _
-                "Current: " & CurrentProject.FullName & vbCrLf & _
-                "Source: " & strPath, vbExclamation
+                "Current: " & CurrentProject.FullName & vbNewLine & _
+                "Source: " & strPath, vbExclamation _
+                , strType & " Name Conflict" _
+                , vbOK
+
             GoTo CleanUp
         End If
     End If
-- 

@hecon5
Copy link
Contributor Author

hecon5 commented Oct 23, 2024

hmm, apparently that's not a good plan, moving it down a bit, but same theme.

@hecon5
Copy link
Contributor Author

hecon5 commented Oct 23, 2024

image
Test image.

The irksome thing is this then immediately bails out and crashes because the log file location can't be found, because it's set several lines later. I'm kind of thinking the log needs to be setup before the first "cleanup" goto is set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants