mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-08-10 11:13:50 +00:00
Support loading configuration from database.
This commit is contained in:
parent
1dbc15f38e
commit
b11f861fbd
@ -22,6 +22,7 @@ noinst_HEADERS = \
|
|||||||
block.h \
|
block.h \
|
||||||
mq-mgr.h \
|
mq-mgr.h \
|
||||||
seaf-db.h \
|
seaf-db.h \
|
||||||
|
config-mgr.h \
|
||||||
merge-new.h \
|
merge-new.h \
|
||||||
block-tx-utils.h \
|
block-tx-utils.h \
|
||||||
sync-repo-common.h \
|
sync-repo-common.h \
|
||||||
|
210
common/config-mgr.c
Normal file
210
common/config-mgr.c
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
#include "common.h"
|
||||||
|
#include "config-mgr.h"
|
||||||
|
#include "seaf-db.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_init (SeafCfgManager *mgr)
|
||||||
|
{
|
||||||
|
char *sql;
|
||||||
|
int db_type = seaf_db_type(mgr->db);
|
||||||
|
|
||||||
|
if (db_type == SEAF_DB_TYPE_MYSQL)
|
||||||
|
sql = "CREATE TABLE IF NOT EXISTS SeafileConf (cfg_group VARCHAR(255) NOT NULL,"
|
||||||
|
"cfg_key VARCHAR(255) NOT NULL, value VARCHAR(255), property INTEGER) ENGINE=INNODB";
|
||||||
|
else
|
||||||
|
sql = "CREATE TABLE IF NOT EXISTS SeafileConf (cfg_group VARCHAR(255) NOT NULL,"
|
||||||
|
"cfg_key VARCHAR(255) NOT NULL, value VARCHAR(255), property INTEGER)";
|
||||||
|
|
||||||
|
if (seaf_db_query (mgr->db, sql) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SeafCfgManager *
|
||||||
|
seaf_cfg_manager_new (SeafileSession *session)
|
||||||
|
{
|
||||||
|
SeafCfgManager *mgr = g_new0 (SeafCfgManager, 1);
|
||||||
|
if (!mgr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
mgr->config = session->config;
|
||||||
|
mgr->db = session->db;
|
||||||
|
|
||||||
|
return mgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config_int (SeafCfgManager *mgr,
|
||||||
|
const char *group,
|
||||||
|
const char *key,
|
||||||
|
int value)
|
||||||
|
{
|
||||||
|
char value_str[256];
|
||||||
|
|
||||||
|
snprintf (value_str, sizeof(value_str), "%d", value);
|
||||||
|
|
||||||
|
return seaf_cfg_manager_set_config (mgr, group, key, value_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config_int64 (SeafCfgManager *mgr,
|
||||||
|
const char *group,
|
||||||
|
const char *key,
|
||||||
|
gint64 value)
|
||||||
|
{
|
||||||
|
char value_str[256];
|
||||||
|
|
||||||
|
snprintf (value_str, sizeof(value_str), "%"G_GINT64_FORMAT"", value);
|
||||||
|
|
||||||
|
return seaf_cfg_manager_set_config (mgr, group, key, value_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config_string (SeafCfgManager *mgr,
|
||||||
|
const char *group,
|
||||||
|
const char *key,
|
||||||
|
const char *value)
|
||||||
|
{
|
||||||
|
char value_str[256];
|
||||||
|
|
||||||
|
snprintf (value_str, sizeof(value_str), "%s", value);
|
||||||
|
|
||||||
|
return seaf_cfg_manager_set_config (mgr, group, key, value_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config_boolean (SeafCfgManager *mgr,
|
||||||
|
const char *group,
|
||||||
|
const char *key,
|
||||||
|
gboolean value)
|
||||||
|
{
|
||||||
|
char value_str[256];
|
||||||
|
|
||||||
|
if (value)
|
||||||
|
snprintf (value_str, sizeof(value_str), "true");
|
||||||
|
else
|
||||||
|
snprintf (value_str, sizeof(value_str), "false");
|
||||||
|
|
||||||
|
return seaf_cfg_manager_set_config (mgr, group, key, value_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config (SeafCfgManager *mgr, const char *group, const char *key, const char *value)
|
||||||
|
{
|
||||||
|
gboolean exists, err = FALSE;
|
||||||
|
|
||||||
|
char *sql = "SELECT 1 FROM SeafileConf WHERE cfg_group=? AND cfg_key=?";
|
||||||
|
exists = seaf_db_statement_exists(mgr->db, sql, &err,
|
||||||
|
2, "string", group,
|
||||||
|
"string", key);
|
||||||
|
if (err) {
|
||||||
|
seaf_warning ("[db error]Failed to set config [%s:%s] to db.\n", group, key);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (exists)
|
||||||
|
sql = "UPDATE SeafileConf SET value=? WHERE cfg_group=? AND cfg_key=?";
|
||||||
|
else
|
||||||
|
sql = "INSERT INTO SeafileConf (value, cfg_group, cfg_key, property) VALUES "
|
||||||
|
"(?,?,?,0)";
|
||||||
|
if (seaf_db_statement_query (mgr->db, sql, 3,
|
||||||
|
"string", value, "string",
|
||||||
|
group, "string", key) < 0) {
|
||||||
|
seaf_warning ("Failed to set config [%s:%s] to db.\n", group, key);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_get_config_int (SeafCfgManager *mgr, const char *group, const char *key)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char *invalid = NULL;
|
||||||
|
|
||||||
|
char *value = seaf_cfg_manager_get_config (mgr, group, key);
|
||||||
|
if (!value)
|
||||||
|
ret = -1;
|
||||||
|
else {
|
||||||
|
ret = strtol (value, &invalid, 10);
|
||||||
|
if (*invalid != '\0') {
|
||||||
|
ret = -1;
|
||||||
|
seaf_warning ("Value of config [%s:%s] is invalid: [%s]\n", group, key, value);
|
||||||
|
}
|
||||||
|
g_free (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
gint64
|
||||||
|
seaf_cfg_manager_get_config_int64 (SeafCfgManager *mgr, const char *group, const char *key)
|
||||||
|
{
|
||||||
|
gint64 ret;
|
||||||
|
char *invalid = NULL;
|
||||||
|
|
||||||
|
char *value = seaf_cfg_manager_get_config (mgr, group, key);
|
||||||
|
if (!value)
|
||||||
|
ret = -1;
|
||||||
|
else {
|
||||||
|
ret = strtoll (value, &invalid, 10);
|
||||||
|
if (*invalid != '\0') {
|
||||||
|
seaf_warning ("Value of config [%s:%s] is invalid: [%s]\n", group, key, value);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
g_free (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
seaf_cfg_manager_get_config_boolean (SeafCfgManager *mgr, const char *group, const char *key)
|
||||||
|
{
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
|
char *value = seaf_cfg_manager_get_config (mgr, group, key);
|
||||||
|
if (!value) {
|
||||||
|
seaf_warning ("Config [%s:%s] not set, default is false.\n", group, key);
|
||||||
|
ret = FALSE;
|
||||||
|
} else {
|
||||||
|
if (strcmp ("true", value) == 0)
|
||||||
|
ret = TRUE;
|
||||||
|
else
|
||||||
|
ret = FALSE;
|
||||||
|
g_free (value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
seaf_cfg_manager_get_config_string (SeafCfgManager *mgr, const char *group, const char *key)
|
||||||
|
{
|
||||||
|
char *ret = NULL;
|
||||||
|
|
||||||
|
char *value = seaf_cfg_manager_get_config (mgr, group, key);
|
||||||
|
if (!value)
|
||||||
|
ret = NULL;
|
||||||
|
else {
|
||||||
|
ret = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
seaf_cfg_manager_get_config (SeafCfgManager *mgr, const char *group, const char *key)
|
||||||
|
{
|
||||||
|
char *sql = "SELECT value FROM SeafileConf WHERE cfg_group=? AND cfg_key=?";
|
||||||
|
char *value = seaf_db_statement_get_string(mgr->db, sql,
|
||||||
|
2, "string", group, "string", key);
|
||||||
|
if (!value) {
|
||||||
|
value = g_key_file_get_string (mgr->config, group, key, NULL);
|
||||||
|
if (value)
|
||||||
|
seaf_cfg_manager_set_config (mgr, group, key, value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
50
common/config-mgr.h
Normal file
50
common/config-mgr.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#ifndef SEAF_CONFIG_MGR_H
|
||||||
|
#define SEAF_CONFIG_MGR_H
|
||||||
|
|
||||||
|
typedef struct _SeafCfgManager SeafCfgManager;
|
||||||
|
#include "seafile-session.h"
|
||||||
|
|
||||||
|
struct _SeafCfgManager {
|
||||||
|
GKeyFile *config;
|
||||||
|
SeafDB *db;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct _SeafileSession SeafileSession;
|
||||||
|
|
||||||
|
SeafCfgManager *
|
||||||
|
seaf_cfg_manager_new (SeafileSession *seaf);
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config (SeafCfgManager *mgr, const char *group, const char *key, const char *value);
|
||||||
|
|
||||||
|
char *
|
||||||
|
seaf_cfg_manager_get_config (SeafCfgManager *mgr, const char *group, const char *key);
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config_int (SeafCfgManager *mgr, const char *group, const char *key, int value);
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_get_config_int (SeafCfgManager *mgr, const char *group, const char *key);
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config_int64 (SeafCfgManager *mgr, const char *group, const char *key, gint64 value);
|
||||||
|
|
||||||
|
gint64
|
||||||
|
seaf_cfg_manager_get_config_int64 (SeafCfgManager *mgr, const char *group, const char *key);
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config_string (SeafCfgManager *mgr, const char *group, const char *key, const char *value);
|
||||||
|
|
||||||
|
char *
|
||||||
|
seaf_cfg_manager_get_config_string (SeafCfgManager *mgr, const char *group, const char *key);
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_set_config_boolean (SeafCfgManager *mgr, const char *group, const char *key, gboolean value);
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
seaf_cfg_manager_get_config_boolean (SeafCfgManager *mgr, const char *group, const char *key);
|
||||||
|
|
||||||
|
int
|
||||||
|
seaf_cfg_manager_init (SeafCfgManager *mgr);
|
||||||
|
|
||||||
|
#endif /* SEAF_CONFIG_MGR_H */
|
@ -5135,4 +5135,95 @@ seafile_mkdir_with_parents (const char *repo_id, const char *parent_dir,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_set_server_config_int (const char *group, const char *key, int value,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
if (!group || !key) {
|
||||||
|
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return seaf_cfg_manager_set_config_int (seaf->cfg_mgr, group, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_get_server_config_int (const char *group, const char *key, GError **error)
|
||||||
|
{
|
||||||
|
if (!group || !key ) {
|
||||||
|
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return seaf_cfg_manager_get_config_int (seaf->cfg_mgr, group, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_set_server_config_int64 (const char *group, const char *key, gint64 value,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
if (!group || !key) {
|
||||||
|
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return seaf_cfg_manager_set_config_int64 (seaf->cfg_mgr, group, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
gint64
|
||||||
|
seafile_get_server_config_int64 (const char *group, const char *key, GError **error)
|
||||||
|
{
|
||||||
|
if (!group || !key ) {
|
||||||
|
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return seaf_cfg_manager_get_config_int64 (seaf->cfg_mgr, group, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_set_server_config_string (const char *group, const char *key, const char *value,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
if (!group || !key || !value) {
|
||||||
|
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return seaf_cfg_manager_set_config_string (seaf->cfg_mgr, group, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
seafile_get_server_config_string (const char *group, const char *key, GError **error)
|
||||||
|
{
|
||||||
|
if (!group || !key ) {
|
||||||
|
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return seaf_cfg_manager_get_config_string (seaf->cfg_mgr, group, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_set_server_config_boolean (const char *group, const char *key, int value,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
if (!group || !key) {
|
||||||
|
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return seaf_cfg_manager_set_config_boolean (seaf->cfg_mgr, group, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_get_server_config_boolean (const char *group, const char *key, GError **error)
|
||||||
|
{
|
||||||
|
if (!group || !key ) {
|
||||||
|
g_set_error (error, 0, SEAF_ERR_BAD_ARGS, "Argument should not be null");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return seaf_cfg_manager_get_config_boolean (seaf->cfg_mgr, group, key);
|
||||||
|
}
|
||||||
#endif /* SEAFILE_SERVER */
|
#endif /* SEAFILE_SERVER */
|
||||||
|
@ -1045,4 +1045,28 @@ seafile_get_file_count_info_by_path (const char *repo_id,
|
|||||||
|
|
||||||
char *
|
char *
|
||||||
seafile_get_trash_repo_owner (const char *repo_id, GError **error);
|
seafile_get_trash_repo_owner (const char *repo_id, GError **error);
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_set_server_config_int (const char *group, const char *key, int value, GError **error);
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_get_server_config_int (const char *group, const char *key, GError **error);
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_set_server_config_int64 (const char *group, const char *key, gint64 value, GError **error);
|
||||||
|
|
||||||
|
gint64
|
||||||
|
seafile_get_server_config_int64 (const char *group, const char *key, GError **error);
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_set_server_config_string (const char *group, const char *key, const char *value, GError **error);
|
||||||
|
|
||||||
|
char *
|
||||||
|
seafile_get_server_config_string (const char *group, const char *key, GError **error);
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_set_server_config_boolean (const char *group, const char *key, int value, GError **error);
|
||||||
|
|
||||||
|
int
|
||||||
|
seafile_get_server_config_boolean (const char *group, const char *key, GError **error);
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,6 +19,8 @@ func_table = [
|
|||||||
[ "int", ["string", "int", "string", "string"] ],
|
[ "int", ["string", "int", "string", "string"] ],
|
||||||
[ "int", ["string", "int", "int", "string", "string"] ],
|
[ "int", ["string", "int", "int", "string", "string"] ],
|
||||||
[ "int", ["string", "string"] ],
|
[ "int", ["string", "string"] ],
|
||||||
|
[ "int", ["string", "string", "int"] ],
|
||||||
|
[ "int", ["string", "string", "int64"] ],
|
||||||
[ "int", ["string", "string", "string"] ],
|
[ "int", ["string", "string", "string"] ],
|
||||||
[ "int", ["string", "string", "int", "int"] ],
|
[ "int", ["string", "string", "int", "int"] ],
|
||||||
[ "int", ["string", "string", "string", "int"] ],
|
[ "int", ["string", "string", "string", "int"] ],
|
||||||
@ -35,6 +37,7 @@ func_table = [
|
|||||||
[ "int64", ["string"] ],
|
[ "int64", ["string"] ],
|
||||||
[ "int64", ["int"]],
|
[ "int64", ["int"]],
|
||||||
[ "int64", ["int", "string"]],
|
[ "int64", ["int", "string"]],
|
||||||
|
[ "int64", ["string", "string"]],
|
||||||
[ "int64", ["string", "int", "string"] ],
|
[ "int64", ["string", "int", "string"] ],
|
||||||
[ "string", [] ],
|
[ "string", [] ],
|
||||||
[ "string", ["int"] ],
|
[ "string", ["int"] ],
|
||||||
|
@ -973,3 +973,35 @@ class SeafServerThreadedRpcClient(ccnet.RpcClientBase):
|
|||||||
def seafile_mkdir_with_parents (repo_id, parent_dir, relative_path, username):
|
def seafile_mkdir_with_parents (repo_id, parent_dir, relative_path, username):
|
||||||
pass
|
pass
|
||||||
mkdir_with_parents = seafile_mkdir_with_parents
|
mkdir_with_parents = seafile_mkdir_with_parents
|
||||||
|
|
||||||
|
@searpc_func("int", ["string", "string"])
|
||||||
|
def get_server_config_int (group, key):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@searpc_func("int", ["string", "string", "int"])
|
||||||
|
def set_server_config_int (group, key, value):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@searpc_func("int64", ["string", "string"])
|
||||||
|
def get_server_config_int64 (group, key):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@searpc_func("int", ["string", "string", "int64"])
|
||||||
|
def set_server_config_int64 (group, key, value):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@searpc_func("string", ["string", "string"])
|
||||||
|
def get_server_config_string (group, key):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@searpc_func("int", ["string", "string", "string"])
|
||||||
|
def set_server_config_string (group, key, value):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@searpc_func("int", ["string", "string"])
|
||||||
|
def get_server_config_boolean (group, key):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@searpc_func("int", ["string", "string", "int"])
|
||||||
|
def set_server_config_boolean (group, key, value):
|
||||||
|
pass
|
||||||
|
@ -681,6 +681,31 @@ class SeafileAPI(object):
|
|||||||
def mkdir_with_parents (self, repo_id, parent_dir, relative_path, username):
|
def mkdir_with_parents (self, repo_id, parent_dir, relative_path, username):
|
||||||
return seafserv_threaded_rpc.mkdir_with_parents(repo_id, parent_dir, relative_path, username)
|
return seafserv_threaded_rpc.mkdir_with_parents(repo_id, parent_dir, relative_path, username)
|
||||||
|
|
||||||
|
def get_server_config_int (self, group, key):
|
||||||
|
return seafserv_threaded_rpc.get_server_config_int (group, key)
|
||||||
|
|
||||||
|
def set_server_config_int (self, group, key, value):
|
||||||
|
return seafserv_threaded_rpc.set_server_config_int (group, key, value)
|
||||||
|
|
||||||
|
def get_server_config_int64 (self, group, key):
|
||||||
|
return seafserv_threaded_rpc.get_server_config_int64 (group, key)
|
||||||
|
|
||||||
|
def set_server_config_int64 (self, group, key, value):
|
||||||
|
return seafserv_threaded_rpc.set_server_config_int64 (group, key, value)
|
||||||
|
|
||||||
|
def get_server_config_string (self, group, key):
|
||||||
|
return seafserv_threaded_rpc.get_server_config_string (group, key)
|
||||||
|
|
||||||
|
def set_server_config_string (self, group, key, value):
|
||||||
|
return seafserv_threaded_rpc.set_server_config_string (group, key, value)
|
||||||
|
|
||||||
|
def get_server_config_boolean (self, group, key):
|
||||||
|
return bool(seafserv_threaded_rpc.get_server_config_boolean (group, key))
|
||||||
|
|
||||||
|
def set_server_config_boolean (self, group, key, value):
|
||||||
|
i_value = 1 if bool(value) else 0
|
||||||
|
return seafserv_threaded_rpc.set_server_config_boolean (group, key, i_value)
|
||||||
|
|
||||||
seafile_api = SeafileAPI()
|
seafile_api = SeafileAPI()
|
||||||
|
|
||||||
class CcnetAPI(object):
|
class CcnetAPI(object):
|
||||||
|
@ -77,6 +77,7 @@ seaf_server_SOURCES = \
|
|||||||
fileserver-config.c \
|
fileserver-config.c \
|
||||||
../common/seaf-db.c \
|
../common/seaf-db.c \
|
||||||
../common/branch-mgr.c ../common/fs-mgr.c \
|
../common/branch-mgr.c ../common/fs-mgr.c \
|
||||||
|
../common/config-mgr.c \
|
||||||
repo-mgr.c ../common/commit-mgr.c \
|
repo-mgr.c ../common/commit-mgr.c \
|
||||||
../common/log.c ../common/object-list.c \
|
../common/log.c ../common/object-list.c \
|
||||||
../common/rpc-service.c \
|
../common/rpc-service.c \
|
||||||
|
@ -35,7 +35,8 @@ common_sources = \
|
|||||||
../../common/seaf-utils.c \
|
../../common/seaf-utils.c \
|
||||||
../../common/obj-store.c \
|
../../common/obj-store.c \
|
||||||
../../common/obj-backend-fs.c \
|
../../common/obj-backend-fs.c \
|
||||||
../../common/seafile-crypt.c
|
../../common/seafile-crypt.c \
|
||||||
|
../../common/config-mgr.c
|
||||||
|
|
||||||
seafserv_gc_SOURCES = \
|
seafserv_gc_SOURCES = \
|
||||||
seafserv-gc.c \
|
seafserv-gc.c \
|
||||||
|
@ -494,7 +494,8 @@ seaf_repo_manager_get_repo_history_limit (SeafRepoManager *mgr,
|
|||||||
get_limit, &per_repo_days);
|
get_limit, &per_repo_days);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
/* If per repo value is not set, return the global one. */
|
/* If per repo value is not set, return the global one. */
|
||||||
return mgr->seaf->keep_history_days;
|
per_repo_days = seaf_cfg_manager_get_config_int (mgr->seaf->cfg_mgr,
|
||||||
|
"history", "keep_days");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (per_repo_days < 0) {
|
if (per_repo_days < 0) {
|
||||||
|
@ -36,21 +36,6 @@ static void usage ()
|
|||||||
"usage: seaf-migrate [-c config_dir] [-d seafile_dir]\n");
|
"usage: seaf-migrate [-c config_dir] [-d seafile_dir]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
load_history_config ()
|
|
||||||
{
|
|
||||||
int keep_history_days;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
seaf->keep_history_days = -1;
|
|
||||||
|
|
||||||
keep_history_days = g_key_file_get_integer (seaf->config,
|
|
||||||
"history", "keep_days",
|
|
||||||
&error);
|
|
||||||
if (error == NULL)
|
|
||||||
seaf->keep_history_days = keep_history_days;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
/* Get the commandline arguments in unicode, then convert them to utf8 */
|
/* Get the commandline arguments in unicode, then convert them to utf8 */
|
||||||
static char **
|
static char **
|
||||||
@ -136,8 +121,6 @@ main(int argc, char *argv[])
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
load_history_config ();
|
|
||||||
|
|
||||||
migrate_v0_repos_to_v1_layout ();
|
migrate_v0_repos_to_v1_layout ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -77,6 +77,10 @@ seafile_session_new(const char *central_config_dir,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session->cfg_mgr = seaf_cfg_manager_new (session);
|
||||||
|
if (!session->cfg_mgr)
|
||||||
|
goto onerror;
|
||||||
|
|
||||||
session->fs_mgr = seaf_fs_manager_new (session, abs_seafile_dir);
|
session->fs_mgr = seaf_fs_manager_new (session, abs_seafile_dir);
|
||||||
if (!session->fs_mgr)
|
if (!session->fs_mgr)
|
||||||
goto onerror;
|
goto onerror;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include "repo-mgr.h"
|
#include "repo-mgr.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
#include "seaf-db.h"
|
#include "seaf-db.h"
|
||||||
|
#include "config-mgr.h"
|
||||||
|
|
||||||
struct _CcnetClient;
|
struct _CcnetClient;
|
||||||
|
|
||||||
@ -30,8 +31,8 @@ struct _SeafileSession {
|
|||||||
SeafCommitManager *commit_mgr;
|
SeafCommitManager *commit_mgr;
|
||||||
SeafBranchManager *branch_mgr;
|
SeafBranchManager *branch_mgr;
|
||||||
SeafRepoManager *repo_mgr;
|
SeafRepoManager *repo_mgr;
|
||||||
|
SeafCfgManager *cfg_mgr;
|
||||||
|
|
||||||
int keep_history_days;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SeafileSession *seaf;
|
extern SeafileSession *seaf;
|
||||||
|
@ -41,21 +41,6 @@ static void usage ()
|
|||||||
"-V, --verbose: verbose output messages\n");
|
"-V, --verbose: verbose output messages\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
load_history_config ()
|
|
||||||
{
|
|
||||||
int keep_history_days;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
seaf->keep_history_days = -1;
|
|
||||||
|
|
||||||
keep_history_days = g_key_file_get_integer (seaf->config,
|
|
||||||
"history", "keep_days",
|
|
||||||
&error);
|
|
||||||
if (error == NULL)
|
|
||||||
seaf->keep_history_days = keep_history_days;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
/* Get the commandline arguments in unicode, then convert them to utf8 */
|
/* Get the commandline arguments in unicode, then convert them to utf8 */
|
||||||
static char **
|
static char **
|
||||||
@ -158,8 +143,6 @@ main(int argc, char *argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
load_history_config ();
|
|
||||||
|
|
||||||
GList *repo_id_list = NULL;
|
GList *repo_id_list = NULL;
|
||||||
int i;
|
int i;
|
||||||
for (i = optind; i < argc; i++)
|
for (i = optind; i < argc; i++)
|
||||||
|
@ -114,8 +114,6 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session)
|
|||||||
int port = 0;
|
int port = 0;
|
||||||
int web_token_expire_time;
|
int web_token_expire_time;
|
||||||
int fixed_block_size_mb;
|
int fixed_block_size_mb;
|
||||||
int max_upload_size_mb;
|
|
||||||
int max_download_dir_size_mb;
|
|
||||||
char *encoding;
|
char *encoding;
|
||||||
int max_indexing_threads;
|
int max_indexing_threads;
|
||||||
|
|
||||||
@ -173,32 +171,6 @@ load_http_config (HttpServerStruct *htp_server, SeafileSession *session)
|
|||||||
htp_server->web_token_expire_time = web_token_expire_time;
|
htp_server->web_token_expire_time = web_token_expire_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
max_upload_size_mb = fileserver_config_get_integer (session->config,
|
|
||||||
"max_upload_size",
|
|
||||||
&error);
|
|
||||||
if (error) {
|
|
||||||
htp_server->max_upload_size = -1; /* no limit */
|
|
||||||
g_clear_error (&error);
|
|
||||||
} else {
|
|
||||||
if (max_upload_size_mb <= 0)
|
|
||||||
htp_server->max_upload_size = -1; /* no limit */
|
|
||||||
else
|
|
||||||
htp_server->max_upload_size = max_upload_size_mb * ((gint64)1 << 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
max_download_dir_size_mb = fileserver_config_get_integer (session->config,
|
|
||||||
"max_download_dir_size",
|
|
||||||
&error);
|
|
||||||
if (error) {
|
|
||||||
htp_server->max_download_dir_size = DEFAULT_MAX_DOWNLOAD_DIR_SIZE;
|
|
||||||
g_clear_error (&error);
|
|
||||||
} else {
|
|
||||||
if (max_download_dir_size_mb <= 0)
|
|
||||||
htp_server->max_download_dir_size = DEFAULT_MAX_DOWNLOAD_DIR_SIZE;
|
|
||||||
else
|
|
||||||
htp_server->max_download_dir_size = max_download_dir_size_mb * ((gint64)1 << 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
max_indexing_threads = fileserver_config_get_integer (session->config,
|
max_indexing_threads = fileserver_config_get_integer (session->config,
|
||||||
"max_indexing_threads",
|
"max_indexing_threads",
|
||||||
&error);
|
&error);
|
||||||
|
@ -17,8 +17,6 @@ struct _HttpServerStruct {
|
|||||||
char *http_temp_dir; /* temp dir for file upload */
|
char *http_temp_dir; /* temp dir for file upload */
|
||||||
char *windows_encoding;
|
char *windows_encoding;
|
||||||
gint64 fixed_block_size;
|
gint64 fixed_block_size;
|
||||||
gint64 max_upload_size;
|
|
||||||
gint64 max_download_dir_size;
|
|
||||||
int web_token_expire_time;
|
int web_token_expire_time;
|
||||||
int max_indexing_threads;
|
int max_indexing_threads;
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#define TB 1000000000000L
|
#define TB 1000000000000L
|
||||||
|
|
||||||
static gint64
|
static gint64
|
||||||
get_default_quota (GKeyFile *config)
|
get_default_quota (SeafCfgManager *mgr)
|
||||||
{
|
{
|
||||||
char *quota_str;
|
char *quota_str;
|
||||||
char *end;
|
char *end;
|
||||||
@ -26,7 +26,7 @@ get_default_quota (GKeyFile *config)
|
|||||||
gint64 multiplier = GB;
|
gint64 multiplier = GB;
|
||||||
gint64 quota;
|
gint64 quota;
|
||||||
|
|
||||||
quota_str = g_key_file_get_string (config, "quota", "default", NULL);
|
quota_str = seaf_cfg_manager_get_config (mgr, "quota", "default");
|
||||||
if (!quota_str)
|
if (!quota_str)
|
||||||
return INFINITE_QUOTA;
|
return INFINITE_QUOTA;
|
||||||
|
|
||||||
@ -68,7 +68,6 @@ seaf_quota_manager_new (struct _SeafileSession *session)
|
|||||||
return NULL;
|
return NULL;
|
||||||
mgr->session = session;
|
mgr->session = session;
|
||||||
|
|
||||||
mgr->default_quota = get_default_quota (session->config);
|
|
||||||
mgr->calc_share_usage = g_key_file_get_boolean (session->config,
|
mgr->calc_share_usage = g_key_file_get_boolean (session->config,
|
||||||
"quota", "calc_share_usage",
|
"quota", "calc_share_usage",
|
||||||
NULL);
|
NULL);
|
||||||
@ -206,7 +205,7 @@ seaf_quota_manager_get_user_quota (SeafQuotaManager *mgr,
|
|||||||
quota = seaf_db_statement_get_int64 (mgr->session->db, sql,
|
quota = seaf_db_statement_get_int64 (mgr->session->db, sql,
|
||||||
1, "string", user);
|
1, "string", user);
|
||||||
if (quota <= 0)
|
if (quota <= 0)
|
||||||
quota = mgr->default_quota;
|
quota = get_default_quota (seaf->cfg_mgr);
|
||||||
|
|
||||||
return quota;
|
return quota;
|
||||||
}
|
}
|
||||||
@ -255,7 +254,7 @@ seaf_quota_manager_get_org_quota (SeafQuotaManager *mgr,
|
|||||||
sql = "SELECT quota FROM OrgQuota WHERE org_id=?";
|
sql = "SELECT quota FROM OrgQuota WHERE org_id=?";
|
||||||
quota = seaf_db_statement_get_int64 (mgr->session->db, sql, 1, "int", org_id);
|
quota = seaf_db_statement_get_int64 (mgr->session->db, sql, 1, "int", org_id);
|
||||||
if (quota <= 0)
|
if (quota <= 0)
|
||||||
quota = mgr->default_quota;
|
quota = get_default_quota (seaf->cfg_mgr);
|
||||||
|
|
||||||
return quota;
|
return quota;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
struct _SeafQuotaManager {
|
struct _SeafQuotaManager {
|
||||||
struct _SeafileSession *session;
|
struct _SeafileSession *session;
|
||||||
|
|
||||||
gint64 default_quota;
|
|
||||||
gboolean calc_share_usage;
|
gboolean calc_share_usage;
|
||||||
};
|
};
|
||||||
typedef struct _SeafQuotaManager SeafQuotaManager;
|
typedef struct _SeafQuotaManager SeafQuotaManager;
|
||||||
|
@ -39,7 +39,6 @@ struct _SeafRepoManagerPriv {
|
|||||||
CcnetTimer *reap_token_timer;
|
CcnetTimer *reap_token_timer;
|
||||||
|
|
||||||
CcnetTimer *scan_trash_timer;
|
CcnetTimer *scan_trash_timer;
|
||||||
gint64 trash_expire_interval;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -250,7 +249,15 @@ scan_trash (void *data)
|
|||||||
{
|
{
|
||||||
GList *repo_ids = NULL;
|
GList *repo_ids = NULL;
|
||||||
SeafRepoManager *mgr = seaf->repo_mgr;
|
SeafRepoManager *mgr = seaf->repo_mgr;
|
||||||
gint64 expire_time = time(NULL) - mgr->priv->trash_expire_interval;
|
gint64 trash_expire_interval = TRASH_EXPIRE_DAYS * 24 * 3600;
|
||||||
|
int expire_days = seaf_cfg_manager_get_config_int (seaf->cfg_mgr,
|
||||||
|
"library_trash",
|
||||||
|
"expire_days");
|
||||||
|
if (expire_days > 0) {
|
||||||
|
trash_expire_interval = expire_days * 24 * 3600;
|
||||||
|
}
|
||||||
|
|
||||||
|
gint64 expire_time = time(NULL) - trash_expire_interval;
|
||||||
char *sql = "SELECT repo_id FROM RepoTrash WHERE del_time <= ?";
|
char *sql = "SELECT repo_id FROM RepoTrash WHERE del_time <= ?";
|
||||||
|
|
||||||
int ret = seaf_db_statement_foreach_row (seaf->db, sql,
|
int ret = seaf_db_statement_foreach_row (seaf->db, sql,
|
||||||
@ -280,7 +287,6 @@ static void
|
|||||||
init_scan_trash_timer (SeafRepoManagerPriv *priv, GKeyFile *config)
|
init_scan_trash_timer (SeafRepoManagerPriv *priv, GKeyFile *config)
|
||||||
{
|
{
|
||||||
int scan_days;
|
int scan_days;
|
||||||
int expire_days;
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
scan_days = g_key_file_get_integer (config,
|
scan_days = g_key_file_get_integer (config,
|
||||||
@ -291,15 +297,6 @@ init_scan_trash_timer (SeafRepoManagerPriv *priv, GKeyFile *config)
|
|||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
}
|
}
|
||||||
|
|
||||||
expire_days = g_key_file_get_integer (config,
|
|
||||||
"library_trash", "expire_days",
|
|
||||||
&error);
|
|
||||||
if (error) {
|
|
||||||
expire_days = TRASH_EXPIRE_DAYS;
|
|
||||||
g_clear_error (&error);
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->trash_expire_interval = expire_days * 24 * 3600;
|
|
||||||
priv->scan_trash_timer = ccnet_timer_new (scan_trash, NULL,
|
priv->scan_trash_timer = ccnet_timer_new (scan_trash, NULL,
|
||||||
scan_days * 24 * 3600 * 1000);
|
scan_days * 24 * 3600 * 1000);
|
||||||
}
|
}
|
||||||
@ -1933,7 +1930,8 @@ seaf_repo_manager_get_repo_history_limit (SeafRepoManager *mgr,
|
|||||||
&per_repo_days, 1, "string", r_repo_id);
|
&per_repo_days, 1, "string", r_repo_id);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
// limit not set, return global one
|
// limit not set, return global one
|
||||||
per_repo_days = mgr->seaf->keep_history_days;
|
per_repo_days= seaf_cfg_manager_get_config_int (mgr->seaf->cfg_mgr,
|
||||||
|
"history", "keep_days");
|
||||||
}
|
}
|
||||||
|
|
||||||
// db error or limit set as negative, means keep full history, return -1
|
// db error or limit set as negative, means keep full history, return -1
|
||||||
@ -2468,6 +2466,7 @@ collect_trash_repo (SeafDBRow *row, void *data)
|
|||||||
repo_id, head_id);
|
repo_id, head_id);
|
||||||
if (!commit) {
|
if (!commit) {
|
||||||
seaf_warning ("Commit %s not found in repo %s\n", head_id, repo_id);
|
seaf_warning ("Commit %s not found in repo %s\n", head_id, repo_id);
|
||||||
|
g_object_unref (trash_repo);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
g_object_set (trash_repo, "encrypted", commit->encrypted, NULL);
|
g_object_set (trash_repo, "encrypted", commit->encrypted, NULL);
|
||||||
|
@ -726,6 +726,48 @@ static void start_rpc_service (CcnetClient *client, int cloud_mode)
|
|||||||
seafile_generate_magic_and_random_key,
|
seafile_generate_magic_and_random_key,
|
||||||
"generate_magic_and_random_key",
|
"generate_magic_and_random_key",
|
||||||
searpc_signature_object__int_string_string());
|
searpc_signature_object__int_string_string());
|
||||||
|
|
||||||
|
/* Config */
|
||||||
|
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||||
|
seafile_get_server_config_int,
|
||||||
|
"get_server_config_int",
|
||||||
|
searpc_signature_int__string_string());
|
||||||
|
|
||||||
|
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||||
|
seafile_set_server_config_int,
|
||||||
|
"set_server_config_int",
|
||||||
|
searpc_signature_int__string_string_int());
|
||||||
|
|
||||||
|
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||||
|
seafile_get_server_config_int64,
|
||||||
|
"get_server_config_int64",
|
||||||
|
searpc_signature_int64__string_string());
|
||||||
|
|
||||||
|
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||||
|
seafile_set_server_config_int64,
|
||||||
|
"set_server_config_int64",
|
||||||
|
searpc_signature_int__string_string_int64());
|
||||||
|
|
||||||
|
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||||
|
seafile_get_server_config_string,
|
||||||
|
"get_server_config_string",
|
||||||
|
searpc_signature_string__string_string());
|
||||||
|
|
||||||
|
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||||
|
seafile_set_server_config_string,
|
||||||
|
"set_server_config_string",
|
||||||
|
searpc_signature_int__string_string_string());
|
||||||
|
|
||||||
|
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||||
|
seafile_get_server_config_boolean,
|
||||||
|
"get_server_config_boolean",
|
||||||
|
searpc_signature_int__string_string());
|
||||||
|
|
||||||
|
searpc_server_register_function ("seafserv-threaded-rpcserver",
|
||||||
|
seafile_set_server_config_boolean,
|
||||||
|
"set_server_config_boolean",
|
||||||
|
searpc_signature_int__string_string_int());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct event sigusr1;
|
static struct event sigusr1;
|
||||||
@ -817,23 +859,6 @@ write_pidfile (const char *pidfile_path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
load_history_config ()
|
|
||||||
{
|
|
||||||
int keep_history_days;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
seaf->keep_history_days = -1;
|
|
||||||
|
|
||||||
keep_history_days = g_key_file_get_integer (seaf->config,
|
|
||||||
"history", "keep_days",
|
|
||||||
&error);
|
|
||||||
if (error == NULL)
|
|
||||||
seaf->keep_history_days = keep_history_days;
|
|
||||||
else
|
|
||||||
g_clear_error (&error);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_seaf_server_exit(void)
|
on_seaf_server_exit(void)
|
||||||
{
|
{
|
||||||
@ -1011,8 +1036,6 @@ main (int argc, char **argv)
|
|||||||
seaf->client_pool = ccnet_client_pool_new (central_config_dir, config_dir);
|
seaf->client_pool = ccnet_client_pool_new (central_config_dir, config_dir);
|
||||||
seaf->cloud_mode = cloud_mode;
|
seaf->cloud_mode = cloud_mode;
|
||||||
|
|
||||||
load_history_config ();
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
set_syslog_config (seaf->config);
|
set_syslog_config (seaf->config);
|
||||||
#endif
|
#endif
|
||||||
|
@ -91,6 +91,10 @@ seafile_session_new(const char *central_config_dir,
|
|||||||
goto onerror;
|
goto onerror;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session->cfg_mgr = seaf_cfg_manager_new (session);
|
||||||
|
if (!session->cfg_mgr)
|
||||||
|
goto onerror;
|
||||||
|
|
||||||
if (load_thread_pool_config (session) < 0) {
|
if (load_thread_pool_config (session) < 0) {
|
||||||
seaf_warning ("Failed to load thread pool config.\n");
|
seaf_warning ("Failed to load thread pool config.\n");
|
||||||
goto onerror;
|
goto onerror;
|
||||||
@ -193,6 +197,9 @@ seafile_session_init (SeafileSession *session)
|
|||||||
if (seaf_quota_manager_init (session->quota_mgr) < 0)
|
if (seaf_quota_manager_init (session->quota_mgr) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (seaf_cfg_manager_init (session->cfg_mgr) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
seaf_mq_manager_init (session->mq_mgr);
|
seaf_mq_manager_init (session->mq_mgr);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "listen-mgr.h"
|
#include "listen-mgr.h"
|
||||||
#include "size-sched.h"
|
#include "size-sched.h"
|
||||||
#include "copy-mgr.h"
|
#include "copy-mgr.h"
|
||||||
|
#include "config-mgr.h"
|
||||||
|
|
||||||
#include "mq-mgr.h"
|
#include "mq-mgr.h"
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ struct _SeafileSession {
|
|||||||
SeafQuotaManager *quota_mgr;
|
SeafQuotaManager *quota_mgr;
|
||||||
SeafListenManager *listen_mgr;
|
SeafListenManager *listen_mgr;
|
||||||
SeafCopyManager *copy_mgr;
|
SeafCopyManager *copy_mgr;
|
||||||
|
SeafCfgManager *cfg_mgr;
|
||||||
|
|
||||||
SeafWebAccessTokenManager *web_at_mgr;
|
SeafWebAccessTokenManager *web_at_mgr;
|
||||||
|
|
||||||
@ -81,7 +83,6 @@ struct _SeafileSession {
|
|||||||
int is_master;
|
int is_master;
|
||||||
|
|
||||||
int cloud_mode;
|
int cloud_mode;
|
||||||
int keep_history_days;
|
|
||||||
|
|
||||||
int rpc_thread_pool_size;
|
int rpc_thread_pool_size;
|
||||||
int sync_thread_pool_size;
|
int sync_thread_pool_size;
|
||||||
|
@ -241,6 +241,7 @@ check_tmp_file_list (GList *tmp_files, int *error_code)
|
|||||||
char *tmp_file;
|
char *tmp_file;
|
||||||
SeafStat st;
|
SeafStat st;
|
||||||
gint64 total_size = 0;
|
gint64 total_size = 0;
|
||||||
|
gint64 max_upload_size;
|
||||||
|
|
||||||
for (ptr = tmp_files; ptr; ptr = ptr->next) {
|
for (ptr = tmp_files; ptr; ptr = ptr->next) {
|
||||||
tmp_file = ptr->data;
|
tmp_file = ptr->data;
|
||||||
@ -253,9 +254,15 @@ check_tmp_file_list (GList *tmp_files, int *error_code)
|
|||||||
|
|
||||||
total_size += (gint64)st.st_size;
|
total_size += (gint64)st.st_size;
|
||||||
}
|
}
|
||||||
|
/* default is MB */
|
||||||
if (seaf->http_server->max_upload_size != -1 &&
|
max_upload_size = seaf_cfg_manager_get_config_int64 (seaf->cfg_mgr, "fileserver",
|
||||||
total_size > seaf->http_server->max_upload_size) {
|
"max_upload_size");
|
||||||
|
if (max_upload_size > 0)
|
||||||
|
max_upload_size = max_upload_size * ((gint64)1 << 20);
|
||||||
|
else
|
||||||
|
max_upload_size = -1;
|
||||||
|
|
||||||
|
if (max_upload_size > 0 && total_size > max_upload_size) {
|
||||||
seaf_debug ("[upload] File size is too large.\n");
|
seaf_debug ("[upload] File size is too large.\n");
|
||||||
*error_code = ERROR_SIZE;
|
*error_code = ERROR_SIZE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#define MAX_ZIP_THREAD_NUM 5
|
#define MAX_ZIP_THREAD_NUM 5
|
||||||
#define SCAN_PROGRESS_INTERVAL 24 * 3600 // 1 day
|
#define SCAN_PROGRESS_INTERVAL 24 * 3600 // 1 day
|
||||||
#define PROGRESS_TTL 5 * 3600 // 5 hours
|
#define PROGRESS_TTL 5 * 3600 // 5 hours
|
||||||
|
#define DEFAULT_MAX_DOWNLOAD_DIR_SIZE 100 * ((gint64)1 << 20) /* 100MB */
|
||||||
|
|
||||||
typedef struct ZipDownloadMgrPriv {
|
typedef struct ZipDownloadMgrPriv {
|
||||||
pthread_mutex_t progress_lock;
|
pthread_mutex_t progress_lock;
|
||||||
@ -406,6 +407,7 @@ validate_download_size (DownloadObj *obj, GError **error)
|
|||||||
{
|
{
|
||||||
SeafRepo *repo = obj->repo;
|
SeafRepo *repo = obj->repo;
|
||||||
gint64 download_size;
|
gint64 download_size;
|
||||||
|
gint64 max_download_dir_size;
|
||||||
|
|
||||||
if (obj->type == DOWNLOAD_DIR) {
|
if (obj->type == DOWNLOAD_DIR) {
|
||||||
download_size = seaf_fs_manager_get_fs_size (seaf->fs_mgr,
|
download_size = seaf_fs_manager_get_fs_size (seaf->fs_mgr,
|
||||||
@ -415,15 +417,23 @@ validate_download_size (DownloadObj *obj, GError **error)
|
|||||||
download_size = calcuate_download_multi_size (repo, (GList *)obj->internal);
|
download_size = calcuate_download_multi_size (repo, (GList *)obj->internal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* default is MB */
|
||||||
|
max_download_dir_size = seaf_cfg_manager_get_config_int64 (seaf->cfg_mgr, "fileserver",
|
||||||
|
"max_download_dir_size");
|
||||||
|
if (max_download_dir_size > 0)
|
||||||
|
max_download_dir_size = max_download_dir_size * ((gint64)1 << 20);
|
||||||
|
else
|
||||||
|
max_download_dir_size = DEFAULT_MAX_DOWNLOAD_DIR_SIZE;
|
||||||
|
|
||||||
if (download_size < 0) {
|
if (download_size < 0) {
|
||||||
seaf_warning ("Failed to get download size.\n");
|
seaf_warning ("Failed to get download size.\n");
|
||||||
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
|
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
|
||||||
"Failed to get download size.");
|
"Failed to get download size.");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else if (download_size > seaf->http_server->max_download_dir_size) {
|
} else if (download_size > max_download_dir_size) {
|
||||||
seaf_warning ("Total download size %"G_GINT64_FORMAT
|
seaf_warning ("Total download size %"G_GINT64_FORMAT
|
||||||
", exceed max download dir size %"G_GINT64_FORMAT".\n",
|
", exceed max download dir size %"G_GINT64_FORMAT".\n",
|
||||||
download_size, seaf->http_server->max_download_dir_size);
|
download_size, max_download_dir_size);
|
||||||
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
|
g_set_error (error, SEAFILE_DOMAIN, SEAF_ERR_GENERAL,
|
||||||
"Download size exceed max download dir size.");
|
"Download size exceed max download dir size.");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
Loading…
Reference in New Issue
Block a user