Skip to content

Commit

Permalink
Clean up files have been read in workspace (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
baixinsui authored Jul 30, 2024
1 parent a8898b7 commit 91ae892
Showing 1 changed file with 18 additions and 10 deletions.
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

0 comments on commit 91ae892

Please sign in to comment.