mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-01 23:46:53 +00:00
Merge same repo once and check fs object is valid (#578)
Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
@@ -7,10 +7,12 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/haiwen/seafile-server/fileserver/objstore"
|
||||
"github.com/haiwen/seafile-server/fileserver/utils"
|
||||
)
|
||||
|
||||
// Commit is a commit object
|
||||
@@ -57,7 +59,9 @@ func NewCommit(repoID, parentID, newRoot, user, desc string) *Commit {
|
||||
commit.CreatorID = "0000000000000000000000000000000000000000"
|
||||
commit.Ctime = time.Now().Unix()
|
||||
commit.CommitID = computeCommitID(commit)
|
||||
commit.ParentID.SetValid(parentID)
|
||||
if parentID != "" {
|
||||
commit.ParentID.SetValid(parentID)
|
||||
}
|
||||
|
||||
return commit
|
||||
}
|
||||
@@ -85,6 +89,22 @@ func (commit *Commit) FromData(p []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !utils.IsValidUUID(commit.RepoID) {
|
||||
return fmt.Errorf("repo id %s is invalid", commit.RepoID)
|
||||
}
|
||||
if !utils.IsObjectIDValid(commit.RootID) {
|
||||
return fmt.Errorf("root id %s is invalid", commit.RootID)
|
||||
}
|
||||
if len(commit.CreatorID) != 40 {
|
||||
return fmt.Errorf("creator id %s is invalid", commit.CreatorID)
|
||||
}
|
||||
if commit.ParentID.Valid && !utils.IsObjectIDValid(commit.ParentID.String) {
|
||||
return fmt.Errorf("parent id %s is invalid", commit.ParentID.String)
|
||||
}
|
||||
if commit.SecondParentID.Valid && !utils.IsObjectIDValid(commit.SecondParentID.String) {
|
||||
return fmt.Errorf("second parent id %s is invalid", commit.SecondParentID.String)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
const (
|
||||
commitID = "0401fc662e3bc87a41f299a907c056aaf8322a27"
|
||||
rootID = "6a1608dc2a1248838464e9b194800d35252e2ce3"
|
||||
repoID = "b1f2ad61-9164-418a-a47f-ab805dbd5694"
|
||||
seafileConfPath = "/tmp/conf"
|
||||
seafileDataDir = "/tmp/conf/seafile-data"
|
||||
@@ -44,6 +45,7 @@ func TestCommit(t *testing.T) {
|
||||
newCommit := new(Commit)
|
||||
newCommit.CommitID = commitID
|
||||
newCommit.RepoID = repoID
|
||||
newCommit.RootID = rootID
|
||||
newCommit.CreatorName = "seafile"
|
||||
newCommit.CreatorID = commitID
|
||||
newCommit.Desc = "This is a commit"
|
||||
@@ -57,11 +59,11 @@ func TestCommit(t *testing.T) {
|
||||
|
||||
commit, err := Load(repoID, commitID)
|
||||
if err != nil {
|
||||
t.Errorf("Failed to load commit.\n")
|
||||
t.Errorf("Failed to load commit: %v.\n", err)
|
||||
}
|
||||
assertEqual(t, commit.CommitID, commitID)
|
||||
assertEqual(t, commit.RepoID, repoID)
|
||||
assertEqual(t, commit.CreatorName, "seafile")
|
||||
assertEqual(t, commit.CreatorID, commitID)
|
||||
assertEqual(t, commit.ParentID, commitID)
|
||||
assertEqual(t, commit.ParentID.String, commitID)
|
||||
}
|
||||
|
Reference in New Issue
Block a user