diff --git a/server/upload.go b/server/upload.go index 3028070..0217a94 100644 --- a/server/upload.go +++ b/server/upload.go @@ -158,12 +158,6 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { return } - _, err = tx.Exec(r.Context(), "UPDATE files SET hash = $2 WHERE id = $1", fileid, hash) - if err != nil { - errorUpload(r, w, taskid, "Set File Hash", err) - return - } - dstPath := filepath.Join(lPath, fPath) slog.InfoContext(r.Context(), "Replacing Original file With Uploaded File", "fileid", id, "path", path, "dstPath", dstPath) @@ -173,6 +167,20 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { return } + info, err := os.Stat(dstPath) + if err != nil { + errorUpload(r, w, taskid, "Stat File", err) + return + } + modTime := info.ModTime().UTC().Round(time.Second) + size := info.Size() + + _, err = tx.Exec(r.Context(), "UPDATE files SET hash = $2, size = $3, mod_time = $3 WHERE id = $1", fileid, hash, size, modTime) + if err != nil { + errorUpload(r, w, taskid, "Set File Hash", err) + return + } + err = tx.Commit(r.Context()) if err != nil { errorUpload(r, w, taskid, "Commit File Hash", err)