Skip to content
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

Add last_modify field in form #666

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 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 Expand Up @@ -2619,6 +2620,7 @@ seafile_put_file (const char *repo_id, const char *temp_file_path,
seaf_repo_manager_put_file (seaf->repo_mgr, repo_id,
temp_file_path, rpath,
norm_file_name, user, head_id,
0,
&new_file_id, error);

out:
Expand Down
54 changes: 45 additions & 9 deletions fileserver/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,15 @@ func doUpload(rsp http.ResponseWriter, r *http.Request, fsm *recvData, isAjax bo
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()
}
}

relativePath := normalizeUTF8Path(r.FormValue("relative_path"))
if relativePath != "" {
if relativePath[0] == '/' || relativePath[0] == '\\' {
Expand Down Expand Up @@ -1114,7 +1123,7 @@ func doUpload(rsp http.ResponseWriter, r *http.Request, fsm *recvData, isAjax bo
}

if err := postMultiFiles(rsp, r, repoID, newParentDir, user, fsm,
replaceExisted, isAjax); err != nil {
replaceExisted, lastModify, isAjax); err != nil {
return err
}

Expand Down Expand Up @@ -1459,7 +1468,7 @@ func parseUploadHeaders(r *http.Request) (*recvData, *appError) {
return fsm, nil
}

func postMultiFiles(rsp http.ResponseWriter, r *http.Request, repoID, parentDir, user string, fsm *recvData, replace bool, isAjax bool) *appError {
func postMultiFiles(rsp http.ResponseWriter, r *http.Request, repoID, parentDir, user string, fsm *recvData, replace bool, lastModify int64, isAjax bool) *appError {

fileNames := fsm.fileNames
files := fsm.files
Expand Down Expand Up @@ -1527,7 +1536,7 @@ func postMultiFiles(rsp http.ResponseWriter, r *http.Request, repoID, parentDir,
}
}

retStr, err := postFilesAndGenCommit(fileNames, repo.ID, user, canonPath, replace, ids, sizes)
retStr, err := postFilesAndGenCommit(fileNames, repo.ID, user, canonPath, replace, ids, sizes, lastModify)
if err != nil {
err := fmt.Errorf("failed to post files and gen commit: %v", err)
return &appError{err, "", http.StatusInternalServerError}
Expand Down Expand Up @@ -1583,7 +1592,7 @@ func checkFilesWithSameName(repo *repomgr.Repo, canonPath string, fileNames []st
return false
}

func postFilesAndGenCommit(fileNames []string, repoID string, user, canonPath string, replace bool, ids []string, sizes []int64) (string, error) {
func postFilesAndGenCommit(fileNames []string, repoID string, user, canonPath string, replace bool, ids []string, sizes []int64, lastModify int64) (string, error) {
repo := repomgr.Get(repoID)
if repo == nil {
err := fmt.Errorf("failed to get repo %s", repoID)
Expand All @@ -1603,7 +1612,10 @@ func postFilesAndGenCommit(fileNames []string, repoID string, user, canonPath st
break
}
mode := (syscall.S_IFREG | 0644)
mtime := time.Now().Unix()
mtime := lastModify
if mtime <= 0 {
mtime = time.Now().Unix()
}
dent := fsmgr.NewDirent(ids[i], name, uint32(mode), mtime, "", sizes[i])
dents = append(dents, dent)
}
Expand Down Expand Up @@ -2762,6 +2774,15 @@ func doUpdate(rsp http.ResponseWriter, r *http.Request, fsm *recvData, isAjax bo
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()
}
}

parentDir := filepath.Dir(targetFile)
fileName := filepath.Base(targetFile)

Expand Down Expand Up @@ -2868,7 +2889,7 @@ func doUpdate(rsp http.ResponseWriter, r *http.Request, fsm *recvData, isAjax bo
headID = headIDs[0]
}

if err := putFile(rsp, r, repoID, parentDir, user, fileName, fsm, headID, isAjax); err != nil {
if err := putFile(rsp, r, repoID, parentDir, user, fileName, fsm, headID, lastModify, isAjax); err != nil {
return err
}

Expand All @@ -2878,7 +2899,7 @@ func doUpdate(rsp http.ResponseWriter, r *http.Request, fsm *recvData, isAjax bo
return nil
}

func putFile(rsp http.ResponseWriter, r *http.Request, repoID, parentDir, user, fileName string, fsm *recvData, headID string, isAjax bool) *appError {
func putFile(rsp http.ResponseWriter, r *http.Request, repoID, parentDir, user, fileName string, fsm *recvData, headID string, lastModify int64, isAjax bool) *appError {
files := fsm.files
repo := repomgr.Get(repoID)
if repo == nil {
Expand Down Expand Up @@ -2973,6 +2994,9 @@ func putFile(rsp http.ResponseWriter, r *http.Request, repoID, parentDir, user,
}

mtime := time.Now().Unix()
if lastModify > 0 {
mtime = lastModify
}
mode := (syscall.S_IFREG | 0644)
newDent := fsmgr.NewDirent(fileID, fileName, uint32(mode), mtime, user, size)

Expand Down Expand Up @@ -3085,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 @@ -3123,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 @@ -3149,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 @@ -3194,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/index-blocks-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ start_index_task (gpointer data, gpointer user_data)
idx_para->canon_path,
id_list,
size_list,
0,
NULL);
progress->status = ret;
if (idx_para->ret_json) {
Expand Down
4 changes: 4 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 @@ -363,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 Expand Up @@ -405,6 +407,7 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr,
const char *file_name,
const char *user,
const char *head_id,
gint64 mtime,
char **new_file_id,
GError **error);

Expand Down Expand Up @@ -914,6 +917,7 @@ post_files_and_gen_commit (GList *filenames,
const char *canon_path,
GList *id_list,
GList *size_list,
gint64 mtime,
GError **error);

char *
Expand Down
25 changes: 21 additions & 4 deletions server/repo-op.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ post_files_and_gen_commit (GList *filenames,
const char *canon_path,
GList *id_list,
GList *size_list,
gint64 mtime,
GError **error);

/*
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 @@ -1169,6 +1176,7 @@ seaf_repo_manager_post_multi_files (SeafRepoManager *mgr,
canon_path,
id_list,
size_list,
mtime,
error);
} else {
ret = index_blocks_mgr_start_index (seaf->index_blocks_mgr,
Expand Down Expand Up @@ -1207,6 +1215,7 @@ post_files_and_gen_commit (GList *filenames,
const char *canon_path,
GList *id_list,
GList *size_list,
gint64 mtime,
GError **error)
{
SeafRepo *repo = NULL;
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 Expand Up @@ -1496,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 @@ -1554,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 Expand Up @@ -4312,6 +4325,7 @@ seaf_repo_manager_put_file (SeafRepoManager *mgr,
const char *file_name,
const char *user,
const char *head_id,
gint64 mtime,
char **new_file_id,
GError **error)
{
Expand Down Expand Up @@ -4389,9 +4403,12 @@ seaf_repo_manager_put_file (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, size);
mtime, user, size);

if (!fullpath)
fullpath = g_build_filename(parent_dir, file_name, NULL);
Expand Down
Loading
Loading