diff --git a/src/db/db_sqlite.c b/src/db/db_sqlite.c index 66f9346..45a36cf 100644 --- a/src/db/db_sqlite.c +++ b/src/db/db_sqlite.c @@ -234,7 +234,7 @@ int32_t db_user_auth(i_auth_t *c, o_auth_t *r) { if (res == db_success) { char u_buf[128]; - sprintf(u_buf, "UPDATE users SET last_login = NOW() WHERE id = %u", r->uid); + sprintf(u_buf, "UPDATE users SET last_login = date() WHERE id = %u", r->uid); sqlite3_exec(db, u_buf, NULL, NULL, NULL); return r->uid; } @@ -295,7 +295,7 @@ int32_t db_save_file(session *s) { res = db_query("INSERT INTO files(user_id, name, size, created_at, " "hash, description, permissions) " - "VALUES ($1, $2, $3, NOW(), $4, $5, $6) " + "VALUES ($1, $2, $3, date(), $4, $5, $6) " "RETURNING id", db_save_file_cb, &resp_data, arg_types, s->uid, sfP->name, sfP->size, sfP->hash, diff --git a/src/file_p.h b/src/file_p.h index 14d3d52..c806ec5 100644 --- a/src/file_p.h +++ b/src/file_p.h @@ -22,4 +22,5 @@ int file_receive_prepare(session *sess, char *line, server_data_t *s_d); int file_upload_description(session *sess, char *line, server_data_t *s_d); int file_save_db(session *sess, server_data_t *s_d); void clear_file_from_sess(session *); +int directory_exists(const char *path); #endif \ No newline at end of file diff --git a/src/server.c b/src/server.c index b47cc07..c28da59 100644 --- a/src/server.c +++ b/src/server.c @@ -2,6 +2,7 @@ /* Copyright (c) 2026 Oleksandr Zhylin */ #include "main.h" +#include "file_p.h" #include "session.h" #include #include @@ -12,6 +13,7 @@ #include #include #include +#include #include void server_main_loop(server_data_t *s_d) { @@ -63,8 +65,7 @@ void server_main_loop(server_data_t *s_d) { /* download/upload file */ if (connections[i] != NULL && (connections[i]->state == OP_UPLOAD || connections[i]->state == OP_DOWNLOAD)) { - if (connections[i]->fd > -1 && - FD_ISSET(connections[i]->fd, &readfds)) { + if (connections[i]->fd > -1 && FD_ISSET(connections[i]->fd, &readfds)) { perform_session_action(connections[i], NULL, s_d); } } else if (connections[i] != NULL && FD_ISSET(i, &readfds)) { @@ -93,7 +94,7 @@ char *get_welcome_mes(void) { perror(WELCOME_FILE_NAME); exit(7); } - int filesize = lseek(fd, 0, SEEK_END)+1; + int filesize = lseek(fd, 0, SEEK_END) + 1; lseek(fd, 0, SEEK_SET); char *welcome_message = mmap(NULL, filesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); @@ -102,7 +103,7 @@ char *get_welcome_mes(void) { close(fd); exit(5); } - welcome_message[filesize-1] = '\04'; + welcome_message[filesize - 1] = '\04'; close(fd); return welcome_message; } @@ -143,4 +144,8 @@ void prepare_start(int argc, char *argv[]) { perror(argv[1]); exit(2); } + + if (!directory_exists(STORAGE_FOLDER)) { + mkdir(STORAGE_FOLDER, 0700); + } } \ No newline at end of file