update 23
This commit is contained in:
61
src/main/java/research/loghunter/config/DatabaseConfig.java
Normal file
61
src/main/java/research/loghunter/config/DatabaseConfig.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package research.loghunter.config;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* 데이터베이스 및 앱 디렉토리 초기화 설정
|
||||
*
|
||||
* 앱 실행 시 필요한 디렉토리를 자동으로 생성합니다.
|
||||
* - ~/.loghunter/data/ : SQLite DB 파일
|
||||
* - ~/.loghunter/exports/ : 내보내기 파일
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class DatabaseConfig {
|
||||
|
||||
@Value("${app.base-path}")
|
||||
private String basePath;
|
||||
|
||||
@Value("${app.export.path}")
|
||||
private String exportPath;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
try {
|
||||
// 기본 디렉토리 생성
|
||||
Path baseDir = Paths.get(basePath);
|
||||
createDirectoryIfNotExists(baseDir);
|
||||
|
||||
// 데이터 디렉토리 생성
|
||||
Path dataDir = baseDir.resolve("data");
|
||||
createDirectoryIfNotExists(dataDir);
|
||||
|
||||
// 내보내기 디렉토리 생성
|
||||
Path exportsDir = Paths.get(exportPath);
|
||||
createDirectoryIfNotExists(exportsDir);
|
||||
|
||||
log.info("LogHunter 디렉토리 초기화 완료: {}", basePath);
|
||||
log.info(" - 데이터: {}", dataDir);
|
||||
log.info(" - 내보내기: {}", exportsDir);
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("디렉토리 생성 실패: {}", e.getMessage());
|
||||
throw new RuntimeException("LogHunter 디렉토리 초기화 실패", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void createDirectoryIfNotExists(Path dir) throws IOException {
|
||||
if (!Files.exists(dir)) {
|
||||
Files.createDirectories(dir);
|
||||
log.info("디렉토리 생성: {}", dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user