mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 12:22:17 +01:00
fix(pdfcpu): correct sorting for the output paths of the split method
This commit is contained in:
@@ -3,10 +3,6 @@ package gotenberg
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -88,46 +84,6 @@ func (fs *FileSystem) MkdirAll() (string, error) {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
type fileWithModTime struct {
|
||||
path string
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
// WalkDir walks through the root level of a directory and returns a list of
|
||||
// files paths that match the specified file extension.
|
||||
func WalkDir(dir, ext string) ([]string, error) {
|
||||
var files []fileWithModTime
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, pathErr error) error {
|
||||
if pathErr != nil {
|
||||
return pathErr
|
||||
}
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if strings.EqualFold(filepath.Ext(info.Name()), ext) {
|
||||
files = append(files, fileWithModTime{
|
||||
path: path,
|
||||
modTime: info.ModTime(),
|
||||
})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sort.Slice(files, func(i, j int) bool {
|
||||
return files[i].modTime.Before(files[j].modTime)
|
||||
})
|
||||
|
||||
sortedPaths := make([]string, len(files))
|
||||
for i, f := range files {
|
||||
sortedPaths[i] = f.path
|
||||
}
|
||||
|
||||
return sortedPaths, nil
|
||||
}
|
||||
|
||||
// Interface guards.
|
||||
var (
|
||||
_ MkdirAll = (*OsMkdirAll)(nil)
|
||||
|
||||
Reference in New Issue
Block a user