From 7ed77944bd276f4f52c0be09faf024960c3e0928 Mon Sep 17 00:00:00 2001 From: "tw123.kim" Date: Mon, 6 May 2013 14:25:34 +0900 Subject: [PATCH] [feature] remove unused library, change the process of creating db and modify pc --- CMakeLists.txt | 21 ++++++------ calendar-service.manifest | 7 ++-- calendar-service.pc.in | 2 +- calendar.pc.in | 13 ++++---- client/CMakeLists.txt | 10 +++--- client/calendar-service2.pc.in | 12 +++---- common/cal_mutex.c | 6 ++-- common/cal_record_event.c | 1 - native/CMakeLists.txt | 13 +++----- native/cal_db.c | 14 ++++---- native/calendar-service-native.pc.in | 13 ++++---- native/calendar-service2.pc.in | 14 -------- packaging/calendar-service.spec | 24 ++++---------- schema/CMakeLists.txt | 14 ++++++-- schema/db-gen/Makefile | 22 +++++++++++++ schema/generator.sh | 7 ++++ schema/initdb.c | 64 +++++++++++++++++++++++++++--------- 17 files changed, 149 insertions(+), 108 deletions(-) delete mode 100644 native/calendar-service2.pc.in create mode 100755 schema/db-gen/Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index 8df46ee..e67cfc0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,14 +6,15 @@ PROJECT(calendar-service C CXX) #ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") #MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") -SET(DEST_INCLUDE_DIR "include") +SET(DEST_INCLUDE_DIR "include/calendar-service") SET(SRC_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include") SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") SET(INCLUDEDIR "\${prefix}/${DEST_INCLUDE_DIR}") SET(VERSION_MAJOR 0) -SET(VERSION "${VERSION_MAJOR}.1.14") +SET(VERSION "${VERSION_MAJOR}.1.15") #INCLUDE_DIRECTORIES(${SRC_INCLUDE_DIR}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -I${CMAKE_SOURCE_DIR}/include") @@ -34,15 +35,15 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") -# pkgconfig file -CONFIGURE_FILE(calendar.pc.in calendar.pc @ONLY) -CONFIGURE_FILE(client/calendar-service2.pc.in client/calendar-service2.pc @ONLY) -CONFIGURE_FILE(native/calendar-service-native.pc.in native/calendar-service-native.pc @ONLY) -CONFIGURE_FILE(native/calendar-service2.pc.in native/calendar-service2.pc @ONLY) +#header +FILE(GLOB HEADER_FILES ${SRC_INCLUDE_DIR}/calendar*.h) +INSTALL(FILES ${HEADER_FILES} DESTINATION ${INCLUDEDIR}) +INSTALL(FILES ${HEADER_FILES} DESTINATION ${INCLUDEDIR}2) # for immigration -SET(IMMIGRATION "calendar") -INSTALL(FILES ${IMMIGRATION}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +SET(IMMIGRATION "calendar-service2") +CONFIGURE_FILE(calendar.pc.in calendar.pc @ONLY) +INSTALL(FILES calendar.pc DESTINATION lib/pkgconfig) FILE(GLOB NOTI_FILES ${CMAKE_SOURCE_DIR}/.CALENDAR_SVC_*_CHANGED) INSTALL(FILES ${NOTI_FILES} DESTINATION /opt/usr/data/calendar-svc) @@ -50,5 +51,5 @@ INSTALL(FILES ${NOTI_FILES} DESTINATION /opt/usr/data/calendar-svc) ADD_SUBDIRECTORY(schema) ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(server) -ADD_SUBDIRECTORY(native) +#ADD_SUBDIRECTORY(native) ADD_SUBDIRECTORY(dft) diff --git a/calendar-service.manifest b/calendar-service.manifest index eacbd46..1a2b331 100644 --- a/calendar-service.manifest +++ b/calendar-service.manifest @@ -7,15 +7,14 @@ - + - - - + + diff --git a/calendar-service.pc.in b/calendar-service.pc.in index 909a846..afff9e8 100755 --- a/calendar-service.pc.in +++ b/calendar-service.pc.in @@ -2,7 +2,7 @@ prefix=@PREFIX@ exec_prefix=@EXEC_PREFIX@ -libdir=@LIB_INSTALL_DIR@ +libdir=@LIBDIR@ includedir=@INCLUDEDIR@ Name: @PROJECT_NAME@ diff --git a/calendar.pc.in b/calendar.pc.in index fb2884d..0649999 100644 --- a/calendar.pc.in +++ b/calendar.pc.in @@ -2,13 +2,12 @@ prefix=@PREFIX@ exec_prefix=@EXEC_PREFIX@ -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDEDIR@/calendar-service2 +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ -Name: calendar-service2 -Description: calendar-service2 library -Version: 0.1.8 +Name: @IMMIGRATION@ +Description: @IMMIGRATION@ library +Version: @VERSION@ Requires: glib-2.0 alarm-service -Libs: -L${libdir} -lcalendar-service2 +Libs: -L${libdir} -l@IMMIGRATION@ Cflags: -I${includedir} - diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 288e7f2..5492b12 100755 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -70,9 +70,9 @@ SET_TARGET_PROPERTIES(${CALSVC2} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${CALSVC2} PROPERTIES VERSION ${VERSION}) TARGET_LINK_LIBRARIES(${CALSVC2} ${service2_pkgs_LDFLAGS}) -INSTALL(TARGETS ${CALSVC2} DESTINATION ${LIB_INSTALL_DIR}) -INSTALL(FILES ${CALSVC2}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(TARGETS ${CALSVC2} DESTINATION lib) + +#pc +CONFIGURE_FILE(${CALSVC2}.pc.in ${CALSVC2}.pc @ONLY) +INSTALL(FILES ${CALSVC2}.pc DESTINATION lib/pkgconfig) -#header -FILE(GLOB HEADER_FILES ${INC_DIR}/calendar*.h) -INSTALL(FILES ${HEADER_FILES} DESTINATION include/calendar-service2) diff --git a/client/calendar-service2.pc.in b/client/calendar-service2.pc.in index dae711c..78024ff 100644 --- a/client/calendar-service2.pc.in +++ b/client/calendar-service2.pc.in @@ -2,12 +2,12 @@ prefix=@PREFIX@ exec_prefix=@EXEC_PREFIX@ -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDEDIR@/calendar-service2 +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ -Name: calendar-service2 -Description: calendar-service2 library -Version: 0.1.14 +Name: @CALSVC2@ +Description: @CALSVC2@ library +Version: @VERSION@ Requires: glib-2.0 alarm-service -Libs: -L${libdir} -lcalendar-service2 +Libs: -L${libdir} -l@CALSVC2@ Cflags: -I${includedir} diff --git a/common/cal_mutex.c b/common/cal_mutex.c index 08e6574..1e0a24f 100644 --- a/common/cal_mutex.c +++ b/common/cal_mutex.c @@ -29,7 +29,7 @@ static pthread_mutex_t __cal_pims_ipc_call_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t __cal_inotify_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t __cal_pims_ipc_pubsub_mutex = PTHREAD_MUTEX_INITIALIZER; -static inline pthread_mutex_t* cts_mutex_get_mutex(int type) +static inline pthread_mutex_t* __cal_mutex_get_mutex(int type) { pthread_mutex_t *ret_val; @@ -62,7 +62,7 @@ void _cal_mutex_lock(int type) int ret; pthread_mutex_t *mutex; - mutex = cts_mutex_get_mutex(type); + mutex = __cal_mutex_get_mutex(type); if (mutex != NULL) { @@ -76,7 +76,7 @@ void _cal_mutex_unlock(int type) int ret; pthread_mutex_t *mutex; - mutex = cts_mutex_get_mutex(type); + mutex = __cal_mutex_get_mutex(type); if (mutex != NULL) { diff --git a/common/cal_record_event.c b/common/cal_record_event.c index d9f74bd..d503af8 100644 --- a/common/cal_record_event.c +++ b/common/cal_record_event.c @@ -290,7 +290,6 @@ static int __cal_record_event_clone( calendar_record_h record, calendar_record_h out_data->latitude = src_data->latitude; out_data->longitude = src_data->longitude; out_data->email_id = src_data->email_id; - //out_data->availability = src_data->availability; out_data->created_time = src_data->created_time; //out_data->completed_time = src_data->completed_time; //out_data->progress = src_data->progress; diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index c941562..6059301 100755 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -72,12 +72,9 @@ SET_TARGET_PROPERTIES(${CALSVCNATIVE} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${CALSVCNATIVE} PROPERTIES VERSION ${VERSION}) TARGET_LINK_LIBRARIES(${CALSVCNATIVE} ${servicenative_pkgs_LDFLAGS}) -INSTALL(TARGETS ${CALSVCNATIVE} DESTINATION ${LIB_INSTALL_DIR}) -INSTALL(FILES ${CALSVCNATIVE}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -#INSTALL(FILES calendar-service2.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - -#header -FILE(GLOB HEADER_FILES ${INC_DIR}/calendar*.h) -INSTALL(FILES ${HEADER_FILES} DESTINATION include/calendar-service-native) - +INSTALL(TARGETS ${CALSVCNATIVE} DESTINATION lib) +#pc +CONFIGURE_FILE(${CALSVCNATIVE}.pc.in ${CALSVCNATIVE}.pc @ONLY) +INSTALL(FILES ${CALSVCNATIVE}.pc DESTINATION lib/pkgconfig) +#INSTALL(FILES calendar-service2.pc DESTINATION lib/pkgconfig) diff --git a/native/cal_db.c b/native/cal_db.c index 6f958e4..b898321 100644 --- a/native/cal_db.c +++ b/native/cal_db.c @@ -279,7 +279,7 @@ static void __cal_db_initialize_view_table(void) * schedule_table(type=1) + rrule_table */ snprintf(query, sizeof(query), - "CREATE TEMP VIEW %s AS " + "CREATE VIEW IF NOT EXISTS %s AS " "SELECT A.*, " "B.freq, B.range_type, B.until_type, B.until_utime, B.until_datetime, B.count, " "B.interval, B.bysecond, B.byminute, B.byhour, B.byday, B.bymonthday, " @@ -306,7 +306,7 @@ static void __cal_db_initialize_view_table(void) * schedule_table(type=2) + rrule_table */ snprintf(query, sizeof(query), - "CREATE TEMP VIEW %s AS " + "CREATE VIEW IF NOT EXISTS %s AS " "SELECT A.*, " "B.freq, B.range_type, B.until_type, B.until_utime, B.until_datetime, B.count, " "B.interval, B.bysecond, B.byminute, B.byhour, B.byday, B.bymonthday, " @@ -336,7 +336,7 @@ static void __cal_db_initialize_view_table(void) * C = calendar_table */ snprintf(query, sizeof(query), - "CREATE TEMP VIEW %s AS SELECT A.event_id, " + "CREATE VIEW IF NOT EXISTS %s AS SELECT A.event_id, " "B.dtstart_type, A.dtstart_utime, B.dtstart_datetime, " "B.dtend_type, A.dtend_utime, B.dtend_datetime, " "B.summary, B.description, " @@ -360,7 +360,7 @@ static void __cal_db_initialize_view_table(void) // CAL_VIEW_TABLE_ALLDAY_INSTANCE : CALENDAR_VIEW_INSTANCE_ALLDAY_CALENDAR snprintf(query, sizeof(query), - "CREATE TEMP VIEW %s AS SELECT A.event_id, " + "CREATE VIEW IF NOT EXISTS %s AS SELECT A.event_id, " "B.dtstart_type, B.dtstart_utime, A.dtstart_datetime, " "B.dtend_type, B.dtend_utime, A.dtend_datetime, " "B.summary, B.description, " @@ -384,7 +384,7 @@ static void __cal_db_initialize_view_table(void) // event_calendar view : CALENDAR_VIEW_EVENT_CALENDAR snprintf(query, sizeof(query), - "CREATE TEMP VIEW %s AS " + "CREATE VIEW IF NOT EXISTS %s AS " "SELECT A.* " ", B.freq, B.range_type, B.until_type, B.until_utime, B.until_datetime, B.count, " "B.interval, B.bysecond, B.byminute, B.byhour, B.byday, B.bymonthday, " @@ -406,7 +406,7 @@ static void __cal_db_initialize_view_table(void) // todo_calendar view : CALENDAR_VIEW_TODO_CALENDAR snprintf(query, sizeof(query), - "CREATE TEMP VIEW %s AS " + "CREATE VIEW IF NOT EXISTS %s AS " "SELECT A.* " ", B.freq, B.range_type, B.until_type, B.until_utime, B.until_datetime, B.count, " "B.interval, B.bysecond, B.byminute, B.byhour, B.byday, B.bymonthday, " @@ -428,7 +428,7 @@ static void __cal_db_initialize_view_table(void) // event_calendar_attendee view : CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE snprintf(query, sizeof(query), - "CREATE TEMP VIEW %s AS " + "CREATE VIEW IF NOT EXISTS %s AS " "SELECT A.* " ", D.freq, D.range_type, D.until_type, D.until_utime, D.until_datetime, D.count, " "D.interval, D.bysecond, D.byminute, D.byhour, D.byday, D.bymonthday, " diff --git a/native/calendar-service-native.pc.in b/native/calendar-service-native.pc.in index 4e9a21e..bd88f1a 100644 --- a/native/calendar-service-native.pc.in +++ b/native/calendar-service-native.pc.in @@ -2,13 +2,12 @@ prefix=@PREFIX@ exec_prefix=@EXEC_PREFIX@ -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDEDIR@/calendar-service-native +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ -Name: calendar-service-native -Description: calendar-service-native library -Version: 0.1.13 +Name: @CALSVCNATIVE@ +Description: @CALSVCNATIVE@ library +Version: @VERSION@ Requires: glib-2.0 alarm-service db-util capi-base-common -Libs: -L${libdir} -lcalendar-service-native +Libs: -L${libdir} -l@CALSVCNATIVE@ Cflags: -I${includedir} - diff --git a/native/calendar-service2.pc.in b/native/calendar-service2.pc.in deleted file mode 100644 index 4e9a21e..0000000 --- a/native/calendar-service2.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -# Package Information for pkg-config - -prefix=@PREFIX@ -exec_prefix=@EXEC_PREFIX@ -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDEDIR@/calendar-service-native - -Name: calendar-service-native -Description: calendar-service-native library -Version: 0.1.13 -Requires: glib-2.0 alarm-service db-util capi-base-common -Libs: -L${libdir} -lcalendar-service-native -Cflags: -I${includedir} - diff --git a/packaging/calendar-service.spec b/packaging/calendar-service.spec index 61f8f9a..89350e7 100644 --- a/packaging/calendar-service.spec +++ b/packaging/calendar-service.spec @@ -1,7 +1,7 @@ Name: calendar-service Summary: DB library for calendar -Version: 0.1.14 -Release: 86 +Version: 0.1.15 +Release: 1 Group: System/Libraries License: Apache 2.0 Source0: %{name}-%{version}.tar.gz @@ -64,17 +64,6 @@ ln -s ../calendar.service %{buildroot}/usr/lib/systemd/user/tizen-middleware.tar chown :6003 /opt/usr/data/calendar-svc mkdir -p /opt/usr/dbspace -if [ -f /opt/usr/dbspace/.calendar-svc.db ] -then - echo "calendar-svc.db exist" -else - calendar-svc-initdb -fi - -if [ -f %{_libdir}/rpm-plugins/msm.so ] -then - chsmack -a 'calendar-service::db' /opt/usr/dbspace/.calendar-svc.db* -fi chown :6003 /opt/usr/dbspace/.calendar-svc.db chown :6003 /opt/usr/dbspace/.calendar-svc.db-journal @@ -89,8 +78,7 @@ chmod 660 /opt/usr/data/calendar-svc/.CALENDAR_SVC_* %files %manifest calendar-service.manifest %defattr(-,root,root,-) -%{_bindir}/calendar-svc-initdb -%{_libdir}/libcalendar-service-native.so.* +#%{_libdir}/libcalendar-service-native.so.* %{_bindir}/calendar-serviced* %{_libdir}/libcalendar-service2.so.* %attr(0755,root,root) /etc/rc.d/init.d/calendar-serviced.sh @@ -101,14 +89,16 @@ chmod 660 /opt/usr/data/calendar-svc/.CALENDAR_SVC_* /opt/usr/data/calendar-svc/.CALENDAR_SVC_EVENT_CHANGED /opt/usr/data/calendar-svc/.CALENDAR_SVC_TODO_CHANGED /usr/share/calendar-svc/dft-calendar +%config(noreplace) /opt/usr/dbspace/.calendar-svc.db* /usr/lib/systemd/user/calendar.service /usr/lib/systemd/user/tizen-middleware.target.wants/calendar.service %files devel %defattr(-,root,root,-) -%{_includedir}/calendar-service-native/*.h +%{_includedir}/calendar-service/*.h %{_includedir}/calendar-service2/*.h %{_libdir}/*.so %{_libdir}/pkgconfig/calendar.pc -%{_libdir}/pkgconfig/calendar-service-native.pc +#%{_libdir}/pkgconfig/calendar-service-native.pc %{_libdir}/pkgconfig/calendar-service2.pc +/opt/usr/data/calendar-svc/calendar-svc-initdb diff --git a/schema/CMakeLists.txt b/schema/CMakeLists.txt index 76515d5..f3dcc2c 100755 --- a/schema/CMakeLists.txt +++ b/schema/CMakeLists.txt @@ -4,7 +4,10 @@ SET(TARGET calendar-svc-initdb) EXECUTE_PROCESS(COMMAND ./generator.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -FILE(GLOB SRCS *.c) +#FILE(GLOB SRCS *.c) + +SET(INITDBFILE initdb.c) +SET(TOOLLIB calendar-service2) pkg_check_modules(initdb_pkgs REQUIRED db-util dlog) @@ -15,8 +18,13 @@ ENDFOREACH(flag) #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -ADD_EXECUTABLE(${TARGET} ${SRCS}) +#ADD_EXECUTABLE(${TARGET} ${SRCS}) +ADD_EXECUTABLE(${TARGET} ${INITDBFILE}) SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS}) TARGET_LINK_LIBRARIES(${TARGET} ${initdb_pkgs_LDFLAGS}) -INSTALL(TARGETS ${TARGET} DESTINATION bin) +#INSTALL(TARGETS ${TARGET} DESTINATION bin) +INSTALL(TARGETS ${TARGET} DESTINATION /opt/usr/data/calendar-svc) + +FILE(GLOB DB_FILES ${CMAKE_SOURCE_DIR}/schema/.calendar-svc.db*) +INSTALL(FILES ${DB_FILES} DESTINATION /opt/usr/dbspace) diff --git a/schema/db-gen/Makefile b/schema/db-gen/Makefile new file mode 100755 index 0000000..6fa00e1 --- /dev/null +++ b/schema/db-gen/Makefile @@ -0,0 +1,22 @@ +CC = gcc + +REQUIRED_PKG = db-util +CFLAGS = -g -Wall #-fprofile-arcs -ftest-coverage +LDFLAGS = +ifdef REQUIRED_PKG + CFLAGS += `pkg-config --cflags $(REQUIRED_PKG)` + LDFLAGS += `pkg-config --libs $(REQUIRED_PKG)` +endif + +SRCS = $(wildcard ../initdb.c) +OBJECTS = $(SRCS:.c=.o) +TARGETS = $(OBJECTS:.o=) + +all: $(TARGETS) + +% : %.o + $(CC) $(LDFLAGS) -o $@ $< + +clean: + rm -rf $(OBJECTS) $(TARGETS) + diff --git a/schema/generator.sh b/schema/generator.sh index 5e7a238..e900e5a 100755 --- a/schema/generator.sh +++ b/schema/generator.sh @@ -27,3 +27,10 @@ make ./schema-header-gen ../schema.sql > ../schema.h make clean + +# Make DB +cd ../db-gen +make +../initdb ../ + +make clean diff --git a/schema/initdb.c b/schema/initdb.c index 36f3763..7b849ef 100755 --- a/schema/initdb.c +++ b/schema/initdb.c @@ -25,21 +25,37 @@ #include "schema.h" -#define CALS_DB_PATH "/opt/usr/dbspace/.calendar-svc.db" -#define CALS_DB_JOURNAL_PATH "/opt/usr/dbspace/.calendar-svc.db-journal" +#define CALS_DB_NAME ".calendar-svc.db" +#define CALS_DB_JOURNAL_NAME ".calendar-svc.db-journal" +#define CALS_DB_PATH "/opt/usr/dbspace/"CALS_DB_NAME +#define CALS_DB_JOURNAL_PATH "/opt/usr/dbspace/"CALS_DB_JOURNAL_NAME // For Security #define CALS_SECURITY_FILE_GROUP 6003 #define CALS_SECURITY_DEFAULT_PERMISSION 0660 #define CALS_SECURITY_DIR_DEFAULT_PERMISSION 0770 -static inline int remake_db_file() +static inline int remake_db_file(char* db_path) { int ret, fd; char *errmsg; sqlite3 *db; + char db_file[256]={0,}; + char db_journal_file[256]={0,}; + + if(db_path == NULL) + { + snprintf(db_file,sizeof(db_file),CALS_DB_PATH); + snprintf(db_journal_file,sizeof(db_journal_file),CALS_DB_JOURNAL_PATH); + } + else + { + snprintf(db_file,sizeof(db_file),"%s%s",db_path, CALS_DB_NAME); + snprintf(db_journal_file,sizeof(db_journal_file),"%s%s", db_path, CALS_DB_JOURNAL_NAME); + } + + ret = db_util_open(db_file, &db, 0); - ret = db_util_open(CALS_DB_PATH, &db, 0); if (SQLITE_OK != ret) { printf("db_util_open() Failed(%d)\n", ret); @@ -54,7 +70,7 @@ static inline int remake_db_file() db_util_close(db); - fd = open(CALS_DB_PATH, O_CREAT | O_RDWR, 0660); + fd = open(db_file, O_CREAT | O_RDWR, 0660); if (-1 == fd) { printf("open Failed\n"); @@ -71,7 +87,8 @@ static inline int remake_db_file() fchmod(fd, CALS_SECURITY_DEFAULT_PERMISSION); close(fd); - fd = open(CALS_DB_JOURNAL_PATH, O_CREAT | O_RDWR, 0660); + fd = open(db_journal_file, O_CREAT | O_RDWR, 0660); + if (-1 == fd) { printf("open Failed\n"); @@ -91,28 +108,45 @@ static inline int remake_db_file() return 0; } -static inline int check_db_file(void) +static inline int check_db_file(char* db_path) { - int fd = open(CALS_DB_PATH, O_RDONLY); + int fd = -1; + + char db_file[256]={0,}; + if(db_path == NULL) + { + snprintf(db_file,sizeof(db_file),CALS_DB_PATH); + } + else + { + snprintf(db_file,sizeof(db_file),"%s%s",db_path, CALS_DB_NAME); + } + + fd = open(db_file, O_RDONLY); + if (-1 == fd) { - printf("DB file(%s) is not exist\n", CALS_DB_PATH); + printf("DB file(%s) is not exist\n", db_file); return -1; } - + printf("DB file(%s) \n", db_file); close(fd); return 0; } -static inline int check_schema(void) +static inline int check_schema(char* db_path) { - if (check_db_file()) - remake_db_file(); - + if (check_db_file(db_path)) + remake_db_file(db_path); return 0; } int main(int argc, char **argv) { - return check_schema(); + char *tmp = NULL; + if(argc > 1) + { + tmp = argv[1]; + } + return check_schema(tmp); } -- 2.7.4