-
Notifications
You must be signed in to change notification settings - Fork 48
CSharp extension: ZIP archive support for InstallExternalLibrary/UninstallExternalLibrary #85
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
base: main
Are you sure you want to change the base?
Changes from all commits
75737dd
10ce19a
1a782e3
8060650
f55001d
0b3916b
af9f8d7
07e0615
a342b0c
7bfdd73
89a7bae
246067b
e7ec844
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,4 +340,139 @@ SQLRETURN Cleanup() | |
| LOG("nativecsharpextension::Cleanup"); | ||
| delete g_dotnet_runtime; | ||
| return SQL_SUCCESS; | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------------------------------- | ||
| // Name: SetLibraryError | ||
| // | ||
| // Description: | ||
| // Helper to populate the library error output parameters. | ||
| // | ||
| static void SetLibraryError( | ||
| const std::string &errorString, | ||
| SQLCHAR **libraryError, | ||
| SQLINTEGER *libraryErrorLength) | ||
| { | ||
| // Guard against null out-parameters. The managed SetLibraryError | ||
| // (CSharpExtension.cs) does the same null-check; without it, a caller | ||
| // passing null libraryError / libraryErrorLength would dereference null | ||
| // and crash the host process. | ||
| if (libraryError == nullptr || libraryErrorLength == nullptr) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (!errorString.empty()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a null-pointer guard consistent with the managed version: if (!errorString.empty() && libraryError != nullptr && libraryErrorLength != nullptr)The managed
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in commit e7ec844. Native
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Problem: If if (!errorString.empty())
{
// Only set on non-empty — otherwise output params are untouched
}Recommendation: Consider explicitly setting
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in commit e7ec844. The |
||
| { | ||
| // Length excludes null terminator -- ExtHost adds +1 when copying | ||
| // (see Utf8ToNullTerminatedUtf16Le / strcpy_s in the host). | ||
| *libraryErrorLength = static_cast<SQLINTEGER>(errorString.length()); | ||
| std::string *pError = new std::string(errorString); | ||
| *libraryError = const_cast<SQLCHAR*>( | ||
| reinterpret_cast<const SQLCHAR *>(pError->c_str())); | ||
| } | ||
| else | ||
| { | ||
| // Explicitly clear the out-parameters so callers that don't | ||
| // pre-initialize them see a well-defined "no error" state. | ||
| *libraryError = nullptr; | ||
| *libraryErrorLength = 0; | ||
| } | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------------------------------- | ||
| // Name: InstallExternalLibrary | ||
| // | ||
| // Description: | ||
| // Installs an external library to the specified directory. | ||
| // The library file is expected to be a zip containing the library files. | ||
| // If it contains an inner zip, that zip is extracted to the install directory. | ||
| // Otherwise, all files are copied directly. | ||
| // | ||
| // Returns: | ||
| // SQL_SUCCESS on success, else SQL_ERROR | ||
| // | ||
| SQLRETURN InstallExternalLibrary( | ||
| SQLGUID setupSessionId, | ||
| SQLCHAR *libraryName, | ||
| SQLINTEGER libraryNameLength, | ||
| SQLCHAR *libraryFile, | ||
| SQLINTEGER libraryFileLength, | ||
| SQLCHAR *libraryInstallDirectory, | ||
| SQLINTEGER libraryInstallDirectoryLength, | ||
| SQLCHAR **libraryError, | ||
| SQLINTEGER *libraryErrorLength) | ||
| { | ||
| LOG("nativecsharpextension::InstallExternalLibrary"); | ||
|
|
||
| SQLRETURN result = SQL_ERROR; | ||
|
|
||
| if (g_dotnet_runtime == nullptr) | ||
| { | ||
| SetLibraryError( | ||
| "Extension not initialized. Call Init before InstallExternalLibrary.", | ||
| libraryError, | ||
| libraryErrorLength); | ||
| } | ||
| else | ||
| { | ||
| result = g_dotnet_runtime->call_managed_method<decltype(&InstallExternalLibrary)>( | ||
| nameof(InstallExternalLibrary), | ||
| setupSessionId, | ||
| libraryName, | ||
| libraryNameLength, | ||
| libraryFile, | ||
| libraryFileLength, | ||
| libraryInstallDirectory, | ||
| libraryInstallDirectoryLength, | ||
| libraryError, | ||
| libraryErrorLength); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------------------------------- | ||
| // Name: UninstallExternalLibrary | ||
| // | ||
| // Description: | ||
| // Uninstalls an external library from the specified directory. | ||
| // | ||
| // Returns: | ||
| // SQL_SUCCESS on success, else SQL_ERROR | ||
| // | ||
| SQLRETURN UninstallExternalLibrary( | ||
| SQLGUID setupSessionId, | ||
| SQLCHAR *libraryName, | ||
| SQLINTEGER libraryNameLength, | ||
| SQLCHAR *libraryInstallDirectory, | ||
| SQLINTEGER libraryInstallDirectoryLength, | ||
| SQLCHAR **libraryError, | ||
| SQLINTEGER *libraryErrorLength) | ||
| { | ||
| LOG("nativecsharpextension::UninstallExternalLibrary"); | ||
|
|
||
| SQLRETURN result = SQL_ERROR; | ||
|
|
||
| if (g_dotnet_runtime == nullptr) | ||
| { | ||
| SetLibraryError( | ||
| "Extension not initialized. Call Init before UninstallExternalLibrary.", | ||
| libraryError, | ||
| libraryErrorLength); | ||
| } | ||
| else | ||
| { | ||
| result = g_dotnet_runtime->call_managed_method<decltype(&UninstallExternalLibrary)>( | ||
| nameof(UninstallExternalLibrary), | ||
| setupSessionId, | ||
| libraryName, | ||
| libraryNameLength, | ||
| libraryInstallDirectory, | ||
| libraryInstallDirectoryLength, | ||
| libraryError, | ||
| libraryErrorLength); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it mean that it will recursively unzip everything if a zip has a zip in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No -- only ONE level of nesting. The flow is: extract the outer ZIP into
tempFolder; if a top-level.zipis found inside, extract THAT intotempFolderas well; then copy the resulting tree toinstallDir. We do not re-scan after the inner-zip extraction, so a zip-in-zip-in-zip would land as a nested.zipfile on disk (treated as opaque content). Added a comment around the inner-zip discovery loop in commit e7ec844 documenting this.