Skip to content

Commit

Permalink
Add mtime for upload_blks_api
Browse files Browse the repository at this point in the history
  • Loading branch information
杨赫然 committed Jul 23, 2024
1 parent 3a435d6 commit 22b28ba
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
16 changes: 14 additions & 2 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3109,6 +3109,15 @@ func doUploadBlks(rsp http.ResponseWriter, r *http.Request, fsm *recvData) *appE
return &appError{nil, msg, http.StatusBadRequest}
}

lastModifyStr := normalizeUTF8Path(r.FormValue("last_modify"))
var lastModify int64
if lastModifyStr != "" {
t, err := time.Parse(time.RFC3339, lastModifyStr)
if err == nil {
lastModify = t.Unix()
}
}

fileName := normalizeUTF8Path(r.FormValue("file_name"))
if fileName == "" {
msg := "No file_name given.\n"
Expand Down Expand Up @@ -3147,7 +3156,7 @@ func doUploadBlks(rsp http.ResponseWriter, r *http.Request, fsm *recvData) *appE
return &appError{nil, msg, http.StatusBadRequest}
}

fileID, appErr := commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user, fileSize, replaceExisted)
fileID, appErr := commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user, fileSize, replaceExisted, lastModify)
if appErr != nil {
return appErr
}
Expand All @@ -3173,7 +3182,7 @@ func doUploadBlks(rsp http.ResponseWriter, r *http.Request, fsm *recvData) *appE
return nil
}

func commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user string, fileSize int64, replace bool) (string, *appError) {
func commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user string, fileSize int64, replace bool, lastModify int64) (string, *appError) {
repo := repomgr.Get(repoID)
if repo == nil {
msg := "Failed to get repo.\n"
Expand Down Expand Up @@ -3218,6 +3227,9 @@ func commitFileBlocks(repoID, parentDir, fileName, blockIDsJSON, user string, fi
}

mtime := time.Now().Unix()
if lastModify > 0 {
mtime = lastModify
}
mode := (syscall.S_IFREG | 0644)
newDent := fsmgr.NewDirent(fileID, fileName, uint32(mode), mtime, user, fileSize)
var names []string
Expand Down
1 change: 1 addition & 0 deletions server/repo-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ seaf_repo_manager_commit_file_blocks (SeafRepoManager *mgr,
const char *user,
gint64 file_size,
int replace_existed,
gint64 mtime,
char **new_id,
GError **error);

Expand Down
6 changes: 5 additions & 1 deletion server/repo-op.c
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ seaf_repo_manager_commit_file_blocks (SeafRepoManager *mgr,
const char *user,
gint64 file_size,
int replace_existed,
gint64 mtime,
char **new_id,
GError **error)
{
Expand Down Expand Up @@ -1563,9 +1564,12 @@ seaf_repo_manager_commit_file_blocks (SeafRepoManager *mgr,
}

rawdata_to_hex(sha1, hex, 20);
if (mtime <= 0) {
mtime = (gint64)time(NULL);
}
new_dent = seaf_dirent_new (dir_version_from_repo_version(repo->version),
hex, STD_FILE_MODE, file_name,
(gint64)time(NULL), user, file_size);
mtime, user, file_size);

root_id = do_post_file_replace (repo, head_commit->root_id,
canon_path, replace_existed, new_dent);
Expand Down
16 changes: 16 additions & 0 deletions server/upload-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,8 @@ upload_blks_api_cb(evhtp_request_t *req, void *arg)
{
RecvFSM *fsm = arg;
const char *parent_dir, *file_name, *size_str, *replace_str, *commitonly_str;
char *last_modify = NULL;
gint64 mtime = 0;
GError *error = NULL;
int error_code = -1;
char *blockids_json;
Expand Down Expand Up @@ -734,6 +736,11 @@ upload_blks_api_cb(evhtp_request_t *req, void *arg)
file_size = atoll(size_str);
commitonly_str = evhtp_kv_find (req->uri->query, "commitonly");

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

if (!file_name || !parent_dir || !size_str || file_size < 0) {
seaf_debug ("[upload-blks] No parent dir or file name given.\n");
send_error_reply (req, EVHTP_RES_BADREQ, "No parent dir or file name.\n");
Expand Down Expand Up @@ -792,6 +799,7 @@ upload_blks_api_cb(evhtp_request_t *req, void *arg)
fsm->user,
file_size,
replace,
mtime,
&new_file_id,
&error);
if (rc < 0) {
Expand Down Expand Up @@ -1428,6 +1436,8 @@ update_blks_api_cb(evhtp_request_t *req, void *arg)
{
RecvFSM *fsm = arg;
char *target_file, *parent_dir = NULL, *filename = NULL, *size_str = NULL;
char *last_modify = NULL;
gint64 mtime = 0;
const char *commitonly_str;
GError *error = NULL;
int error_code = -1;
Expand All @@ -1451,6 +1461,11 @@ update_blks_api_cb(evhtp_request_t *req, void *arg)
return;
}

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

parent_dir = g_path_get_dirname (target_file);
filename = g_path_get_basename (target_file);

Expand Down Expand Up @@ -1501,6 +1516,7 @@ update_blks_api_cb(evhtp_request_t *req, void *arg)
fsm->user,
file_size,
1,
mtime,
&new_file_id,
&error);

Expand Down

0 comments on commit 22b28ba

Please sign in to comment.