버전 비교 로직 제거
This commit is contained in:
@ -1,12 +1,5 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Operation string
|
||||
|
||||
const (
|
||||
@ -58,62 +51,3 @@ type UploadRequest struct {
|
||||
Filter string
|
||||
DeleteAfterUploaded string // true, false
|
||||
}
|
||||
|
||||
type ParsedVersionString = []string
|
||||
|
||||
func ParseVersionString(ver string) ParsedVersionString {
|
||||
return strings.Split(ver, ".")
|
||||
}
|
||||
|
||||
func CompareVersionString(lhs, rhs ParsedVersionString) int {
|
||||
minlen := len(lhs)
|
||||
if minlen > len(rhs) {
|
||||
minlen = len(rhs)
|
||||
}
|
||||
|
||||
for i := 0; i < minlen; i++ {
|
||||
if len(lhs[i]) < len(rhs[i]) {
|
||||
return -1
|
||||
}
|
||||
|
||||
if len(lhs[i]) > len(rhs[i]) {
|
||||
return 1
|
||||
}
|
||||
|
||||
if lhs[i] < rhs[i] {
|
||||
return -1
|
||||
}
|
||||
|
||||
if lhs[i] > rhs[i] {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
return len(lhs) - len(rhs)
|
||||
}
|
||||
|
||||
func FindLastestVersion(storageRoot, name string) (string, error) {
|
||||
// 최신 버전을 찾음
|
||||
targetPath := path.Join(storageRoot, name)
|
||||
entries, err := os.ReadDir(targetPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(entries) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
var dironly []fs.DirEntry
|
||||
for _, ent := range entries {
|
||||
if ent.IsDir() {
|
||||
dironly = append(dironly, ent)
|
||||
}
|
||||
}
|
||||
latest := ParseVersionString(dironly[0].Name())
|
||||
for i := 1; i < len(dironly); i++ {
|
||||
next := ParseVersionString(dironly[i].Name())
|
||||
if CompareVersionString(latest, next) < 0 {
|
||||
latest = next
|
||||
}
|
||||
}
|
||||
return strings.Join(latest, "."), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user