fix(import): preserve DataGrip groups and Kingbase connections
This commit is contained in:
1 parent
71090d56c0
commit
7b95f0ca17
10 files changed
+208
-19
No files matched your search
@@ -6332,23 +6332,35 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
if (isTauriRuntime()) {
|
||||
const { open } = await import("@tauri-apps/plugin-dialog");
|
||||
const { readTextFile } = await import("@tauri-apps/plugin-fs");
|
||||
const path = await open({
|
||||
filters: [{ name: "DataGrip dataSources.xml", extensions: ["xml"] }],
|
||||
multiple: false,
|
||||
const { matchDataGripImportFiles } = await import("@/lib/imports/datagripImport");
|
||||
const paths = await open({
|
||||
multiple: true,
|
||||
filters: [{ name: "DataGrip configuration files", extensions: ["xml"] }],
|
||||
title: i18n.global.t("configExport.importDatagripDialogTitle"),
|
||||
});
|
||||
if (!path) return null;
|
||||
dataSources = await readTextFile(path as string);
|
||||
// Auto-load dataSources.local.xml from the same directory
|
||||
const dir = (path as string).replace(/[^/\\]*$/, "");
|
||||
if (!paths || paths.length === 0) return null;
|
||||
// Tauri's fs scope authorizes only the exact paths picked in the dialog,
|
||||
// so every file read below must be explicitly selected — sibling files in
|
||||
// the same directory (e.g. dataSources.local.xml) are NOT readable.
|
||||
let picked: { dataSources: string; local?: string; forest?: string };
|
||||
try {
|
||||
dataSourcesLocal = await readTextFile(dir + "dataSources.local.xml");
|
||||
} catch {
|
||||
dataSourcesLocal = "";
|
||||
picked = matchDataGripImportFiles(Array.isArray(paths) ? paths : [paths]);
|
||||
} catch (error) {
|
||||
if ((error as Error & { code?: string })?.code === "DATAGRIP_IMPORT_MISSING_DATASOURCES") {
|
||||
throw new Error(i18n.global.t("configExport.importDatagripSelectFiles"));
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
try {
|
||||
dbForestConfig = await readTextFile(dir + "db-forest-config.xml");
|
||||
} catch {
|
||||
dbForestConfig = "";
|
||||
dataSources = await readTextFile(picked.dataSources);
|
||||
if (picked.local) {
|
||||
dataSourcesLocal = await readTextFile(picked.local);
|
||||
} else {
|
||||
console.warn("[DataGrip Import] dataSources.local.xml not selected; usernames will fall back to defaults");
|
||||
}
|
||||
if (picked.forest) {
|
||||
dbForestConfig = await readTextFile(picked.forest);
|
||||
} else {
|
||||
console.warn("[DataGrip Import] db-forest-config.xml not selected; legacy group tree skipped");
|
||||
}
|
||||
} else {
|
||||
const files = await new Promise<FileList>((resolve, reject) => {
|
||||
@@ -6366,7 +6378,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
input.click();
|
||||
});
|
||||
const fileList = Array.from(files);
|
||||
const dsFile = fileList.find((f) => /^dataSources\.xml$/i.test(f.name)) || fileList[0];
|
||||
const dsFile = fileList.find((f) => /^dataSources\.xml$/i.test(f.name));
|
||||
const localFile = fileList.find((f) => /^dataSources\.local\.xml$/i.test(f.name));
|
||||
const forestFile = fileList.find((f) => /^db-forest-config\.xml$/i.test(f.name));
|
||||
if (!dsFile) throw new Error("Select dataSources.xml");
|
||||
|
||||
Reference in new issue
Block a user