Skip to content

Commit

Permalink
Dev 1.1.18 mv hdfs file (apache#390)
Browse files Browse the repository at this point in the history
* push hdfs file code

* push hdfs file code

* push chmod code

* update test

* code  opitization

* code opmitization

* update regex  for  chmod

* update api

* chmod support file path default file://

* fix  chmod  hdfs  error
  • Loading branch information
v-kkhuang committed Jan 2, 2024
1 parent ff252a1 commit 7b3d3c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public class WorkspaceExceptionManager {
put(
"80032",
"The file size exceeds 30M and page viewing is currently not supported. Please download to view or view in a shared directory(文件大小超过30M,暂不支持页面查看。请下载查看或在共享目录中查看)");
put("80033", "The log file exceeds 30MB and is too large and cannot be opened (日志文件超过30M,文件太大暂不支持打开查看)");
put(
"80033",
"The log file exceeds 30MB and is too large and cannot be opened (日志文件超过30M,文件太大暂不支持打开查看)");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,41 +1195,37 @@ public Message chmod(
if (StringUtils.isEmpty(filePermission)) {
return Message.error(MessageFormat.format(PARAMETER_NOT_BLANK, filePermission));
}
if (!filePath.startsWith("file://") || !filePath.startsWith("hdfs://")) {
if (!filePath.startsWith("file://") && !filePath.startsWith("hdfs://")) {
filePath = "file://" + filePath;
}
if (!checkIsUsersDirectory(filePath, userName, false)) {
return Message.error(MessageFormat.format(FILEPATH_ILLEGALITY, filePath));
} else {
List<String> pathList = new ArrayList<>();
FileSystem fileSystem = fsService.getFileSystem(userName, new FsPath(filePath));
Stack<FsPath> dirsToChmod = new Stack<>();
dirsToChmod.push(new FsPath(filePath));
if (isRecursion) {
traverseFolder(new FsPath(filePath).toFile(), pathList);
} else {
pathList.add(filePath);
traverseFolder(new FsPath(filePath), fileSystem, dirsToChmod);
}
for (String path : pathList) {
FsPath fsPath = new FsPath(path);
FileSystem fileSystem = fsService.getFileSystem(userName, fsPath);
fileSystem.setPermission(fsPath, filePermission);
while (!dirsToChmod.empty()) {
fileSystem.setPermission(dirsToChmod.pop(), filePermission);
}
return Message.ok();
}
}

private static List<String> traverseFolder(File folder, List<String> pathList) {
File[] files = folder.listFiles();
pathList.add(folder.getAbsolutePath());
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
// If it is a folder, recursively traverse
traverseFolder(file, pathList);
} else {
// If it is a file, save the output file address
pathList.add(file.getAbsolutePath());
}
private static void traverseFolder(
FsPath fsPath, FileSystem fileSystem, Stack<FsPath> dirsToChmod) throws IOException {
List<FsPath> list = fileSystem.list(fsPath);
if (list == null) {
return;
}
for (FsPath path : list) {
if (path.isdir()) {
traverseFolder(path, fileSystem, dirsToChmod);
} else {
dirsToChmod.push(path);
}
}
return pathList;
}
}

0 comments on commit 7b3d3c9

Please sign in to comment.