Skip to content

Commit

Permalink
Clean up files have been read in workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
baixinsui committed Jul 30, 2024
1 parent a8898b7 commit 97c2601
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,29 @@ 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).filter(file -> file.isFile()
&& !isExcludedFile(file.getName())).forEach(file -> {
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

0 comments on commit 97c2601

Please sign in to comment.