mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-20 19:38:39 +00:00
Use github.com/saracen/walker for file walk operations
In some local tests w/ a slowed down filesystem, this massively cut down on the time to clean up a repository by ~3x, bringing a total 'publish update' time from ~16s to ~13s. Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
This commit is contained in:
committed by
André Roth
parent
53c4a567c0
commit
8ab8398c50
14
api/files.go
14
api/files.go
@@ -6,8 +6,10 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/saracen/walker"
|
||||
)
|
||||
|
||||
func verifyPath(path string) bool {
|
||||
@@ -34,17 +36,16 @@ func verifyDir(c *gin.Context) bool {
|
||||
// GET /files
|
||||
func apiFilesListDirs(c *gin.Context) {
|
||||
list := []string{}
|
||||
listLock := &sync.Mutex{}
|
||||
|
||||
err := filepath.Walk(context.UploadPath(), func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := walker.Walk(context.UploadPath(), func(path string, info os.FileInfo) error {
|
||||
if path == context.UploadPath() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
listLock.Lock()
|
||||
defer listLock.Unlock()
|
||||
list = append(list, filepath.Base(path))
|
||||
return filepath.SkipDir
|
||||
}
|
||||
@@ -121,6 +122,7 @@ func apiFilesListFiles(c *gin.Context) {
|
||||
}
|
||||
|
||||
list := []string{}
|
||||
listLock := &sync.Mutex{}
|
||||
root := filepath.Join(context.UploadPath(), c.Params.ByName("dir"))
|
||||
|
||||
err := filepath.Walk(root, func(path string, _ os.FileInfo, err error) error {
|
||||
@@ -132,6 +134,8 @@ func apiFilesListFiles(c *gin.Context) {
|
||||
return nil
|
||||
}
|
||||
|
||||
listLock.Lock()
|
||||
defer listLock.Unlock()
|
||||
list = append(list, filepath.Base(path))
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user