Skip to content

Commit c125619

Browse files
alexander-skoblikovkseniaguzeevaMashaKorax
authored
dbeaver/pro#7481 ability to read/write to an external fs (#4007)
Co-authored-by: kseniaguzeeva <112612526+kseniaguzeeva@users.noreply.github.com> Co-authored-by: MashaKorax <84867187+MashaKorax@users.noreply.github.com>
1 parent 7a12ad4 commit c125619

File tree

5 files changed

+38
-50
lines changed

5 files changed

+38
-50
lines changed

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/app/BaseServerConfigurationController.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
import com.google.gson.GsonBuilder;
2121
import org.jkiss.code.NotNull;
2222
import org.jkiss.code.Nullable;
23+
import org.jkiss.dbeaver.DBException;
2324
import org.jkiss.dbeaver.Log;
24-
import org.jkiss.dbeaver.registry.fs.FileSystemProviderRegistry;
25+
import org.jkiss.dbeaver.registry.fs.FSUtils;
2526
import org.jkiss.utils.CommonUtils;
2627

27-
import java.net.URI;
28-
import java.nio.file.FileSystem;
29-
import java.nio.file.FileSystems;
3028
import java.nio.file.Path;
3129

3230
/**
@@ -65,30 +63,20 @@ protected synchronized Path initWorkspacePath() {
6563
if (CommonUtils.isEmpty(workspaceLocation)) {
6664
return defaultWorkspaceLocation;
6765
}
68-
URI workspaceUri = URI.create(workspaceLocation);
69-
if (workspaceUri.getScheme() == null) {
70-
// default filesystem
71-
return getHomeDirectory().resolve(workspaceLocation);
72-
} else {
73-
var externalFsProvider =
74-
FileSystemProviderRegistry.getInstance().getFileSystemProviderBySchema(workspaceUri.getScheme());
75-
if (externalFsProvider == null) {
76-
log.error("File system not found for scheme: " + workspaceUri.getScheme() + " default workspace " +
77-
"location will be used");
66+
try {
67+
Path externalFsPath = FSUtils.getPathFromURI(workspaceLocation);
68+
if (externalFsPath == null) {
69+
log.warn("Failed to detect workspace path from URI: " + workspaceLocation +
70+
" default workspace location will be used");
7871
return defaultWorkspaceLocation;
7972
}
80-
ClassLoader fsClassloader = externalFsProvider.getInstance().getClass().getClassLoader();
81-
try (FileSystem externalFileSystem = FileSystems.newFileSystem(workspaceUri,
82-
System.getenv(),
83-
fsClassloader)) {
84-
log.info("Path from external filesystem used for workspace: " + workspaceUri);
85-
return externalFileSystem.provider().getPath(workspaceUri);
86-
} catch (Exception e) {
87-
log.error("Failed to initialize workspace path: " + workspaceUri + " default workspace " +
88-
"location will be used", e);
89-
}
73+
log.info("Path from external filesystem used for workspace: " + externalFsPath);
74+
return externalFsPath;
75+
} catch (DBException e) {
76+
log.error("Failed to detect workspace path from URI: " + workspaceLocation +
77+
" default workspace location will be used", e);
78+
return defaultWorkspaceLocation;
9079
}
91-
return defaultWorkspaceLocation;
9280
}
9381

9482
@Nullable

server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/fs/FSUtils.java renamed to server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/model/fs/WebFSUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DBeaver - Universal Database Manager
3-
* Copyright (C) 2010-2024 DBeaver Corp and others
3+
* Copyright (C) 2010-2025 DBeaver Corp and others
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828

2929
import java.nio.file.Path;
3030

31-
public class FSUtils {
31+
public class WebFSUtils {
3232
@NotNull
3333
public static String makeUniqueFsId(@NotNull DBFVirtualFileSystem fileSystem) {
3434
return fileSystem.getType() + "://" + fileSystem.getId();

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/navigator/WebNavigatorNodeInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DBeaver - Universal Database Manager
3-
* Copyright (C) 2010-2024 DBeaver Corp and others
3+
* Copyright (C) 2010-2025 DBeaver Corp and others
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@
1919
import io.cloudbeaver.DBWebException;
2020
import io.cloudbeaver.WebServiceUtils;
2121
import io.cloudbeaver.model.WebPropertyInfo;
22-
import io.cloudbeaver.model.fs.FSUtils;
22+
import io.cloudbeaver.model.fs.WebFSUtils;
2323
import io.cloudbeaver.model.rm.DBNResourceManagerResource;
2424
import io.cloudbeaver.model.session.WebSession;
2525
import io.cloudbeaver.registry.WebObjectFeatureProviderDescriptor;
@@ -208,7 +208,7 @@ public String getObjectId() {
208208
if (node instanceof DBNPathBase dbnPath) {
209209
return DBFUtils.getUriFromPath(dbnPath.getPath()).toString();
210210
} else if (node instanceof DBNFileSystem dbnFs) {
211-
return FSUtils.makeUniqueFsId(dbnFs.getFileSystem());
211+
return WebFSUtils.makeUniqueFsId(dbnFs.getFileSystem());
212212
}
213213
return null;
214214
}

server/bundles/io.cloudbeaver.service.fs/src/io/cloudbeaver/service/fs/impl/WebServiceFS.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DBeaver - Universal Database Manager
3-
* Copyright (C) 2010-2024 DBeaver Corp and others
3+
* Copyright (C) 2010-2025 DBeaver Corp and others
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818

1919
import io.cloudbeaver.DBWConstants;
2020
import io.cloudbeaver.DBWebException;
21-
import io.cloudbeaver.model.fs.FSUtils;
21+
import io.cloudbeaver.model.fs.WebFSUtils;
2222
import io.cloudbeaver.model.session.WebSession;
2323
import io.cloudbeaver.service.fs.DBWServiceFS;
2424
import io.cloudbeaver.service.fs.model.FSFile;
@@ -69,7 +69,7 @@ public FSFileSystem[] getAvailableFileSystems(@NotNull WebSession webSession, @N
6969
}
7070
return Arrays.stream(children)
7171
.map(fs -> new FSFileSystem(
72-
FSUtils.makeUniqueFsId(fs.getFileSystem()),
72+
WebFSUtils.makeUniqueFsId(fs.getFileSystem()),
7373
fs.getNodeUri(),
7474
fsRegistry.getProvider(fs.getFileSystem().getProviderId()).getRequiredAuth()
7575
)
@@ -94,7 +94,7 @@ public FSFileSystem getFileSystem(
9494
}
9595
var fsRegistry = FileSystemProviderRegistry.getInstance();
9696
return new FSFileSystem(
97-
FSUtils.makeUniqueFsId(fs.getFileSystem()),
97+
WebFSUtils.makeUniqueFsId(fs.getFileSystem()),
9898
fs.getNodeUri(),
9999
fsRegistry.getProvider(fs.getFileSystem().getProviderId()).getRequiredAuth()
100100
);
@@ -108,7 +108,7 @@ public FSFileSystem getFileSystem(
108108
public FSFile getFile(@NotNull WebSession webSession, @NotNull String nodePath)
109109
throws DBWebException {
110110
try {
111-
DBNPathBase node = FSUtils.getNodeByPath(webSession, nodePath);
111+
DBNPathBase node = WebFSUtils.getNodeByPath(webSession, nodePath);
112112
return new FSFile(node);
113113
} catch (Exception e) {
114114
throw new DBWebException("Failed to found file: " + e.getMessage(), e);
@@ -120,7 +120,7 @@ public FSFile getFile(@NotNull WebSession webSession, @NotNull String nodePath)
120120
public FSFile[] getFiles(@NotNull WebSession webSession, @NotNull String parentPath)
121121
throws DBWebException {
122122
try {
123-
DBNPathBase folderPath = FSUtils.getNodeByPath(webSession, parentPath);
123+
DBNPathBase folderPath = WebFSUtils.getNodeByPath(webSession, parentPath);
124124
var children = folderPath.getChildren(webSession.getProgressMonitor());
125125
if (children == null) {
126126
return new FSFile[0];
@@ -140,7 +140,7 @@ public FSFile[] getFiles(@NotNull WebSession webSession, @NotNull String parentP
140140
public String readFileContent(@NotNull WebSession webSession, @NotNull String nodePath)
141141
throws DBWebException {
142142
try {
143-
Path filePath = FSUtils.getPathFromNode(webSession, nodePath);
143+
Path filePath = WebFSUtils.getPathFromNode(webSession, nodePath);
144144
var data = Files.readAllBytes(filePath);
145145
return new String(data, StandardCharsets.UTF_8);
146146
} catch (Exception e) {
@@ -158,7 +158,7 @@ public FSFile writeFileContent(
158158
throws DBWebException {
159159
validateEditPermissions(webSession);
160160
try {
161-
DBNPathBase node = FSUtils.getNodeByPath(webSession, nodePath);
161+
DBNPathBase node = WebFSUtils.getNodeByPath(webSession, nodePath);
162162
Path filePath = node.getPath();
163163
if (!forceOverwrite) {
164164
throw new DBException("Cannot overwrite exist file");
@@ -179,7 +179,7 @@ public FSFile createFile(
179179
) throws DBWebException {
180180
validateEditPermissions(webSession);
181181
try {
182-
DBNPathBase parentNode = FSUtils.getNodeByPath(webSession, parentPath);
182+
DBNPathBase parentNode = WebFSUtils.getNodeByPath(webSession, parentPath);
183183
if (!Files.isDirectory(parentNode.getPath())) {
184184
throw new DBException(MessageFormat.format("Node ''{0}'' is not a directory", parentPath));
185185
}
@@ -200,10 +200,10 @@ public FSFile moveFile(
200200
) throws DBWebException {
201201
validateEditPermissions(webSession);
202202
try {
203-
DBNPathBase oldNode = FSUtils.getNodeByPath(webSession, oldNodePath);
203+
DBNPathBase oldNode = WebFSUtils.getNodeByPath(webSession, oldNodePath);
204204
DBNPathBase oldParentNode = (DBNPathBase) oldNode.getParentNode();
205205
String fileName = oldNode.getName();
206-
DBNPathBase parentNode = FSUtils.getNodeByPath(webSession, parentNodePath);
206+
DBNPathBase parentNode = WebFSUtils.getNodeByPath(webSession, parentNodePath);
207207
Path parentPath = parentNode.getPath();
208208
if (!Files.isDirectory(parentPath)) {
209209
throw new DBException(MessageFormat.format("Node ''{0}'' is not a directory", parentPath));
@@ -227,7 +227,7 @@ public FSFile renameFile(
227227
validateEditPermissions(webSession);
228228
validateFilename(newName);
229229
try {
230-
DBNPathBase node = FSUtils.getNodeByPath(webSession, nodePath);
230+
DBNPathBase node = WebFSUtils.getNodeByPath(webSession, nodePath);
231231
node.rename(webSession.getProgressMonitor(), newName);
232232
return new FSFile(node);
233233
} catch (Exception e) {
@@ -243,9 +243,9 @@ public FSFile copyFile(
243243
) throws DBWebException {
244244
validateEditPermissions(webSession);
245245
try {
246-
DBNPathBase oldNode = FSUtils.getNodeByPath(webSession, oldNodePath);
246+
DBNPathBase oldNode = WebFSUtils.getNodeByPath(webSession, oldNodePath);
247247
String fileName = oldNode.getName();
248-
DBNPathBase parentNode = FSUtils.getNodeByPath(webSession, parentNodePath);
248+
DBNPathBase parentNode = WebFSUtils.getNodeByPath(webSession, parentNodePath);
249249
Path parentPath = parentNode.getPath();
250250
if (!Files.isDirectory(parentPath)) {
251251
throw new DBException(MessageFormat.format("Node ''{0}'' is not a directory", parentPath));
@@ -267,7 +267,7 @@ public FSFile createFolder(
267267
) throws DBWebException {
268268
validateEditPermissions(webSession);
269269
try {
270-
DBNPathBase parentNode = FSUtils.getNodeByPath(webSession, parentPath);
270+
DBNPathBase parentNode = WebFSUtils.getNodeByPath(webSession, parentPath);
271271
if (!Files.isDirectory(parentNode.getPath())) {
272272
throw new DBException(MessageFormat.format("Node ''{0}'' is not a directory", parentPath));
273273
}
@@ -287,7 +287,7 @@ public boolean deleteFile(
287287
) throws DBWebException {
288288
validateEditPermissions(webSession);
289289
try {
290-
DBNPathBase node = FSUtils.getNodeByPath(webSession, nodePath);
290+
DBNPathBase node = WebFSUtils.getNodeByPath(webSession, nodePath);
291291
Path path = node.getPath();
292292
Files.delete(path);
293293
DBNPathBase parentNode = (DBNPathBase) node.getParentNode();

server/bundles/io.cloudbeaver.service.fs/src/io/cloudbeaver/service/fs/model/WebFSServlet.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DBeaver - Universal Database Manager
3-
* Copyright (C) 2010-2024 DBeaver Corp and others
3+
* Copyright (C) 2010-2025 DBeaver Corp and others
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818

1919
import io.cloudbeaver.DBWConstants;
2020
import io.cloudbeaver.DBWebException;
21-
import io.cloudbeaver.model.fs.FSUtils;
21+
import io.cloudbeaver.model.fs.WebFSUtils;
2222
import io.cloudbeaver.model.session.WebSession;
2323
import io.cloudbeaver.server.CBApplication;
2424
import io.cloudbeaver.service.WebServiceServletBase;
@@ -74,7 +74,7 @@ protected void processServiceRequest(WebSession session, HttpServletRequest requ
7474
}
7575

7676
private void doGet(WebSession session, HttpServletRequest request, HttpServletResponse response) throws DBException, IOException {
77-
Path path = FSUtils.getPathFromNode(session, request.getParameter("nodePath"));
77+
Path path = WebFSUtils.getPathFromNode(session, request.getParameter("nodePath"));
7878
session.addInfoMessage("Download data ...");
7979
response.setHeader("Content-Type", "application/octet-stream");
8080
response.setHeader("Content-Disposition", "attachment; filename=\"" + path.getFileName() + "\"");
@@ -93,7 +93,7 @@ private void doPost(WebSession session, HttpServletRequest request, HttpServletR
9393
if (CommonUtils.isEmpty(parentNodePath)) {
9494
throw new DBException("Parent node path parameter is not found");
9595
}
96-
DBNPathBase node = FSUtils.getNodeByPath(session, parentNodePath);
96+
DBNPathBase node = WebFSUtils.getNodeByPath(session, parentNodePath);
9797
Path path = node.getPath();
9898
try {
9999
for (Part part : request.getParts()) {

0 commit comments

Comments
 (0)