Skip to content

Commit

Permalink
Add last_modify field in form
Browse files Browse the repository at this point in the history
  • Loading branch information
杨赫然 committed Jul 16, 2024
1 parent 06851a1 commit 5caa192
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions common/rpc-service.c
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,7 @@ seafile_post_multi_files (const char *repo_id,
paths_json,
user,
replace_existed,
0,
&ret_json,
NULL,
error);
Expand Down
1 change: 1 addition & 0 deletions server/index-blocks-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ start_index_task (gpointer data, gpointer user_data)
idx_para->user,
idx_para->ret_json ? &ret_json : NULL,
idx_para->replace_existed,
0,
idx_para->canon_path,
id_list,
size_list,
Expand Down
2 changes: 2 additions & 0 deletions server/repo-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr,
const char *paths_json,
const char *user,
int replace_existed,
gint64 mtime,
char **new_ids,
char **task_id,
GError **error);
Expand Down Expand Up @@ -911,6 +912,7 @@ post_files_and_gen_commit (GList *filenames,
const char *user,
char **ret_json,
int replace_existed,
gint64 mtime,
const char *canon_path,
GList *id_list,
GList *size_list,
Expand Down
13 changes: 11 additions & 2 deletions server/repo-op.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ post_files_and_gen_commit (GList *filenames,
const char *user,
char **ret_json,
int replace_existed,
gint64 mtime,
const char *canon_path,
GList *id_list,
GList *size_list,
Expand Down Expand Up @@ -904,6 +905,7 @@ do_post_multi_files (SeafRepo *repo,
GList *size_list,
const char *user,
int replace_existed,
gint64 mtime,
GList **name_list)
{
SeafDirent *dent;
Expand All @@ -925,7 +927,11 @@ do_post_multi_files (SeafRepo *repo,
dent->id[40] = '\0';
dent->size = *size;
dent->mode = STD_FILE_MODE;
dent->mtime = (gint64)time(NULL);
if (mtime > 0) {
dent->mtime = mtime;
} else {
dent->mtime = (gint64)time(NULL);
}

dents = g_list_append (dents, dent);
}
Expand Down Expand Up @@ -1069,6 +1075,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr,
const char *paths_json,
const char *user,
int replace_existed,
gint64 mtime,
char **ret_json,
char **task_id,
GError **error)
Expand Down Expand Up @@ -1166,6 +1173,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr,
user,
ret_json,
replace_existed,
mtime,
canon_path,
id_list,
size_list,
Expand Down Expand Up @@ -1204,6 +1212,7 @@ post_files_and_gen_commit (GList *filenames,
const char *user,
char **ret_json,
int replace_existed,
gint64 mtime,
const char *canon_path,
GList *id_list,
GList *size_list,
Expand All @@ -1224,7 +1233,7 @@ post_files_and_gen_commit (GList *filenames,
/* Add the files to parent dir and commit. */
root_id = do_post_multi_files (repo, head_commit->root_id, canon_path,
filenames, id_list, size_list, user,
replace_existed, &name_list);
replace_existed, mtime, &name_list);
if (!root_id) {
seaf_warning ("[post multi-file] Failed to post files to %s in repo %s.\n",
canon_path, repo->id);
Expand Down
16 changes: 16 additions & 0 deletions server/upload-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ upload_api_cb(evhtp_request_t *req, void *arg)
RecvFSM *fsm = arg;
char *parent_dir, *replace_str;
char *relative_path = NULL, *new_parent_dir = NULL;
char *last_modify = NULL;
gint64 mtime = 0;
GError *error = NULL;
int error_code = -1;
char *filenames_json, *tmp_files_json;
Expand Down Expand Up @@ -468,6 +470,11 @@ upload_api_cb(evhtp_request_t *req, void *arg)
return;
}

last_modify = g_hash_table_lookup (fsm->form_kvs, "last_modify");
if (last_modify) {
mtime = atoll(last_modify);
}

replace_str = g_hash_table_lookup (fsm->form_kvs, "replace");
if (replace_str) {
replace = atoi(replace_str);
Expand Down Expand Up @@ -575,6 +582,7 @@ upload_api_cb(evhtp_request_t *req, void *arg)
tmp_files_json,
fsm->user,
replace,
mtime,
&ret_json,
fsm->need_idx_progress ? &task_id : NULL,
&error);
Expand Down Expand Up @@ -1051,6 +1059,8 @@ upload_ajax_cb(evhtp_request_t *req, void *arg)
{
RecvFSM *fsm = arg;
char *parent_dir = NULL, *relative_path = NULL, *new_parent_dir = NULL;
char *last_modify = NULL;
gint64 mtime = 0;
GError *error = NULL;
int error_code = -1;
char *filenames_json, *tmp_files_json;
Expand Down Expand Up @@ -1091,6 +1101,11 @@ upload_ajax_cb(evhtp_request_t *req, void *arg)
return;
}

last_modify = g_hash_table_lookup (fsm->form_kvs, "last_modify");
if (last_modify) {
mtime = atoll(last_modify);
}

if (!fsm->filenames) {
seaf_debug ("[upload] No file uploaded.\n");
send_error_reply (req, EVHTP_RES_BADREQ, "No file uploaded.\n");
Expand Down Expand Up @@ -1190,6 +1205,7 @@ upload_ajax_cb(evhtp_request_t *req, void *arg)
tmp_files_json,
fsm->user,
0,
mtime,
&ret_json,
fsm->need_idx_progress ? &task_id : NULL,
&error);
Expand Down
44 changes: 44 additions & 0 deletions tests/test_file_operation/test_upload_and_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,47 @@ def test_api(repo):
time.sleep(1)
del_repo_files(repo.id)
del_local_files()

def test_ajax_mtime(repo):
create_test_file()
obj_id = '{"parent_dir":"/"}'
mtime = '1695809905'

token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False)
upload_url_base = 'http://127.0.0.1:8082/upload-aj/'+ token
m = MultipartEncoder(
fields={
'parent_dir': '/',
'last_modify': mtime,
'file': (file_name, open(file_path, 'rb'), 'application/octet-stream')
})
response = requests.post(upload_url_base,
data = m, headers = {'Content-Type': m.content_type})
assert_upload_response(response, False, False)

dent = api.get_dirent_by_path(repo.id, '/' + file_name)

assert dent.mtime == 1695809905

def test_api_mtime(repo):
create_test_file()
params = {'ret-json':'1'}
obj_id = '{"parent_dir":"/"}'
mtime = '1695809905'

token = api.get_fileserver_access_token(repo.id, obj_id, 'upload', USER, False)
upload_url_base = 'http://127.0.0.1:8082/upload-api/' + token
m = MultipartEncoder(
fields={
'parent_dir': '/',
'last_modify': mtime,
'file': (file_name, open(file_path, 'rb'), 'application/octet-stream')
})
response = requests.post(upload_url_base, params = params,
data = m, headers = {'Content-Type': m.content_type})
assert_upload_response(response, False, False)

dent = api.get_dirent_by_path(repo.id, '/' + file_name)

assert dent.mtime == 1695809905

0 comments on commit 5caa192

Please sign in to comment.