-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get nickname from seahub database #663
Conversation
common/merge-new.c
Outdated
} | ||
g_hash_table_insert (email_to_nickname, g_strdup(modifier), g_strdup(nickname)); | ||
|
||
return g_strdup (nickname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
实际上返回的时候可以不复制 nickname,直接将 hash table 里面的 value 返回,以为这个 hash table 是不会被改变的。
common/seaf-utils.c
Outdated
&error); | ||
|
||
if (error != NULL) { | ||
seaf_warning ("Failed to run python parse_seahub_db.py : %s\n", error->message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error 需要释放一下。
common/seaf-utils.c
Outdated
return -1; | ||
} | ||
if (retcode != 0) { | ||
seaf_warning ("Failed to run python parse_seahub_db.py [%d]: %s\n", retcode, strerror(errno)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该可以使用 g_spawn_check_wait_status 把这个 wait status 转换为 GError 吧,这样处理更方便一些。你现在这样处理也是不对的,这个 retcode 是 waitpid 返回的。
char *child_stdout = NULL; | ||
char *child_stderr = NULL; | ||
|
||
char *binary_path = g_find_program_in_path ("parse_seahub_db.py"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个字符串要释放一下吧。
port = MYSQL_DEFAULT_PORT; | ||
} | ||
|
||
if (!engine || strstr (engine, "sqlite") != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqlite 是不能支持多进程同时打开的吧,而且11版本之后 sqlite 已经不支持了。所以这里如果检测到 sqlite 就不用做 username 的转换了。
#ifdef HAVE_MYSQL | ||
else if (strstr (engine, "mysql") != NULL) { | ||
seaf_message("Use database Mysql\n"); | ||
session->seahub_db = seaf_db_new_mysql (host, port, user, password, name, NULL, FALSE, FALSE, NULL, charset, DEFAULT_MAX_CONNECTIONS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要检查必要的参数是否已经设置了。
if err != nil || port <= 0 { | ||
port = 3306 | ||
} | ||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?tls=%t", user, password, host, port, dbName, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也需要类似 C 部分改一下。
另外,怎样保证在 go fileserver 运行之前 seaf-server 已经解析好了 seahub_db.json 呢?而且把数据库密码这些敏感信息写入到 tmp 下面也有安全问题的,应该改为 seaf-server 和 go fileserver 都直接把 python 脚本的输出读取到内存里面,不需要临时文件。
common/merge-new.c
Outdated
@@ -46,11 +74,14 @@ merge_conflict_filename (const char *store_id, int version, | |||
seaf_commit_unref (commit); | |||
} | |||
|
|||
conflict_name = gen_conflict_path (filename, modifier, mtime); | |||
nickname = get_nickname_by_modifier (opt->email_to_nickname, modifier); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该在这个位置先检查 seahub_db 是否为 NULL,如果为 NULL 就表明不支持从 seahub_db 查找用户名称,按照原有的逻辑即可。
server/virtual-repo.c
Outdated
@@ -952,6 +952,10 @@ static void *merge_virtual_repo (void *vtask) | |||
memcpy (opt.remote_repo_id, repo_id, 36); | |||
memcpy (opt.remote_head, head->commit_id, 40); | |||
opt.do_merge = TRUE; | |||
opt.email_to_nickname = g_hash_table_new_full(g_str_hash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个哈希表可以在 seaf_merge_trees 函数内部创建和释放,这样就不用改所有调用这个函数的地方了。
common/seaf-utils.c
Outdated
} | ||
|
||
g_free (binary_path); | ||
return g_strdup(child_stdout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个应该不用复制吧,因为本来就是新分配的。
char *child_stdout = NULL; | ||
char *child_stderr = NULL; | ||
|
||
char *binary_path = g_find_program_in_path ("parse_seahub_db.py"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
怎样保证能找到这个脚本呢?需要把脚本放在 bin 目录下面的话,需要记录一个任务告诉马宇航处理一下。
No description provided.