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

Clean up files have been read in workspace #44

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,30 @@ private Map<String, String> getImportantFilesContent(String workspace) {
if (workPath.isDirectory() && workPath.exists()) {
File[] files = workPath.listFiles();
if (Objects.nonNull(files)) {
List<File> importantFiles = Arrays.stream(files)
.filter(file -> file.isFile() && !isExcludedFile(file.getName())).toList();
for (File importantFile : importantFiles) {
try {
String content = Files.readString(importantFile.toPath());
fileContentMap.put(importantFile.getName(), content);
} catch (IOException e) {
log.error("Read content of file with name:{} error.",
importantFile.getName(), e);
Arrays.stream(files).forEach(file -> {
if (file.isFile() && !isExcludedFile(file.getName())) {
String content = readFileContentAndDelete(file);
fileContentMap.put(file.getName(), content);
}
}
});
}
}
return fileContentMap;
}

private String readFileContentAndDelete(File file) {
String fileContent = "";
try {
fileContent = Files.readString(file.toPath());
boolean deleted = Files.deleteIfExists(file.toPath());
log.info("Read file content with name:{} successfully. Delete result:{}",
file.getName(), deleted);
} catch (IOException e) {
log.error("Read file content with name:{} error.", file.getName(), e);
}
return fileContent;
}

private void deleteWorkspace(String workspace) {
Path path = Paths.get(workspace);
try (Stream<Path> pathStream = Files.walk(path)) {
Expand Down