summaryrefslogtreecommitdiffstats
path: root/models/lfs_lock.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-12-12 13:18:07 +0000
committerLunny Xiao <xiaolunwen@gmail.com>2019-12-12 21:18:07 +0800
commitdc2fe9801f1a83a5810a778b806dac1bc210f110 (patch)
treec8f45d4005f90cd5727dc9ec44fdd35641c88376 /models/lfs_lock.go
parent751cfb805ddddbb4242583db2a71d8d3ed00f9d7 (diff)
downloadgitea-dc2fe9801f1a83a5810a778b806dac1bc210f110.tar.gz
gitea-dc2fe9801f1a83a5810a778b806dac1bc210f110.zip
Make repository management section handle lfs locks (#8726)
* Make repository maangement section handle lfs locks * Add check attribute handling and handle locking paths better * More cleanly check-attributes * handle error * Check if file exists in default branch before linking to it. * fixup * Properly cleanPath * Use cleanPath * Sigh
Diffstat (limited to 'models/lfs_lock.go')
-rw-r--r--models/lfs_lock.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/models/lfs_lock.go b/models/lfs_lock.go
index ba1a452815..3e56a7960b 100644
--- a/models/lfs_lock.go
+++ b/models/lfs_lock.go
@@ -49,7 +49,7 @@ func (l *LFSLock) AfterLoad(session *xorm.Session) {
}
func cleanPath(p string) string {
- return path.Clean(p)
+ return path.Clean("/" + p)[1:]
}
// APIFormat convert a Release to lfs.LFSLock
@@ -71,6 +71,8 @@ func CreateLFSLock(lock *LFSLock) (*LFSLock, error) {
return nil, err
}
+ lock.Path = cleanPath(lock.Path)
+
l, err := GetLFSLock(lock.Repo, lock.Path)
if err == nil {
return l, ErrLFSLockAlreadyExist{lock.RepoID, lock.Path}
@@ -110,9 +112,24 @@ func GetLFSLockByID(id int64) (*LFSLock, error) {
}
// GetLFSLockByRepoID returns a list of locks of repository.
-func GetLFSLockByRepoID(repoID int64) (locks []*LFSLock, err error) {
- err = x.Where("repo_id = ?", repoID).Find(&locks)
- return
+func GetLFSLockByRepoID(repoID int64, page, pageSize int) ([]*LFSLock, error) {
+ sess := x.NewSession()
+ defer sess.Close()
+
+ if page >= 0 && pageSize > 0 {
+ start := 0
+ if page > 0 {
+ start = (page - 1) * pageSize
+ }
+ sess.Limit(pageSize, start)
+ }
+ lfsLocks := make([]*LFSLock, 0, pageSize)
+ return lfsLocks, sess.Find(&lfsLocks, &LFSLock{RepoID: repoID})
+}
+
+// CountLFSLockByRepoID returns a count of all LFSLocks associated with a repository.
+func CountLFSLockByRepoID(repoID int64) (int64, error) {
+ return x.Count(&LFSLock{RepoID: repoID})
}
// DeleteLFSLockByID deletes a lock by given ID.